@0xsequence/provider 0.35.7 → 0.35.8
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 +38 -33
- package/dist/0xsequence-provider.cjs.prod.js +38 -33
- package/dist/0xsequence-provider.esm.js +38 -33
- 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 -11
- package/src/transports/wallet-request-handler.ts +20 -11
- package/src/transports/window-transport/window-message-provider.ts +1 -0
|
@@ -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
|
|
@@ -1705,6 +1701,7 @@ class WindowMessageHandler extends BaseWalletTransport {
|
|
|
1705
1701
|
|
|
1706
1702
|
}
|
|
1707
1703
|
|
|
1704
|
+
const SIGNER_READY_TIMEOUT = 10000;
|
|
1708
1705
|
class WalletRequestHandler {
|
|
1709
1706
|
// signer interface of the wallet. A null value means there is no signer (ie. user not signed in). An undefined
|
|
1710
1707
|
// value means the signer state is unknown, usually meaning the wallet app is booting up and initializing. Of course
|
|
@@ -1754,10 +1751,7 @@ class WalletRequestHandler {
|
|
|
1754
1751
|
id: request.id,
|
|
1755
1752
|
result: null
|
|
1756
1753
|
};
|
|
1757
|
-
|
|
1758
|
-
if (_this.signer === undefined) {
|
|
1759
|
-
await _this.signerReady();
|
|
1760
|
-
}
|
|
1754
|
+
await _this.getSigner();
|
|
1761
1755
|
|
|
1762
1756
|
try {
|
|
1763
1757
|
// only allow public json rpc method to the provider when user is not logged in, aka signer is not set
|
|
@@ -2150,6 +2144,21 @@ class WalletRequestHandler {
|
|
|
2150
2144
|
callback(undefined, response);
|
|
2151
2145
|
};
|
|
2152
2146
|
|
|
2147
|
+
this.isSignedIn = async function () {
|
|
2148
|
+
await _this.signerReady();
|
|
2149
|
+
return !!_this.signer;
|
|
2150
|
+
};
|
|
2151
|
+
|
|
2152
|
+
this.getSigner = async function () {
|
|
2153
|
+
await _this.signerReady();
|
|
2154
|
+
|
|
2155
|
+
if (_this.signer === undefined) {
|
|
2156
|
+
throw new Error('signerReady failed resolve');
|
|
2157
|
+
}
|
|
2158
|
+
|
|
2159
|
+
return _this.signer;
|
|
2160
|
+
};
|
|
2161
|
+
|
|
2153
2162
|
this.signer = _signer;
|
|
2154
2163
|
this.prompter = prompter;
|
|
2155
2164
|
this.mainnetNetworks = mainnetNetworks;
|
|
@@ -2206,7 +2215,7 @@ class WalletRequestHandler {
|
|
|
2206
2215
|
|
|
2207
2216
|
signOut() {
|
|
2208
2217
|
// signed out state
|
|
2209
|
-
this.
|
|
2218
|
+
this.setSigner(null);
|
|
2210
2219
|
}
|
|
2211
2220
|
|
|
2212
2221
|
signerReset() {
|
|
@@ -2215,14 +2224,18 @@ class WalletRequestHandler {
|
|
|
2215
2224
|
this.signer = undefined;
|
|
2216
2225
|
}
|
|
2217
2226
|
|
|
2218
|
-
signerReady() {
|
|
2227
|
+
signerReady(timeout = SIGNER_READY_TIMEOUT) {
|
|
2219
2228
|
return new Promise((resolve, reject) => {
|
|
2220
2229
|
if (this.signer !== undefined) {
|
|
2221
|
-
resolve(
|
|
2230
|
+
resolve();
|
|
2222
2231
|
} else {
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2232
|
+
setTimeout(() => {
|
|
2233
|
+
if (this.signer === undefined) {
|
|
2234
|
+
this.signerReadyCallbacks = [];
|
|
2235
|
+
reject(`signerReady timed out`);
|
|
2236
|
+
}
|
|
2237
|
+
}, timeout);
|
|
2238
|
+
this.signerReadyCallbacks.push(resolve);
|
|
2226
2239
|
}
|
|
2227
2240
|
});
|
|
2228
2241
|
}
|
|
@@ -2426,14 +2439,6 @@ class WalletRequestHandler {
|
|
|
2426
2439
|
this.events.emit('close', error);
|
|
2427
2440
|
}
|
|
2428
2441
|
|
|
2429
|
-
isSignedIn() {
|
|
2430
|
-
return !!this.signer;
|
|
2431
|
-
}
|
|
2432
|
-
|
|
2433
|
-
getSigner() {
|
|
2434
|
-
return this.signer;
|
|
2435
|
-
}
|
|
2436
|
-
|
|
2437
2442
|
setSigner(signer) {
|
|
2438
2443
|
this.signer = signer;
|
|
2439
2444
|
|
|
@@ -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
|
|
@@ -1705,6 +1701,7 @@ class WindowMessageHandler extends BaseWalletTransport {
|
|
|
1705
1701
|
|
|
1706
1702
|
}
|
|
1707
1703
|
|
|
1704
|
+
const SIGNER_READY_TIMEOUT = 10000;
|
|
1708
1705
|
class WalletRequestHandler {
|
|
1709
1706
|
// signer interface of the wallet. A null value means there is no signer (ie. user not signed in). An undefined
|
|
1710
1707
|
// value means the signer state is unknown, usually meaning the wallet app is booting up and initializing. Of course
|
|
@@ -1754,10 +1751,7 @@ class WalletRequestHandler {
|
|
|
1754
1751
|
id: request.id,
|
|
1755
1752
|
result: null
|
|
1756
1753
|
};
|
|
1757
|
-
|
|
1758
|
-
if (_this.signer === undefined) {
|
|
1759
|
-
await _this.signerReady();
|
|
1760
|
-
}
|
|
1754
|
+
await _this.getSigner();
|
|
1761
1755
|
|
|
1762
1756
|
try {
|
|
1763
1757
|
// only allow public json rpc method to the provider when user is not logged in, aka signer is not set
|
|
@@ -2150,6 +2144,21 @@ class WalletRequestHandler {
|
|
|
2150
2144
|
callback(undefined, response);
|
|
2151
2145
|
};
|
|
2152
2146
|
|
|
2147
|
+
this.isSignedIn = async function () {
|
|
2148
|
+
await _this.signerReady();
|
|
2149
|
+
return !!_this.signer;
|
|
2150
|
+
};
|
|
2151
|
+
|
|
2152
|
+
this.getSigner = async function () {
|
|
2153
|
+
await _this.signerReady();
|
|
2154
|
+
|
|
2155
|
+
if (_this.signer === undefined) {
|
|
2156
|
+
throw new Error('signerReady failed resolve');
|
|
2157
|
+
}
|
|
2158
|
+
|
|
2159
|
+
return _this.signer;
|
|
2160
|
+
};
|
|
2161
|
+
|
|
2153
2162
|
this.signer = _signer;
|
|
2154
2163
|
this.prompter = prompter;
|
|
2155
2164
|
this.mainnetNetworks = mainnetNetworks;
|
|
@@ -2206,7 +2215,7 @@ class WalletRequestHandler {
|
|
|
2206
2215
|
|
|
2207
2216
|
signOut() {
|
|
2208
2217
|
// signed out state
|
|
2209
|
-
this.
|
|
2218
|
+
this.setSigner(null);
|
|
2210
2219
|
}
|
|
2211
2220
|
|
|
2212
2221
|
signerReset() {
|
|
@@ -2215,14 +2224,18 @@ class WalletRequestHandler {
|
|
|
2215
2224
|
this.signer = undefined;
|
|
2216
2225
|
}
|
|
2217
2226
|
|
|
2218
|
-
signerReady() {
|
|
2227
|
+
signerReady(timeout = SIGNER_READY_TIMEOUT) {
|
|
2219
2228
|
return new Promise((resolve, reject) => {
|
|
2220
2229
|
if (this.signer !== undefined) {
|
|
2221
|
-
resolve(
|
|
2230
|
+
resolve();
|
|
2222
2231
|
} else {
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2232
|
+
setTimeout(() => {
|
|
2233
|
+
if (this.signer === undefined) {
|
|
2234
|
+
this.signerReadyCallbacks = [];
|
|
2235
|
+
reject(`signerReady timed out`);
|
|
2236
|
+
}
|
|
2237
|
+
}, timeout);
|
|
2238
|
+
this.signerReadyCallbacks.push(resolve);
|
|
2226
2239
|
}
|
|
2227
2240
|
});
|
|
2228
2241
|
}
|
|
@@ -2426,14 +2439,6 @@ class WalletRequestHandler {
|
|
|
2426
2439
|
this.events.emit('close', error);
|
|
2427
2440
|
}
|
|
2428
2441
|
|
|
2429
|
-
isSignedIn() {
|
|
2430
|
-
return !!this.signer;
|
|
2431
|
-
}
|
|
2432
|
-
|
|
2433
|
-
getSigner() {
|
|
2434
|
-
return this.signer;
|
|
2435
|
-
}
|
|
2436
|
-
|
|
2437
2442
|
setSigner(signer) {
|
|
2438
2443
|
this.signer = signer;
|
|
2439
2444
|
|
|
@@ -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
|
|
@@ -1701,6 +1697,7 @@ class WindowMessageHandler extends BaseWalletTransport {
|
|
|
1701
1697
|
|
|
1702
1698
|
}
|
|
1703
1699
|
|
|
1700
|
+
const SIGNER_READY_TIMEOUT = 10000;
|
|
1704
1701
|
class WalletRequestHandler {
|
|
1705
1702
|
// signer interface of the wallet. A null value means there is no signer (ie. user not signed in). An undefined
|
|
1706
1703
|
// value means the signer state is unknown, usually meaning the wallet app is booting up and initializing. Of course
|
|
@@ -1750,10 +1747,7 @@ class WalletRequestHandler {
|
|
|
1750
1747
|
id: request.id,
|
|
1751
1748
|
result: null
|
|
1752
1749
|
};
|
|
1753
|
-
|
|
1754
|
-
if (_this.signer === undefined) {
|
|
1755
|
-
await _this.signerReady();
|
|
1756
|
-
}
|
|
1750
|
+
await _this.getSigner();
|
|
1757
1751
|
|
|
1758
1752
|
try {
|
|
1759
1753
|
// only allow public json rpc method to the provider when user is not logged in, aka signer is not set
|
|
@@ -2146,6 +2140,21 @@ class WalletRequestHandler {
|
|
|
2146
2140
|
callback(undefined, response);
|
|
2147
2141
|
};
|
|
2148
2142
|
|
|
2143
|
+
this.isSignedIn = async function () {
|
|
2144
|
+
await _this.signerReady();
|
|
2145
|
+
return !!_this.signer;
|
|
2146
|
+
};
|
|
2147
|
+
|
|
2148
|
+
this.getSigner = async function () {
|
|
2149
|
+
await _this.signerReady();
|
|
2150
|
+
|
|
2151
|
+
if (_this.signer === undefined) {
|
|
2152
|
+
throw new Error('signerReady failed resolve');
|
|
2153
|
+
}
|
|
2154
|
+
|
|
2155
|
+
return _this.signer;
|
|
2156
|
+
};
|
|
2157
|
+
|
|
2149
2158
|
this.signer = _signer;
|
|
2150
2159
|
this.prompter = prompter;
|
|
2151
2160
|
this.mainnetNetworks = mainnetNetworks;
|
|
@@ -2202,7 +2211,7 @@ class WalletRequestHandler {
|
|
|
2202
2211
|
|
|
2203
2212
|
signOut() {
|
|
2204
2213
|
// signed out state
|
|
2205
|
-
this.
|
|
2214
|
+
this.setSigner(null);
|
|
2206
2215
|
}
|
|
2207
2216
|
|
|
2208
2217
|
signerReset() {
|
|
@@ -2211,14 +2220,18 @@ class WalletRequestHandler {
|
|
|
2211
2220
|
this.signer = undefined;
|
|
2212
2221
|
}
|
|
2213
2222
|
|
|
2214
|
-
signerReady() {
|
|
2223
|
+
signerReady(timeout = SIGNER_READY_TIMEOUT) {
|
|
2215
2224
|
return new Promise((resolve, reject) => {
|
|
2216
2225
|
if (this.signer !== undefined) {
|
|
2217
|
-
resolve(
|
|
2226
|
+
resolve();
|
|
2218
2227
|
} else {
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2228
|
+
setTimeout(() => {
|
|
2229
|
+
if (this.signer === undefined) {
|
|
2230
|
+
this.signerReadyCallbacks = [];
|
|
2231
|
+
reject(`signerReady timed out`);
|
|
2232
|
+
}
|
|
2233
|
+
}, timeout);
|
|
2234
|
+
this.signerReadyCallbacks.push(resolve);
|
|
2222
2235
|
}
|
|
2223
2236
|
});
|
|
2224
2237
|
}
|
|
@@ -2422,14 +2435,6 @@ class WalletRequestHandler {
|
|
|
2422
2435
|
this.events.emit('close', error);
|
|
2423
2436
|
}
|
|
2424
2437
|
|
|
2425
|
-
isSignedIn() {
|
|
2426
|
-
return !!this.signer;
|
|
2427
|
-
}
|
|
2428
|
-
|
|
2429
|
-
getSigner() {
|
|
2430
|
-
return this.signer;
|
|
2431
|
-
}
|
|
2432
|
-
|
|
2433
2438
|
setSigner(signer) {
|
|
2434
2439
|
this.signer = signer;
|
|
2435
2440
|
|
|
@@ -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.8",
|
|
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.8",
|
|
17
|
+
"@0xsequence/auth": "^0.35.8",
|
|
18
|
+
"@0xsequence/config": "^0.35.8",
|
|
19
|
+
"@0xsequence/network": "^0.35.8",
|
|
20
|
+
"@0xsequence/transactions": "^0.35.8",
|
|
21
|
+
"@0xsequence/utils": "^0.35.8",
|
|
22
|
+
"@0xsequence/wallet": "^0.35.8",
|
|
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,11 +321,6 @@ 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
|
|
@@ -369,8 +364,11 @@ export abstract class BaseWalletTransport implements WalletTransport {
|
|
|
369
364
|
this.walletRequestHandler.setConnectOptions(undefined)
|
|
370
365
|
}
|
|
371
366
|
|
|
367
|
+
// ensure signer is ready
|
|
368
|
+
await this.walletRequestHandler.getSigner()
|
|
369
|
+
|
|
372
370
|
// Notify open and proceed to prompt for connection if intended
|
|
373
|
-
if (!this.walletRequestHandler.isSignedIn()) {
|
|
371
|
+
if (!(await this.walletRequestHandler.isSignedIn())) {
|
|
374
372
|
// open wallet without a specific connected chainId, as the user is not signed in
|
|
375
373
|
this.notifyOpen({
|
|
376
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
|
|
@@ -118,7 +120,7 @@ export class WalletRequestHandler implements ExternalProvider, JsonRpcHandler, P
|
|
|
118
120
|
|
|
119
121
|
signOut() {
|
|
120
122
|
// signed out state
|
|
121
|
-
this.
|
|
123
|
+
this.setSigner(null)
|
|
122
124
|
}
|
|
123
125
|
|
|
124
126
|
signerReset() {
|
|
@@ -127,14 +129,18 @@ export class WalletRequestHandler implements ExternalProvider, JsonRpcHandler, P
|
|
|
127
129
|
this.signer = undefined
|
|
128
130
|
}
|
|
129
131
|
|
|
130
|
-
signerReady() {
|
|
132
|
+
signerReady(timeout: number = SIGNER_READY_TIMEOUT): Promise<void> {
|
|
131
133
|
return new Promise((resolve, reject) => {
|
|
132
134
|
if (this.signer !== undefined) {
|
|
133
|
-
resolve(
|
|
135
|
+
resolve()
|
|
134
136
|
} else {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
137
|
+
setTimeout(() => {
|
|
138
|
+
if (this.signer === undefined) {
|
|
139
|
+
this.signerReadyCallbacks = []
|
|
140
|
+
reject(`signerReady timed out`)
|
|
141
|
+
}
|
|
142
|
+
}, timeout)
|
|
143
|
+
this.signerReadyCallbacks.push(resolve)
|
|
138
144
|
}
|
|
139
145
|
})
|
|
140
146
|
}
|
|
@@ -238,9 +244,7 @@ export class WalletRequestHandler implements ExternalProvider, JsonRpcHandler, P
|
|
|
238
244
|
result: null
|
|
239
245
|
}
|
|
240
246
|
|
|
241
|
-
|
|
242
|
-
await this.signerReady()
|
|
243
|
-
}
|
|
247
|
+
await this.getSigner()
|
|
244
248
|
|
|
245
249
|
try {
|
|
246
250
|
// only allow public json rpc method to the provider when user is not logged in, aka signer is not set
|
|
@@ -720,11 +724,16 @@ export class WalletRequestHandler implements ExternalProvider, JsonRpcHandler, P
|
|
|
720
724
|
this.events.emit('close', error)
|
|
721
725
|
}
|
|
722
726
|
|
|
723
|
-
isSignedIn(): boolean {
|
|
727
|
+
isSignedIn = async (): Promise<boolean> => {
|
|
728
|
+
await this.signerReady()
|
|
724
729
|
return !!this.signer
|
|
725
730
|
}
|
|
726
731
|
|
|
727
|
-
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
|
+
}
|
|
728
737
|
return this.signer
|
|
729
738
|
}
|
|
730
739
|
|
|
@@ -80,6 +80,7 @@ export class WindowMessageProvider extends BaseProviderTransport {
|
|
|
80
80
|
this._init = InitState.NIL
|
|
81
81
|
this._sessionId = `${performance.now()}`
|
|
82
82
|
windowSessionParams.set('sid', this._sessionId)
|
|
83
|
+
|
|
83
84
|
if (intent) {
|
|
84
85
|
// for the window-transport, we eagerly/optimistically set the origin host
|
|
85
86
|
// when connecting to the wallet, however, this will be verified and enforced
|