@0xsequence/provider 0.35.2 → 0.35.6
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 +73 -10
- package/dist/0xsequence-provider.cjs.prod.js +73 -10
- package/dist/0xsequence-provider.esm.js +73 -10
- package/dist/declarations/src/transports/wallet-request-handler.d.ts +11 -4
- package/package.json +8 -8
- package/src/transports/base-wallet-transport.ts +13 -0
- package/src/transports/wallet-request-handler.ts +56 -5
- package/src/transports/window-transport/window-message-handler.ts +0 -4
- package/src/transports/window-transport/window-message-provider.ts +16 -5
- package/CHANGELOG.md +0 -1154
|
@@ -597,9 +597,14 @@ class BaseWalletTransport {
|
|
|
597
597
|
};
|
|
598
598
|
|
|
599
599
|
this.handleMessage = async function (message) {
|
|
600
|
-
const request = message; // ensure
|
|
600
|
+
const request = message; // ensure signer is ready to handle requests
|
|
601
|
+
|
|
602
|
+
if (_this.walletRequestHandler.getSigner() === undefined) {
|
|
603
|
+
await _this.walletRequestHandler.signerReady();
|
|
604
|
+
} // ensure initial handshake is complete before accepting
|
|
601
605
|
// other kinds of messages.
|
|
602
606
|
|
|
607
|
+
|
|
603
608
|
if (_this._init !== exports.InitState.OK) {
|
|
604
609
|
if (request.type === exports.EventType.INIT) {
|
|
605
610
|
if (_this.isValidInitAck(message)) {
|
|
@@ -671,6 +676,13 @@ class BaseWalletTransport {
|
|
|
671
676
|
intent,
|
|
672
677
|
networkId
|
|
673
678
|
});
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
_this.walletRequestHandler.setOpenIntent(intent); // ensure signer is ready
|
|
682
|
+
|
|
683
|
+
|
|
684
|
+
if (_this.walletRequestHandler.getSigner() === undefined) {
|
|
685
|
+
await _this.walletRequestHandler.signerReady();
|
|
674
686
|
} // init handshake for certain transports, before we can open the communication.
|
|
675
687
|
//
|
|
676
688
|
// for example, with the window-transport, we have to exchange messages to determine the
|
|
@@ -1450,8 +1462,17 @@ class WindowMessageProvider extends BaseProviderTransport {
|
|
|
1450
1462
|
} // Open popup window on center of the app window
|
|
1451
1463
|
|
|
1452
1464
|
|
|
1453
|
-
|
|
1454
|
-
|
|
1465
|
+
let windowSize;
|
|
1466
|
+
let windowPos;
|
|
1467
|
+
|
|
1468
|
+
if (isBrowserExtension()) {
|
|
1469
|
+
windowSize = [450, 750];
|
|
1470
|
+
windowPos = [Math.abs(window.screen.width / 2 - windowSize[0] / 2), Math.abs(window.screen.height / 2 - windowSize[1] / 2)];
|
|
1471
|
+
} else {
|
|
1472
|
+
windowSize = [450, 750];
|
|
1473
|
+
windowPos = [Math.abs(window.screenX + window.innerWidth / 2 - windowSize[0] / 2), Math.abs(window.screenY + window.innerHeight / 2 - windowSize[1] / 2)];
|
|
1474
|
+
}
|
|
1475
|
+
|
|
1455
1476
|
const windowFeatures = `toolbar=0,location=0,menubar=0,scrollbars=yes,status=yes` + `,width=${windowSize[0]},height=${windowSize[1]}` + `,left=${windowPos[0]},top=${windowPos[1]}`; // serialize params
|
|
1456
1477
|
|
|
1457
1478
|
walletURL.search = windowSessionParams.toString();
|
|
@@ -1607,12 +1628,6 @@ class WindowMessageHandler extends BaseWalletTransport {
|
|
|
1607
1628
|
if (!session) {
|
|
1608
1629
|
utils.logger.error('window session is undefined');
|
|
1609
1630
|
return;
|
|
1610
|
-
}
|
|
1611
|
-
|
|
1612
|
-
if (session.intent && isNewWindowSession) {
|
|
1613
|
-
window.history.replaceState({
|
|
1614
|
-
openWalletIntent: true
|
|
1615
|
-
}, document.title, pathname);
|
|
1616
1631
|
} // record parent window instance for communication
|
|
1617
1632
|
|
|
1618
1633
|
|
|
@@ -1691,13 +1706,18 @@ class WindowMessageHandler extends BaseWalletTransport {
|
|
|
1691
1706
|
}
|
|
1692
1707
|
|
|
1693
1708
|
class WalletRequestHandler {
|
|
1709
|
+
// signer interface of the wallet. A null value means there is no signer (ie. user not signed in). An undefined
|
|
1710
|
+
// value means the signer state is unknown, usually meaning the wallet app is booting up and initializing. Of course
|
|
1711
|
+
// a Signer value is the actually interface to a signed-in account
|
|
1694
1712
|
constructor(_signer, prompter, mainnetNetworks, testnetNetworks = []) {
|
|
1695
1713
|
var _this = this;
|
|
1696
1714
|
|
|
1697
1715
|
this.signer = void 0;
|
|
1716
|
+
this.signerReadyCallbacks = [];
|
|
1698
1717
|
this.prompter = void 0;
|
|
1699
1718
|
this.mainnetNetworks = void 0;
|
|
1700
1719
|
this.testnetNetworks = void 0;
|
|
1720
|
+
this._openIntent = void 0;
|
|
1701
1721
|
this._connectOptions = void 0;
|
|
1702
1722
|
this._defaultNetworkId = void 0;
|
|
1703
1723
|
this._chainId = void 0;
|
|
@@ -1735,6 +1755,10 @@ class WalletRequestHandler {
|
|
|
1735
1755
|
result: null
|
|
1736
1756
|
};
|
|
1737
1757
|
|
|
1758
|
+
if (_this.signer === undefined) {
|
|
1759
|
+
await _this.signerReady();
|
|
1760
|
+
}
|
|
1761
|
+
|
|
1738
1762
|
try {
|
|
1739
1763
|
// only allow public json rpc method to the provider when user is not logged in, aka signer is not set
|
|
1740
1764
|
if ((!_this.signer || _this.signer === null) && !permittedJsonRpcMethods.includes(request.method)) {
|
|
@@ -2133,7 +2157,7 @@ class WalletRequestHandler {
|
|
|
2133
2157
|
}
|
|
2134
2158
|
|
|
2135
2159
|
async signIn(signer, options = {}) {
|
|
2136
|
-
this.signer
|
|
2160
|
+
this.setSigner(signer);
|
|
2137
2161
|
const {
|
|
2138
2162
|
connect,
|
|
2139
2163
|
mainnetNetworks,
|
|
@@ -2180,6 +2204,29 @@ class WalletRequestHandler {
|
|
|
2180
2204
|
}
|
|
2181
2205
|
}
|
|
2182
2206
|
|
|
2207
|
+
signOut() {
|
|
2208
|
+
// signed out state
|
|
2209
|
+
this.signer = null;
|
|
2210
|
+
}
|
|
2211
|
+
|
|
2212
|
+
signerReset() {
|
|
2213
|
+
// resetting signer puts the wallet in an uninitialized state, which requires the app to
|
|
2214
|
+
// re-initiatize and set the signer either as "null" (ie. no signer) or "Signer" (ie. signed in).
|
|
2215
|
+
this.signer = undefined;
|
|
2216
|
+
}
|
|
2217
|
+
|
|
2218
|
+
signerReady() {
|
|
2219
|
+
return new Promise((resolve, reject) => {
|
|
2220
|
+
if (this.signer !== undefined) {
|
|
2221
|
+
resolve(undefined);
|
|
2222
|
+
} else {
|
|
2223
|
+
this.signerReadyCallbacks.push(() => {
|
|
2224
|
+
resolve(undefined);
|
|
2225
|
+
});
|
|
2226
|
+
}
|
|
2227
|
+
});
|
|
2228
|
+
}
|
|
2229
|
+
|
|
2183
2230
|
async connect(options) {
|
|
2184
2231
|
if (!this.signer) {
|
|
2185
2232
|
return {
|
|
@@ -2268,6 +2315,14 @@ class WalletRequestHandler {
|
|
|
2268
2315
|
}
|
|
2269
2316
|
}
|
|
2270
2317
|
|
|
2318
|
+
get openIntent() {
|
|
2319
|
+
return this._openIntent;
|
|
2320
|
+
}
|
|
2321
|
+
|
|
2322
|
+
setOpenIntent(intent) {
|
|
2323
|
+
this._openIntent = intent;
|
|
2324
|
+
}
|
|
2325
|
+
|
|
2271
2326
|
get connectOptions() {
|
|
2272
2327
|
return this._connectOptions;
|
|
2273
2328
|
}
|
|
@@ -2381,6 +2436,14 @@ class WalletRequestHandler {
|
|
|
2381
2436
|
|
|
2382
2437
|
setSigner(signer) {
|
|
2383
2438
|
this.signer = signer;
|
|
2439
|
+
|
|
2440
|
+
if (signer !== undefined) {
|
|
2441
|
+
for (let i = 0; i < this.signerReadyCallbacks.length; i++) {
|
|
2442
|
+
this.signerReadyCallbacks[i]();
|
|
2443
|
+
}
|
|
2444
|
+
|
|
2445
|
+
this.signerReadyCallbacks = [];
|
|
2446
|
+
}
|
|
2384
2447
|
}
|
|
2385
2448
|
|
|
2386
2449
|
async handleConfirmWalletDeployPrompt(prompter, signer, chainId) {
|
|
@@ -597,9 +597,14 @@ class BaseWalletTransport {
|
|
|
597
597
|
};
|
|
598
598
|
|
|
599
599
|
this.handleMessage = async function (message) {
|
|
600
|
-
const request = message; // ensure
|
|
600
|
+
const request = message; // ensure signer is ready to handle requests
|
|
601
|
+
|
|
602
|
+
if (_this.walletRequestHandler.getSigner() === undefined) {
|
|
603
|
+
await _this.walletRequestHandler.signerReady();
|
|
604
|
+
} // ensure initial handshake is complete before accepting
|
|
601
605
|
// other kinds of messages.
|
|
602
606
|
|
|
607
|
+
|
|
603
608
|
if (_this._init !== exports.InitState.OK) {
|
|
604
609
|
if (request.type === exports.EventType.INIT) {
|
|
605
610
|
if (_this.isValidInitAck(message)) {
|
|
@@ -671,6 +676,13 @@ class BaseWalletTransport {
|
|
|
671
676
|
intent,
|
|
672
677
|
networkId
|
|
673
678
|
});
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
_this.walletRequestHandler.setOpenIntent(intent); // ensure signer is ready
|
|
682
|
+
|
|
683
|
+
|
|
684
|
+
if (_this.walletRequestHandler.getSigner() === undefined) {
|
|
685
|
+
await _this.walletRequestHandler.signerReady();
|
|
674
686
|
} // init handshake for certain transports, before we can open the communication.
|
|
675
687
|
//
|
|
676
688
|
// for example, with the window-transport, we have to exchange messages to determine the
|
|
@@ -1450,8 +1462,17 @@ class WindowMessageProvider extends BaseProviderTransport {
|
|
|
1450
1462
|
} // Open popup window on center of the app window
|
|
1451
1463
|
|
|
1452
1464
|
|
|
1453
|
-
|
|
1454
|
-
|
|
1465
|
+
let windowSize;
|
|
1466
|
+
let windowPos;
|
|
1467
|
+
|
|
1468
|
+
if (isBrowserExtension()) {
|
|
1469
|
+
windowSize = [450, 750];
|
|
1470
|
+
windowPos = [Math.abs(window.screen.width / 2 - windowSize[0] / 2), Math.abs(window.screen.height / 2 - windowSize[1] / 2)];
|
|
1471
|
+
} else {
|
|
1472
|
+
windowSize = [450, 750];
|
|
1473
|
+
windowPos = [Math.abs(window.screenX + window.innerWidth / 2 - windowSize[0] / 2), Math.abs(window.screenY + window.innerHeight / 2 - windowSize[1] / 2)];
|
|
1474
|
+
}
|
|
1475
|
+
|
|
1455
1476
|
const windowFeatures = `toolbar=0,location=0,menubar=0,scrollbars=yes,status=yes` + `,width=${windowSize[0]},height=${windowSize[1]}` + `,left=${windowPos[0]},top=${windowPos[1]}`; // serialize params
|
|
1456
1477
|
|
|
1457
1478
|
walletURL.search = windowSessionParams.toString();
|
|
@@ -1607,12 +1628,6 @@ class WindowMessageHandler extends BaseWalletTransport {
|
|
|
1607
1628
|
if (!session) {
|
|
1608
1629
|
utils.logger.error('window session is undefined');
|
|
1609
1630
|
return;
|
|
1610
|
-
}
|
|
1611
|
-
|
|
1612
|
-
if (session.intent && isNewWindowSession) {
|
|
1613
|
-
window.history.replaceState({
|
|
1614
|
-
openWalletIntent: true
|
|
1615
|
-
}, document.title, pathname);
|
|
1616
1631
|
} // record parent window instance for communication
|
|
1617
1632
|
|
|
1618
1633
|
|
|
@@ -1691,13 +1706,18 @@ class WindowMessageHandler extends BaseWalletTransport {
|
|
|
1691
1706
|
}
|
|
1692
1707
|
|
|
1693
1708
|
class WalletRequestHandler {
|
|
1709
|
+
// signer interface of the wallet. A null value means there is no signer (ie. user not signed in). An undefined
|
|
1710
|
+
// value means the signer state is unknown, usually meaning the wallet app is booting up and initializing. Of course
|
|
1711
|
+
// a Signer value is the actually interface to a signed-in account
|
|
1694
1712
|
constructor(_signer, prompter, mainnetNetworks, testnetNetworks = []) {
|
|
1695
1713
|
var _this = this;
|
|
1696
1714
|
|
|
1697
1715
|
this.signer = void 0;
|
|
1716
|
+
this.signerReadyCallbacks = [];
|
|
1698
1717
|
this.prompter = void 0;
|
|
1699
1718
|
this.mainnetNetworks = void 0;
|
|
1700
1719
|
this.testnetNetworks = void 0;
|
|
1720
|
+
this._openIntent = void 0;
|
|
1701
1721
|
this._connectOptions = void 0;
|
|
1702
1722
|
this._defaultNetworkId = void 0;
|
|
1703
1723
|
this._chainId = void 0;
|
|
@@ -1735,6 +1755,10 @@ class WalletRequestHandler {
|
|
|
1735
1755
|
result: null
|
|
1736
1756
|
};
|
|
1737
1757
|
|
|
1758
|
+
if (_this.signer === undefined) {
|
|
1759
|
+
await _this.signerReady();
|
|
1760
|
+
}
|
|
1761
|
+
|
|
1738
1762
|
try {
|
|
1739
1763
|
// only allow public json rpc method to the provider when user is not logged in, aka signer is not set
|
|
1740
1764
|
if ((!_this.signer || _this.signer === null) && !permittedJsonRpcMethods.includes(request.method)) {
|
|
@@ -2133,7 +2157,7 @@ class WalletRequestHandler {
|
|
|
2133
2157
|
}
|
|
2134
2158
|
|
|
2135
2159
|
async signIn(signer, options = {}) {
|
|
2136
|
-
this.signer
|
|
2160
|
+
this.setSigner(signer);
|
|
2137
2161
|
const {
|
|
2138
2162
|
connect,
|
|
2139
2163
|
mainnetNetworks,
|
|
@@ -2180,6 +2204,29 @@ class WalletRequestHandler {
|
|
|
2180
2204
|
}
|
|
2181
2205
|
}
|
|
2182
2206
|
|
|
2207
|
+
signOut() {
|
|
2208
|
+
// signed out state
|
|
2209
|
+
this.signer = null;
|
|
2210
|
+
}
|
|
2211
|
+
|
|
2212
|
+
signerReset() {
|
|
2213
|
+
// resetting signer puts the wallet in an uninitialized state, which requires the app to
|
|
2214
|
+
// re-initiatize and set the signer either as "null" (ie. no signer) or "Signer" (ie. signed in).
|
|
2215
|
+
this.signer = undefined;
|
|
2216
|
+
}
|
|
2217
|
+
|
|
2218
|
+
signerReady() {
|
|
2219
|
+
return new Promise((resolve, reject) => {
|
|
2220
|
+
if (this.signer !== undefined) {
|
|
2221
|
+
resolve(undefined);
|
|
2222
|
+
} else {
|
|
2223
|
+
this.signerReadyCallbacks.push(() => {
|
|
2224
|
+
resolve(undefined);
|
|
2225
|
+
});
|
|
2226
|
+
}
|
|
2227
|
+
});
|
|
2228
|
+
}
|
|
2229
|
+
|
|
2183
2230
|
async connect(options) {
|
|
2184
2231
|
if (!this.signer) {
|
|
2185
2232
|
return {
|
|
@@ -2268,6 +2315,14 @@ class WalletRequestHandler {
|
|
|
2268
2315
|
}
|
|
2269
2316
|
}
|
|
2270
2317
|
|
|
2318
|
+
get openIntent() {
|
|
2319
|
+
return this._openIntent;
|
|
2320
|
+
}
|
|
2321
|
+
|
|
2322
|
+
setOpenIntent(intent) {
|
|
2323
|
+
this._openIntent = intent;
|
|
2324
|
+
}
|
|
2325
|
+
|
|
2271
2326
|
get connectOptions() {
|
|
2272
2327
|
return this._connectOptions;
|
|
2273
2328
|
}
|
|
@@ -2381,6 +2436,14 @@ class WalletRequestHandler {
|
|
|
2381
2436
|
|
|
2382
2437
|
setSigner(signer) {
|
|
2383
2438
|
this.signer = signer;
|
|
2439
|
+
|
|
2440
|
+
if (signer !== undefined) {
|
|
2441
|
+
for (let i = 0; i < this.signerReadyCallbacks.length; i++) {
|
|
2442
|
+
this.signerReadyCallbacks[i]();
|
|
2443
|
+
}
|
|
2444
|
+
|
|
2445
|
+
this.signerReadyCallbacks = [];
|
|
2446
|
+
}
|
|
2384
2447
|
}
|
|
2385
2448
|
|
|
2386
2449
|
async handleConfirmWalletDeployPrompt(prompter, signer, chainId) {
|
|
@@ -593,9 +593,14 @@ class BaseWalletTransport {
|
|
|
593
593
|
};
|
|
594
594
|
|
|
595
595
|
this.handleMessage = async function (message) {
|
|
596
|
-
const request = message; // ensure
|
|
596
|
+
const request = message; // ensure signer is ready to handle requests
|
|
597
|
+
|
|
598
|
+
if (_this.walletRequestHandler.getSigner() === undefined) {
|
|
599
|
+
await _this.walletRequestHandler.signerReady();
|
|
600
|
+
} // ensure initial handshake is complete before accepting
|
|
597
601
|
// other kinds of messages.
|
|
598
602
|
|
|
603
|
+
|
|
599
604
|
if (_this._init !== InitState.OK) {
|
|
600
605
|
if (request.type === EventType.INIT) {
|
|
601
606
|
if (_this.isValidInitAck(message)) {
|
|
@@ -667,6 +672,13 @@ class BaseWalletTransport {
|
|
|
667
672
|
intent,
|
|
668
673
|
networkId
|
|
669
674
|
});
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
_this.walletRequestHandler.setOpenIntent(intent); // ensure signer is ready
|
|
678
|
+
|
|
679
|
+
|
|
680
|
+
if (_this.walletRequestHandler.getSigner() === undefined) {
|
|
681
|
+
await _this.walletRequestHandler.signerReady();
|
|
670
682
|
} // init handshake for certain transports, before we can open the communication.
|
|
671
683
|
//
|
|
672
684
|
// for example, with the window-transport, we have to exchange messages to determine the
|
|
@@ -1446,8 +1458,17 @@ class WindowMessageProvider extends BaseProviderTransport {
|
|
|
1446
1458
|
} // Open popup window on center of the app window
|
|
1447
1459
|
|
|
1448
1460
|
|
|
1449
|
-
|
|
1450
|
-
|
|
1461
|
+
let windowSize;
|
|
1462
|
+
let windowPos;
|
|
1463
|
+
|
|
1464
|
+
if (isBrowserExtension()) {
|
|
1465
|
+
windowSize = [450, 750];
|
|
1466
|
+
windowPos = [Math.abs(window.screen.width / 2 - windowSize[0] / 2), Math.abs(window.screen.height / 2 - windowSize[1] / 2)];
|
|
1467
|
+
} else {
|
|
1468
|
+
windowSize = [450, 750];
|
|
1469
|
+
windowPos = [Math.abs(window.screenX + window.innerWidth / 2 - windowSize[0] / 2), Math.abs(window.screenY + window.innerHeight / 2 - windowSize[1] / 2)];
|
|
1470
|
+
}
|
|
1471
|
+
|
|
1451
1472
|
const windowFeatures = `toolbar=0,location=0,menubar=0,scrollbars=yes,status=yes` + `,width=${windowSize[0]},height=${windowSize[1]}` + `,left=${windowPos[0]},top=${windowPos[1]}`; // serialize params
|
|
1452
1473
|
|
|
1453
1474
|
walletURL.search = windowSessionParams.toString();
|
|
@@ -1603,12 +1624,6 @@ class WindowMessageHandler extends BaseWalletTransport {
|
|
|
1603
1624
|
if (!session) {
|
|
1604
1625
|
logger.error('window session is undefined');
|
|
1605
1626
|
return;
|
|
1606
|
-
}
|
|
1607
|
-
|
|
1608
|
-
if (session.intent && isNewWindowSession) {
|
|
1609
|
-
window.history.replaceState({
|
|
1610
|
-
openWalletIntent: true
|
|
1611
|
-
}, document.title, pathname);
|
|
1612
1627
|
} // record parent window instance for communication
|
|
1613
1628
|
|
|
1614
1629
|
|
|
@@ -1687,13 +1702,18 @@ class WindowMessageHandler extends BaseWalletTransport {
|
|
|
1687
1702
|
}
|
|
1688
1703
|
|
|
1689
1704
|
class WalletRequestHandler {
|
|
1705
|
+
// signer interface of the wallet. A null value means there is no signer (ie. user not signed in). An undefined
|
|
1706
|
+
// value means the signer state is unknown, usually meaning the wallet app is booting up and initializing. Of course
|
|
1707
|
+
// a Signer value is the actually interface to a signed-in account
|
|
1690
1708
|
constructor(_signer, prompter, mainnetNetworks, testnetNetworks = []) {
|
|
1691
1709
|
var _this = this;
|
|
1692
1710
|
|
|
1693
1711
|
this.signer = void 0;
|
|
1712
|
+
this.signerReadyCallbacks = [];
|
|
1694
1713
|
this.prompter = void 0;
|
|
1695
1714
|
this.mainnetNetworks = void 0;
|
|
1696
1715
|
this.testnetNetworks = void 0;
|
|
1716
|
+
this._openIntent = void 0;
|
|
1697
1717
|
this._connectOptions = void 0;
|
|
1698
1718
|
this._defaultNetworkId = void 0;
|
|
1699
1719
|
this._chainId = void 0;
|
|
@@ -1731,6 +1751,10 @@ class WalletRequestHandler {
|
|
|
1731
1751
|
result: null
|
|
1732
1752
|
};
|
|
1733
1753
|
|
|
1754
|
+
if (_this.signer === undefined) {
|
|
1755
|
+
await _this.signerReady();
|
|
1756
|
+
}
|
|
1757
|
+
|
|
1734
1758
|
try {
|
|
1735
1759
|
// only allow public json rpc method to the provider when user is not logged in, aka signer is not set
|
|
1736
1760
|
if ((!_this.signer || _this.signer === null) && !permittedJsonRpcMethods.includes(request.method)) {
|
|
@@ -2129,7 +2153,7 @@ class WalletRequestHandler {
|
|
|
2129
2153
|
}
|
|
2130
2154
|
|
|
2131
2155
|
async signIn(signer, options = {}) {
|
|
2132
|
-
this.signer
|
|
2156
|
+
this.setSigner(signer);
|
|
2133
2157
|
const {
|
|
2134
2158
|
connect,
|
|
2135
2159
|
mainnetNetworks,
|
|
@@ -2176,6 +2200,29 @@ class WalletRequestHandler {
|
|
|
2176
2200
|
}
|
|
2177
2201
|
}
|
|
2178
2202
|
|
|
2203
|
+
signOut() {
|
|
2204
|
+
// signed out state
|
|
2205
|
+
this.signer = null;
|
|
2206
|
+
}
|
|
2207
|
+
|
|
2208
|
+
signerReset() {
|
|
2209
|
+
// resetting signer puts the wallet in an uninitialized state, which requires the app to
|
|
2210
|
+
// re-initiatize and set the signer either as "null" (ie. no signer) or "Signer" (ie. signed in).
|
|
2211
|
+
this.signer = undefined;
|
|
2212
|
+
}
|
|
2213
|
+
|
|
2214
|
+
signerReady() {
|
|
2215
|
+
return new Promise((resolve, reject) => {
|
|
2216
|
+
if (this.signer !== undefined) {
|
|
2217
|
+
resolve(undefined);
|
|
2218
|
+
} else {
|
|
2219
|
+
this.signerReadyCallbacks.push(() => {
|
|
2220
|
+
resolve(undefined);
|
|
2221
|
+
});
|
|
2222
|
+
}
|
|
2223
|
+
});
|
|
2224
|
+
}
|
|
2225
|
+
|
|
2179
2226
|
async connect(options) {
|
|
2180
2227
|
if (!this.signer) {
|
|
2181
2228
|
return {
|
|
@@ -2264,6 +2311,14 @@ class WalletRequestHandler {
|
|
|
2264
2311
|
}
|
|
2265
2312
|
}
|
|
2266
2313
|
|
|
2314
|
+
get openIntent() {
|
|
2315
|
+
return this._openIntent;
|
|
2316
|
+
}
|
|
2317
|
+
|
|
2318
|
+
setOpenIntent(intent) {
|
|
2319
|
+
this._openIntent = intent;
|
|
2320
|
+
}
|
|
2321
|
+
|
|
2267
2322
|
get connectOptions() {
|
|
2268
2323
|
return this._connectOptions;
|
|
2269
2324
|
}
|
|
@@ -2377,6 +2432,14 @@ class WalletRequestHandler {
|
|
|
2377
2432
|
|
|
2378
2433
|
setSigner(signer) {
|
|
2379
2434
|
this.signer = signer;
|
|
2435
|
+
|
|
2436
|
+
if (signer !== undefined) {
|
|
2437
|
+
for (let i = 0; i < this.signerReadyCallbacks.length; i++) {
|
|
2438
|
+
this.signerReadyCallbacks[i]();
|
|
2439
|
+
}
|
|
2440
|
+
|
|
2441
|
+
this.signerReadyCallbacks = [];
|
|
2442
|
+
}
|
|
2380
2443
|
}
|
|
2381
2444
|
|
|
2382
2445
|
async handleConfirmWalletDeployPrompt(prompter, signer, chainId) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ProviderMessageRequest, ProviderMessageResponse, ProviderMessageRequestHandler, MessageToSign, ProviderRpcError, ConnectOptions, ConnectDetails, PromptConnectDetails, WalletSession, ProviderEventTypes } from '../types';
|
|
1
|
+
import { ProviderMessageRequest, ProviderMessageResponse, ProviderMessageRequestHandler, MessageToSign, ProviderRpcError, ConnectOptions, ConnectDetails, PromptConnectDetails, WalletSession, OpenWalletIntent, ProviderEventTypes } from '../types';
|
|
2
2
|
import { ExternalProvider } from '@ethersproject/providers';
|
|
3
3
|
import { Networks, NetworkConfig, JsonRpcHandler, JsonRpcRequest, JsonRpcResponseCallback } from '@0xsequence/network';
|
|
4
4
|
import { Signer } from '@0xsequence/wallet';
|
|
@@ -11,15 +11,20 @@ export interface WalletSignInOptions {
|
|
|
11
11
|
}
|
|
12
12
|
export declare class WalletRequestHandler implements ExternalProvider, JsonRpcHandler, ProviderMessageRequestHandler {
|
|
13
13
|
private signer;
|
|
14
|
+
private signerReadyCallbacks;
|
|
14
15
|
private prompter;
|
|
15
16
|
private mainnetNetworks;
|
|
16
17
|
private testnetNetworks;
|
|
18
|
+
private _openIntent?;
|
|
17
19
|
private _connectOptions?;
|
|
18
20
|
private _defaultNetworkId?;
|
|
19
21
|
private _chainId?;
|
|
20
22
|
private events;
|
|
21
|
-
constructor(signer: Signer | null, prompter: WalletUserPrompter | null, mainnetNetworks: Networks, testnetNetworks?: Networks);
|
|
23
|
+
constructor(signer: Signer | null | undefined, prompter: WalletUserPrompter | null, mainnetNetworks: Networks, testnetNetworks?: Networks);
|
|
22
24
|
signIn(signer: Signer | null, options?: WalletSignInOptions): Promise<void>;
|
|
25
|
+
signOut(): void;
|
|
26
|
+
signerReset(): void;
|
|
27
|
+
signerReady(): Promise<unknown>;
|
|
23
28
|
connect(options?: ConnectOptions): Promise<ConnectDetails>;
|
|
24
29
|
promptConnect: (options?: ConnectOptions | undefined) => Promise<ConnectDetails>;
|
|
25
30
|
sendMessageRequest(message: ProviderMessageRequest): Promise<ProviderMessageResponse>;
|
|
@@ -28,6 +33,8 @@ export declare class WalletRequestHandler implements ExternalProvider, JsonRpcHa
|
|
|
28
33
|
once<K extends keyof ProviderEventTypes>(event: K, fn: ProviderEventTypes[K]): void;
|
|
29
34
|
getAddress(): Promise<string>;
|
|
30
35
|
getChainId(): Promise<number>;
|
|
36
|
+
get openIntent(): OpenWalletIntent | undefined;
|
|
37
|
+
setOpenIntent(intent: OpenWalletIntent | undefined): void;
|
|
31
38
|
get connectOptions(): ConnectOptions | undefined;
|
|
32
39
|
setConnectOptions(options: ConnectOptions | undefined): void;
|
|
33
40
|
get defaultNetworkId(): string | number | undefined;
|
|
@@ -40,8 +47,8 @@ export declare class WalletRequestHandler implements ExternalProvider, JsonRpcHa
|
|
|
40
47
|
notifyWalletContext(): Promise<void>;
|
|
41
48
|
notifyClose(error?: ProviderRpcError): void;
|
|
42
49
|
isSignedIn(): boolean;
|
|
43
|
-
getSigner(): Signer | null;
|
|
44
|
-
setSigner(signer: Signer | null): void;
|
|
50
|
+
getSigner(): Signer | null | undefined;
|
|
51
|
+
setSigner(signer: Signer | null | undefined): void;
|
|
45
52
|
private handleConfirmWalletDeployPrompt;
|
|
46
53
|
}
|
|
47
54
|
export interface WalletUserPrompter {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0xsequence/provider",
|
|
3
|
-
"version": "0.35.
|
|
3
|
+
"version": "0.35.6",
|
|
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.6",
|
|
17
|
+
"@0xsequence/auth": "^0.35.6",
|
|
18
|
+
"@0xsequence/config": "^0.35.6",
|
|
19
|
+
"@0xsequence/network": "^0.35.6",
|
|
20
|
+
"@0xsequence/transactions": "^0.35.6",
|
|
21
|
+
"@0xsequence/utils": "^0.35.6",
|
|
22
|
+
"@0xsequence/wallet": "^0.35.6",
|
|
23
23
|
"@ethersproject/abstract-signer": "^5.5.0",
|
|
24
24
|
"@ethersproject/hash": "^5.5.0",
|
|
25
25
|
"@ethersproject/providers": "^5.5.1",
|
|
@@ -100,6 +100,11 @@ 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
|
+
|
|
103
108
|
// ensure initial handshake is complete before accepting
|
|
104
109
|
// other kinds of messages.
|
|
105
110
|
if (this._init !== InitState.OK) {
|
|
@@ -314,12 +319,20 @@ export abstract class BaseWalletTransport implements WalletTransport {
|
|
|
314
319
|
this.saveTransportSession({ sessionId, intent, networkId })
|
|
315
320
|
}
|
|
316
321
|
|
|
322
|
+
this.walletRequestHandler.setOpenIntent(intent)
|
|
323
|
+
|
|
324
|
+
// ensure signer is ready
|
|
325
|
+
if (this.walletRequestHandler.getSigner() === undefined) {
|
|
326
|
+
await this.walletRequestHandler.signerReady()
|
|
327
|
+
}
|
|
328
|
+
|
|
317
329
|
// init handshake for certain transports, before we can open the communication.
|
|
318
330
|
//
|
|
319
331
|
// for example, with the window-transport, we have to exchange messages to determine the
|
|
320
332
|
// origin host of the dapp.
|
|
321
333
|
await this.init()
|
|
322
334
|
|
|
335
|
+
|
|
323
336
|
// Prepare connect options from intent
|
|
324
337
|
if (intent && intent.type === 'connect' && intent.options) {
|
|
325
338
|
const connectOptions = intent.options
|