@0xsequence/provider 1.5.0 → 1.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -32,6 +32,10 @@ function isProviderTransport(transport) {
|
|
|
32
32
|
// ProviderMessageCallback is used to respond to ProviderMessage requests. The error
|
|
33
33
|
// argument is for exceptions during the execution, and response is the response payload
|
|
34
34
|
// which may contain the result or an error payload from the wallet.
|
|
35
|
+
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
|
|
37
|
+
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
|
|
35
39
|
class WindowSessionParams extends URLSearchParams {
|
|
36
40
|
static new(init) {
|
|
37
41
|
return new URLSearchParams(init);
|
|
@@ -93,8 +97,17 @@ class BaseProviderTransport {
|
|
|
93
97
|
var _this = this;
|
|
94
98
|
this.pendingMessageRequests = [];
|
|
95
99
|
this.responseCallbacks = new Map();
|
|
100
|
+
this.state = void 0;
|
|
96
101
|
this.confirmationOnly = false;
|
|
97
102
|
this.events = new eventemitter2.EventEmitter2();
|
|
103
|
+
this.openPayload = void 0;
|
|
104
|
+
this.connectPayload = void 0;
|
|
105
|
+
this.accountsChangedPayload = void 0;
|
|
106
|
+
this.networksPayload = void 0;
|
|
107
|
+
this.walletContextPayload = void 0;
|
|
108
|
+
this._sessionId = void 0;
|
|
109
|
+
this._init = void 0;
|
|
110
|
+
this._registered = void 0;
|
|
98
111
|
this.sendAsync = async function (request, callback, chainId) {
|
|
99
112
|
// here, we receive the message from the dapp provider call
|
|
100
113
|
|
|
@@ -120,7 +133,6 @@ class BaseProviderTransport {
|
|
|
120
133
|
if (!_this.isOpened()) {
|
|
121
134
|
await _this.waitUntilOpened(); // will throw on timeout
|
|
122
135
|
}
|
|
123
|
-
|
|
124
136
|
const response = await _this.sendMessageRequest({
|
|
125
137
|
idx: nextMessageIdx(),
|
|
126
138
|
type: EventType.MESSAGE,
|
|
@@ -325,7 +337,6 @@ class BaseProviderTransport {
|
|
|
325
337
|
}
|
|
326
338
|
}, 500); // TODO: be smarter about timer as we're processing the response callbacks..
|
|
327
339
|
}
|
|
328
|
-
|
|
329
340
|
if (!responseCallback) {
|
|
330
341
|
// NOTE: this would occur if 'idx' isn't set, which should never happen
|
|
331
342
|
// or when we register two handler, or duplicate messages with the same idx are sent,
|
|
@@ -706,11 +717,18 @@ async function resolveArrayProperties(object) {
|
|
|
706
717
|
|
|
707
718
|
const TRANSPORT_SESSION_LS_KEY = '@sequence.transportSession';
|
|
708
719
|
class BaseWalletTransport {
|
|
709
|
-
// appOrigin identifies the dapp's origin which opened the app. A transport
|
|
710
|
-
// will auto-detect and set this value if it can. This is determined
|
|
711
|
-
// as the parent app/window which opened the wallet.
|
|
712
720
|
constructor(walletRequestHandler) {
|
|
713
721
|
var _this = this;
|
|
722
|
+
this.walletRequestHandler = void 0;
|
|
723
|
+
this._sessionId = void 0;
|
|
724
|
+
this._registered = void 0;
|
|
725
|
+
this._init = void 0;
|
|
726
|
+
this._initNonce = void 0;
|
|
727
|
+
this._initCallback = void 0;
|
|
728
|
+
// appOrigin identifies the dapp's origin which opened the app. A transport
|
|
729
|
+
// will auto-detect and set this value if it can. This is determined
|
|
730
|
+
// as the parent app/window which opened the wallet.
|
|
731
|
+
this.appOrigin = void 0;
|
|
714
732
|
this.sendAsync = async function (request, callback, chainId) {
|
|
715
733
|
throw new Error('abstract method');
|
|
716
734
|
};
|
|
@@ -1130,6 +1148,8 @@ class BaseWalletTransport {
|
|
|
1130
1148
|
|
|
1131
1149
|
class ProxyMessageChannel {
|
|
1132
1150
|
constructor() {
|
|
1151
|
+
this.app = void 0;
|
|
1152
|
+
this.wallet = void 0;
|
|
1133
1153
|
const port1 = new ProxyMessageChannelPort();
|
|
1134
1154
|
const port2 = new ProxyMessageChannelPort();
|
|
1135
1155
|
port1.conn = port2;
|
|
@@ -1140,6 +1160,7 @@ class ProxyMessageChannel {
|
|
|
1140
1160
|
}
|
|
1141
1161
|
class ProxyMessageChannelPort {
|
|
1142
1162
|
constructor() {
|
|
1163
|
+
this.conn = void 0;
|
|
1143
1164
|
this.events = new eventemitter2.EventEmitter2();
|
|
1144
1165
|
// handle messages which hit this port
|
|
1145
1166
|
this.handleMessage = message => {
|
|
@@ -1175,6 +1196,7 @@ class ProxyMessageChannelPort {
|
|
|
1175
1196
|
class ProxyMessageProvider extends BaseProviderTransport {
|
|
1176
1197
|
constructor(port) {
|
|
1177
1198
|
super();
|
|
1199
|
+
this.port = void 0;
|
|
1178
1200
|
this.register = () => {
|
|
1179
1201
|
this.port.handleMessage = message => {
|
|
1180
1202
|
this.handleMessage(message);
|
|
@@ -1246,6 +1268,7 @@ class ProxyMessageProvider extends BaseProviderTransport {
|
|
|
1246
1268
|
class ProxyMessageHandler extends BaseWalletTransport {
|
|
1247
1269
|
constructor(walletRequestHandler, port) {
|
|
1248
1270
|
super(walletRequestHandler);
|
|
1271
|
+
this.port = void 0;
|
|
1249
1272
|
this.port = port;
|
|
1250
1273
|
this._init = InitState.OK;
|
|
1251
1274
|
}
|
|
@@ -1312,6 +1335,7 @@ let registeredUnrealMessageProvider;
|
|
|
1312
1335
|
class UnrealMessageProvider extends BaseProviderTransport {
|
|
1313
1336
|
constructor(walletAppURL) {
|
|
1314
1337
|
super();
|
|
1338
|
+
this.walletURL = void 0;
|
|
1315
1339
|
this.register = () => {
|
|
1316
1340
|
var _window$ue;
|
|
1317
1341
|
overrideLogs('dapp');
|
|
@@ -1330,7 +1354,7 @@ class UnrealMessageProvider extends BaseProviderTransport {
|
|
|
1330
1354
|
console.log('registering transport!');
|
|
1331
1355
|
};
|
|
1332
1356
|
this.unregister = () => {
|
|
1333
|
-
var _window$ue2
|
|
1357
|
+
var _window$ue2;
|
|
1334
1358
|
this._registered = false;
|
|
1335
1359
|
this.closeWallet();
|
|
1336
1360
|
|
|
@@ -1338,7 +1362,7 @@ class UnrealMessageProvider extends BaseProviderTransport {
|
|
|
1338
1362
|
if (registeredUnrealMessageProvider === this) {
|
|
1339
1363
|
registeredUnrealMessageProvider = undefined;
|
|
1340
1364
|
}
|
|
1341
|
-
if (((_window$ue2 = window.ue) == null
|
|
1365
|
+
if (((_window$ue2 = window.ue) == null || (_window$ue2 = _window$ue2.sequencewallettransport) == null ? void 0 : _window$ue2.onmessagefromwallet) === this.onUnrealCallback) {
|
|
1342
1366
|
delete window.ue.sequencewallettransport.onmessagefromwallet;
|
|
1343
1367
|
}
|
|
1344
1368
|
|
|
@@ -1391,10 +1415,10 @@ class UnrealMessageProvider extends BaseProviderTransport {
|
|
|
1391
1415
|
}
|
|
1392
1416
|
// all lowercase is an annoying limitation of Unreal CEF BindUObject
|
|
1393
1417
|
sendMessage(message) {
|
|
1394
|
-
var _window$ue3
|
|
1418
|
+
var _window$ue3;
|
|
1395
1419
|
const postedMessage = typeof message !== 'string' ? JSON.stringify(message) : message;
|
|
1396
1420
|
console.log('Sending message to wallet:', postedMessage);
|
|
1397
|
-
(_window$ue3 = window.ue) == null
|
|
1421
|
+
(_window$ue3 = window.ue) == null || (_window$ue3 = _window$ue3.sequencewallettransport) == null || _window$ue3.sendmessagetowallet(postedMessage);
|
|
1398
1422
|
}
|
|
1399
1423
|
}
|
|
1400
1424
|
|
|
@@ -1477,15 +1501,15 @@ class UnrealMessageHandler extends BaseWalletTransport {
|
|
|
1477
1501
|
});
|
|
1478
1502
|
}
|
|
1479
1503
|
unregister() {
|
|
1480
|
-
var _window$ue2
|
|
1481
|
-
if (((_window$ue2 = window.ue) == null
|
|
1504
|
+
var _window$ue2;
|
|
1505
|
+
if (((_window$ue2 = window.ue) == null || (_window$ue2 = _window$ue2.sequencewallettransport) == null ? void 0 : _window$ue2.onmessagefromsequencejs) === this.onMessageFromUnreal) {
|
|
1482
1506
|
delete window.ue.sequencewallettransport.onmessagefromsequencejs;
|
|
1483
1507
|
}
|
|
1484
1508
|
this._registered = false;
|
|
1485
1509
|
}
|
|
1486
1510
|
// sendMessage sends message to the dapp window
|
|
1487
1511
|
sendMessage(message) {
|
|
1488
|
-
var _window$ue3
|
|
1512
|
+
var _window$ue3;
|
|
1489
1513
|
if (message.type !== EventType.INIT && this._init !== InitState.OK) {
|
|
1490
1514
|
utils.logger.error('impossible state, should not be calling postMessage until inited');
|
|
1491
1515
|
return;
|
|
@@ -1494,7 +1518,7 @@ class UnrealMessageHandler extends BaseWalletTransport {
|
|
|
1494
1518
|
const payload = JSON.stringify(message);
|
|
1495
1519
|
|
|
1496
1520
|
// post-message to app.
|
|
1497
|
-
(_window$ue3 = window.ue) == null
|
|
1521
|
+
(_window$ue3 = window.ue) == null || (_window$ue3 = _window$ue3.sequencewallettransport) == null || _window$ue3.sendmessagetosequencejs(payload);
|
|
1498
1522
|
}
|
|
1499
1523
|
}
|
|
1500
1524
|
|
|
@@ -1503,6 +1527,7 @@ class ExtensionMessageHandler extends BaseWalletTransport {
|
|
|
1503
1527
|
constructor(walletRequestHandler, runtime) {
|
|
1504
1528
|
super(walletRequestHandler);
|
|
1505
1529
|
this.runtime = runtime;
|
|
1530
|
+
this.port = void 0;
|
|
1506
1531
|
this._init = InitState.OK;
|
|
1507
1532
|
}
|
|
1508
1533
|
register() {
|
|
@@ -1552,6 +1577,7 @@ class BaseInjectedTransport extends eventemitter2.EventEmitter2 {
|
|
|
1552
1577
|
var _this;
|
|
1553
1578
|
super();
|
|
1554
1579
|
_this = this;
|
|
1580
|
+
this.stream = stream;
|
|
1555
1581
|
this.responseCallbacks = new Map();
|
|
1556
1582
|
this._messageIdx = 0;
|
|
1557
1583
|
this.nextMessageIdx = () => ++this._messageIdx;
|
|
@@ -1612,7 +1638,6 @@ class BaseInjectedTransport extends eventemitter2.EventEmitter2 {
|
|
|
1612
1638
|
_this.sendMessage(message);
|
|
1613
1639
|
});
|
|
1614
1640
|
};
|
|
1615
|
-
this.stream = stream;
|
|
1616
1641
|
this.stream.on('data', this.handleMessage);
|
|
1617
1642
|
}
|
|
1618
1643
|
sendMessage(message) {
|
|
@@ -1628,6 +1653,8 @@ let registeredWindowMessageProvider;
|
|
|
1628
1653
|
class WindowMessageProvider extends BaseProviderTransport {
|
|
1629
1654
|
constructor(walletAppURL) {
|
|
1630
1655
|
super();
|
|
1656
|
+
this.walletURL = void 0;
|
|
1657
|
+
this.walletWindow = void 0;
|
|
1631
1658
|
this.register = () => {
|
|
1632
1659
|
if (registeredWindowMessageProvider) {
|
|
1633
1660
|
// overriding the registered message provider
|
|
@@ -1780,7 +1807,7 @@ class WindowMessageProvider extends BaseProviderTransport {
|
|
|
1780
1807
|
closeWallet() {
|
|
1781
1808
|
var _this$walletWindow;
|
|
1782
1809
|
this.close();
|
|
1783
|
-
(_this$walletWindow = this.walletWindow) == null
|
|
1810
|
+
(_this$walletWindow = this.walletWindow) == null || _this$walletWindow.close();
|
|
1784
1811
|
}
|
|
1785
1812
|
sendMessage(message) {
|
|
1786
1813
|
if (!this.walletWindow) {
|
|
@@ -1797,6 +1824,7 @@ class WindowMessageHandler extends BaseWalletTransport {
|
|
|
1797
1824
|
var _this;
|
|
1798
1825
|
super(walletRequestHandler);
|
|
1799
1826
|
_this = this;
|
|
1827
|
+
this.parentWindow = void 0;
|
|
1800
1828
|
this._isPopup = false;
|
|
1801
1829
|
// onmessage is called when (the wallet) receives request messages from the dapp
|
|
1802
1830
|
// over the window post-messaging transport
|
|
@@ -1945,6 +1973,8 @@ function isMuxTransportTemplate(obj) {
|
|
|
1945
1973
|
class MuxMessageProvider {
|
|
1946
1974
|
constructor(...messageProviders) {
|
|
1947
1975
|
var _this = this;
|
|
1976
|
+
this.messageProviders = void 0;
|
|
1977
|
+
this.provider = void 0;
|
|
1948
1978
|
this.register = () => {
|
|
1949
1979
|
if (this.messageProviders.length === 1) {
|
|
1950
1980
|
this.provider = this.messageProviders[0];
|
|
@@ -2033,7 +2063,6 @@ class MuxMessageProvider {
|
|
|
2033
2063
|
// send all requests to the WindowMessageProvider anyways. By allowing it, if browser restarts, it will break
|
|
2034
2064
|
// the entire extension because messageProvider.provider will be undefined. So this is a hack to fix it.
|
|
2035
2065
|
}
|
|
2036
|
-
|
|
2037
2066
|
if ((_template$unrealTrans = template.unrealTransport) != null && _template$unrealTrans.enabled && template.windowTransport && template.walletAppURL) {
|
|
2038
2067
|
const unrealMessageProvider = new UnrealMessageProvider(template.walletAppURL);
|
|
2039
2068
|
muxMessageProvider.add(unrealMessageProvider);
|
|
@@ -2155,7 +2184,12 @@ class WalletRequestHandler {
|
|
|
2155
2184
|
// signer interface of the wallet. A null value means there is no signer (ie. user not signed in). An undefined
|
|
2156
2185
|
// value means the signer state is unknown, usually meaning the wallet app is booting up and initializing. Of course
|
|
2157
2186
|
// a Signer value is the actually interface to a signed-in account
|
|
2187
|
+
this.account = void 0;
|
|
2158
2188
|
this.signerReadyCallbacks = [];
|
|
2189
|
+
this.prompter = void 0;
|
|
2190
|
+
this.networks = void 0;
|
|
2191
|
+
this._openIntent = void 0;
|
|
2192
|
+
this._connectOptions = void 0;
|
|
2159
2193
|
this.events = new eventemitter2.EventEmitter2();
|
|
2160
2194
|
this.onConnectOptionsChange = undefined;
|
|
2161
2195
|
this.promptConnect = async function (options) {
|
|
@@ -2644,6 +2678,10 @@ class WalletRequestHandler {
|
|
|
2644
2678
|
}
|
|
2645
2679
|
}
|
|
2646
2680
|
signOut() {
|
|
2681
|
+
if (this.account) {
|
|
2682
|
+
this.notifyDisconnect();
|
|
2683
|
+
}
|
|
2684
|
+
|
|
2647
2685
|
// signed out state
|
|
2648
2686
|
this.setAccount(null);
|
|
2649
2687
|
}
|
|
@@ -2752,7 +2790,7 @@ class WalletRequestHandler {
|
|
|
2752
2790
|
setConnectOptions(options) {
|
|
2753
2791
|
var _this$onConnectOption;
|
|
2754
2792
|
this._connectOptions = options;
|
|
2755
|
-
(_this$onConnectOption = this.onConnectOptionsChange) == null
|
|
2793
|
+
(_this$onConnectOption = this.onConnectOptionsChange) == null || _this$onConnectOption.call(this, options);
|
|
2756
2794
|
}
|
|
2757
2795
|
async setDefaultChainId(chainId) {
|
|
2758
2796
|
var _this$prompter4;
|
|
@@ -2794,7 +2832,7 @@ class WalletRequestHandler {
|
|
|
2794
2832
|
if (network$1) {
|
|
2795
2833
|
var _session$networks;
|
|
2796
2834
|
// Delete the isDefaultChain property from the session network
|
|
2797
|
-
(_session$networks = session.networks) == null
|
|
2835
|
+
(_session$networks = session.networks) == null || _session$networks.forEach(n => delete n.isDefaultChain);
|
|
2798
2836
|
|
|
2799
2837
|
// Add the isDefaultChain property to the network with the given networkId
|
|
2800
2838
|
network$1.isDefaultChain = true;
|
|
@@ -2898,11 +2936,11 @@ class SequenceSigner {
|
|
|
2898
2936
|
return this.provider.utils;
|
|
2899
2937
|
}
|
|
2900
2938
|
constructor(client, provider) {
|
|
2939
|
+
this.client = client;
|
|
2940
|
+
this.provider = provider;
|
|
2901
2941
|
this.singleNetworkSigners = {};
|
|
2902
2942
|
this._isSigner = true;
|
|
2903
2943
|
this._isSequenceSigner = true;
|
|
2904
|
-
this.client = client;
|
|
2905
|
-
this.provider = provider;
|
|
2906
2944
|
}
|
|
2907
2945
|
async getAddress() {
|
|
2908
2946
|
return this.client.getAddress();
|
|
@@ -3060,8 +3098,8 @@ class SequenceSigner {
|
|
|
3060
3098
|
class SingleNetworkSequenceSigner extends SequenceSigner {
|
|
3061
3099
|
constructor(client, provider, chainId) {
|
|
3062
3100
|
super(client, provider.getProvider(chainId));
|
|
3063
|
-
this._isSingleNetworkSequenceSigner = true;
|
|
3064
3101
|
this.chainId = chainId;
|
|
3102
|
+
this._isSingleNetworkSequenceSigner = true;
|
|
3065
3103
|
}
|
|
3066
3104
|
_useChainId(chainId) {
|
|
3067
3105
|
const provided = this.provider.toChainId(chainId);
|
|
@@ -3169,11 +3207,13 @@ class SequenceProvider extends ethers.ethers.providers.BaseProvider {
|
|
|
3169
3207
|
super(client.getChainId());
|
|
3170
3208
|
|
|
3171
3209
|
// Emit events as defined by EIP-1193
|
|
3172
|
-
this.singleNetworkProviders = {};
|
|
3173
|
-
this._isSequenceProvider = true;
|
|
3174
3210
|
this.client = client;
|
|
3175
3211
|
this.providerFor = providerFor;
|
|
3176
3212
|
this.networks = networks;
|
|
3213
|
+
this.singleNetworkProviders = {};
|
|
3214
|
+
this._isSequenceProvider = true;
|
|
3215
|
+
this.utils = void 0;
|
|
3216
|
+
this.signer = void 0;
|
|
3177
3217
|
client.onConnect(details => {
|
|
3178
3218
|
this.emit('connect', details);
|
|
3179
3219
|
});
|
|
@@ -3484,8 +3524,8 @@ function normalizeChainId(chainId) {
|
|
|
3484
3524
|
class SingleNetworkSequenceProvider extends SequenceProvider {
|
|
3485
3525
|
constructor(client, providerFor, chainId) {
|
|
3486
3526
|
super(client, providerFor);
|
|
3487
|
-
this._isSingleNetworkSequenceProvider = true;
|
|
3488
3527
|
this.chainId = chainId;
|
|
3528
|
+
this._isSingleNetworkSequenceProvider = true;
|
|
3489
3529
|
}
|
|
3490
3530
|
_useChainId(chainId) {
|
|
3491
3531
|
const provided = this.toChainId(chainId);
|
|
@@ -3533,7 +3573,7 @@ class SingleNetworkSequenceProvider extends SequenceProvider {
|
|
|
3533
3573
|
|
|
3534
3574
|
var packageJson = {
|
|
3535
3575
|
name: "@0xsequence/provider",
|
|
3536
|
-
version: "1.
|
|
3576
|
+
version: "1.6.1",
|
|
3537
3577
|
description: "provider sub-package for Sequence",
|
|
3538
3578
|
repository: "https://github.com/0xsequence/sequence.js/tree/master/packages/provider",
|
|
3539
3579
|
source: "src/index.ts",
|
|
@@ -3544,7 +3584,7 @@ var packageJson = {
|
|
|
3544
3584
|
scripts: {
|
|
3545
3585
|
test: "pnpm test:concurrently 'pnpm test:run'",
|
|
3546
3586
|
"test:run": "pnpm test:file tests/**/*.spec.ts",
|
|
3547
|
-
"test:file": "NODE_OPTIONS='--
|
|
3587
|
+
"test:file": "NODE_OPTIONS='--import tsx' mocha --timeout 30000",
|
|
3548
3588
|
typecheck: "tsc --noEmit",
|
|
3549
3589
|
"test:concurrently": "concurrently -k --success first 'pnpm start:hardhat1' 'pnpm start:hardhat2'",
|
|
3550
3590
|
"start:hardhat1": "pnpm start:hardhat1:verbose > /dev/null 2>&1",
|
|
@@ -3626,9 +3666,9 @@ class SequenceClientSession {
|
|
|
3626
3666
|
SequenceClientSession.SESSION_LOCALSTORE_KEY = '@sequence.session';
|
|
3627
3667
|
class DefaultChainIdTracker {
|
|
3628
3668
|
constructor(store, startingChainId = 1) {
|
|
3629
|
-
this.callbacks = [];
|
|
3630
3669
|
this.store = store;
|
|
3631
3670
|
this.startingChainId = startingChainId;
|
|
3671
|
+
this.callbacks = [];
|
|
3632
3672
|
store.onItemChange(DefaultChainIdTracker.SESSION_CHAIN_ID_KEY, value => {
|
|
3633
3673
|
if (value) {
|
|
3634
3674
|
const chainId = parseInt(value);
|
|
@@ -3661,12 +3701,18 @@ DefaultChainIdTracker.SESSION_CHAIN_ID_KEY = '@sequence.session.defaultChainId';
|
|
|
3661
3701
|
* and it allows to perform all sequence specific (or write) operations related to the wallet.
|
|
3662
3702
|
*s
|
|
3663
3703
|
* It doesn't implement a full ethereum Provider, it doesn't include read-only methods.
|
|
3664
|
-
*/
|
|
3704
|
+
*/
|
|
3705
|
+
|
|
3706
|
+
// TODO: rename Client to transport.. or something.. like SequenceTransport ..
|
|
3665
3707
|
class SequenceClient {
|
|
3666
3708
|
constructor(transport, store, options, projectAccessKey) {
|
|
3667
3709
|
var _options$defaultEIP;
|
|
3668
|
-
this.callbacks = {};
|
|
3669
3710
|
this.projectAccessKey = projectAccessKey;
|
|
3711
|
+
this.session = void 0;
|
|
3712
|
+
this.defaultChainId = void 0;
|
|
3713
|
+
this.callbacks = {};
|
|
3714
|
+
this.transport = void 0;
|
|
3715
|
+
this.defaultEIP6492 = void 0;
|
|
3670
3716
|
if (isMuxTransportTemplate(transport)) {
|
|
3671
3717
|
this.transport = MuxMessageProvider.new(transport);
|
|
3672
3718
|
} else if (isProviderTransport(transport)) {
|
|
@@ -3683,12 +3729,12 @@ class SequenceClient {
|
|
|
3683
3729
|
if (accounts.length > 1) {
|
|
3684
3730
|
console.warn('SequenceClient: wallet-webapp returned more than one account');
|
|
3685
3731
|
}
|
|
3686
|
-
(_this$callbacks$accou = this.callbacks.accountsChanged) == null
|
|
3732
|
+
(_this$callbacks$accou = this.callbacks.accountsChanged) == null || _this$callbacks$accou.forEach(cb => cb(accounts));
|
|
3687
3733
|
});
|
|
3688
3734
|
this.transport.on('connect', response => {
|
|
3689
3735
|
var _this$callbacks$conne;
|
|
3690
3736
|
const chainIdHex = ethers.ethers.utils.hexValue(this.getChainId());
|
|
3691
|
-
(_this$callbacks$conne = this.callbacks.connect) == null
|
|
3737
|
+
(_this$callbacks$conne = this.callbacks.connect) == null || _this$callbacks$conne.forEach(cb => cb(_extends({}, response, {
|
|
3692
3738
|
// Ignore the full connect response
|
|
3693
3739
|
// use the chainId defined locally
|
|
3694
3740
|
chainId: chainIdHex
|
|
@@ -3696,27 +3742,27 @@ class SequenceClient {
|
|
|
3696
3742
|
});
|
|
3697
3743
|
this.transport.on('disconnect', (error, origin) => {
|
|
3698
3744
|
var _this$callbacks$disco;
|
|
3699
|
-
(_this$callbacks$disco = this.callbacks.disconnect) == null
|
|
3745
|
+
(_this$callbacks$disco = this.callbacks.disconnect) == null || _this$callbacks$disco.forEach(cb => cb(error, origin));
|
|
3700
3746
|
});
|
|
3701
3747
|
this.transport.on('networks', networks => {
|
|
3702
3748
|
var _this$callbacks$netwo;
|
|
3703
|
-
(_this$callbacks$netwo = this.callbacks.networks) == null
|
|
3749
|
+
(_this$callbacks$netwo = this.callbacks.networks) == null || _this$callbacks$netwo.forEach(cb => cb(networks));
|
|
3704
3750
|
});
|
|
3705
3751
|
this.transport.on('walletContext', context => {
|
|
3706
3752
|
var _this$callbacks$walle;
|
|
3707
|
-
(_this$callbacks$walle = this.callbacks.walletContext) == null
|
|
3753
|
+
(_this$callbacks$walle = this.callbacks.walletContext) == null || _this$callbacks$walle.forEach(cb => cb(context));
|
|
3708
3754
|
});
|
|
3709
3755
|
this.transport.on('open', info => {
|
|
3710
3756
|
var _this$callbacks$open;
|
|
3711
|
-
(_this$callbacks$open = this.callbacks.open) == null
|
|
3757
|
+
(_this$callbacks$open = this.callbacks.open) == null || _this$callbacks$open.forEach(cb => cb(info));
|
|
3712
3758
|
});
|
|
3713
3759
|
this.transport.on('close', () => {
|
|
3714
3760
|
var _this$callbacks$close;
|
|
3715
|
-
(_this$callbacks$close = this.callbacks.close) == null
|
|
3761
|
+
(_this$callbacks$close = this.callbacks.close) == null || _this$callbacks$close.forEach(cb => cb());
|
|
3716
3762
|
});
|
|
3717
3763
|
this.transport.on('chainChanged', (chainIdHex, origin) => {
|
|
3718
3764
|
var _this$callbacks$chain;
|
|
3719
|
-
(_this$callbacks$chain = this.callbacks.chainChanged) == null
|
|
3765
|
+
(_this$callbacks$chain = this.callbacks.chainChanged) == null || _this$callbacks$chain.forEach(cb => cb(chainIdHex, origin));
|
|
3720
3766
|
});
|
|
3721
3767
|
|
|
3722
3768
|
// We don't listen for the transport chainChanged event
|
|
@@ -3724,7 +3770,7 @@ class SequenceClient {
|
|
|
3724
3770
|
this.defaultChainId.onDefaultChainIdChanged(chainId => {
|
|
3725
3771
|
var _this$callbacks$chain2;
|
|
3726
3772
|
const chainIdHex = ethers.ethers.utils.hexValue(chainId);
|
|
3727
|
-
(_this$callbacks$chain2 = this.callbacks.chainChanged) == null
|
|
3773
|
+
(_this$callbacks$chain2 = this.callbacks.chainChanged) == null || _this$callbacks$chain2.forEach(cb => cb(chainIdHex));
|
|
3728
3774
|
});
|
|
3729
3775
|
}
|
|
3730
3776
|
|
|
@@ -32,6 +32,10 @@ function isProviderTransport(transport) {
|
|
|
32
32
|
// ProviderMessageCallback is used to respond to ProviderMessage requests. The error
|
|
33
33
|
// argument is for exceptions during the execution, and response is the response payload
|
|
34
34
|
// which may contain the result or an error payload from the wallet.
|
|
35
|
+
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
|
|
37
|
+
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
|
|
35
39
|
class WindowSessionParams extends URLSearchParams {
|
|
36
40
|
static new(init) {
|
|
37
41
|
return new URLSearchParams(init);
|
|
@@ -93,8 +97,17 @@ class BaseProviderTransport {
|
|
|
93
97
|
var _this = this;
|
|
94
98
|
this.pendingMessageRequests = [];
|
|
95
99
|
this.responseCallbacks = new Map();
|
|
100
|
+
this.state = void 0;
|
|
96
101
|
this.confirmationOnly = false;
|
|
97
102
|
this.events = new eventemitter2.EventEmitter2();
|
|
103
|
+
this.openPayload = void 0;
|
|
104
|
+
this.connectPayload = void 0;
|
|
105
|
+
this.accountsChangedPayload = void 0;
|
|
106
|
+
this.networksPayload = void 0;
|
|
107
|
+
this.walletContextPayload = void 0;
|
|
108
|
+
this._sessionId = void 0;
|
|
109
|
+
this._init = void 0;
|
|
110
|
+
this._registered = void 0;
|
|
98
111
|
this.sendAsync = async function (request, callback, chainId) {
|
|
99
112
|
// here, we receive the message from the dapp provider call
|
|
100
113
|
|
|
@@ -120,7 +133,6 @@ class BaseProviderTransport {
|
|
|
120
133
|
if (!_this.isOpened()) {
|
|
121
134
|
await _this.waitUntilOpened(); // will throw on timeout
|
|
122
135
|
}
|
|
123
|
-
|
|
124
136
|
const response = await _this.sendMessageRequest({
|
|
125
137
|
idx: nextMessageIdx(),
|
|
126
138
|
type: EventType.MESSAGE,
|
|
@@ -325,7 +337,6 @@ class BaseProviderTransport {
|
|
|
325
337
|
}
|
|
326
338
|
}, 500); // TODO: be smarter about timer as we're processing the response callbacks..
|
|
327
339
|
}
|
|
328
|
-
|
|
329
340
|
if (!responseCallback) {
|
|
330
341
|
// NOTE: this would occur if 'idx' isn't set, which should never happen
|
|
331
342
|
// or when we register two handler, or duplicate messages with the same idx are sent,
|
|
@@ -706,11 +717,18 @@ async function resolveArrayProperties(object) {
|
|
|
706
717
|
|
|
707
718
|
const TRANSPORT_SESSION_LS_KEY = '@sequence.transportSession';
|
|
708
719
|
class BaseWalletTransport {
|
|
709
|
-
// appOrigin identifies the dapp's origin which opened the app. A transport
|
|
710
|
-
// will auto-detect and set this value if it can. This is determined
|
|
711
|
-
// as the parent app/window which opened the wallet.
|
|
712
720
|
constructor(walletRequestHandler) {
|
|
713
721
|
var _this = this;
|
|
722
|
+
this.walletRequestHandler = void 0;
|
|
723
|
+
this._sessionId = void 0;
|
|
724
|
+
this._registered = void 0;
|
|
725
|
+
this._init = void 0;
|
|
726
|
+
this._initNonce = void 0;
|
|
727
|
+
this._initCallback = void 0;
|
|
728
|
+
// appOrigin identifies the dapp's origin which opened the app. A transport
|
|
729
|
+
// will auto-detect and set this value if it can. This is determined
|
|
730
|
+
// as the parent app/window which opened the wallet.
|
|
731
|
+
this.appOrigin = void 0;
|
|
714
732
|
this.sendAsync = async function (request, callback, chainId) {
|
|
715
733
|
throw new Error('abstract method');
|
|
716
734
|
};
|
|
@@ -1130,6 +1148,8 @@ class BaseWalletTransport {
|
|
|
1130
1148
|
|
|
1131
1149
|
class ProxyMessageChannel {
|
|
1132
1150
|
constructor() {
|
|
1151
|
+
this.app = void 0;
|
|
1152
|
+
this.wallet = void 0;
|
|
1133
1153
|
const port1 = new ProxyMessageChannelPort();
|
|
1134
1154
|
const port2 = new ProxyMessageChannelPort();
|
|
1135
1155
|
port1.conn = port2;
|
|
@@ -1140,6 +1160,7 @@ class ProxyMessageChannel {
|
|
|
1140
1160
|
}
|
|
1141
1161
|
class ProxyMessageChannelPort {
|
|
1142
1162
|
constructor() {
|
|
1163
|
+
this.conn = void 0;
|
|
1143
1164
|
this.events = new eventemitter2.EventEmitter2();
|
|
1144
1165
|
// handle messages which hit this port
|
|
1145
1166
|
this.handleMessage = message => {
|
|
@@ -1175,6 +1196,7 @@ class ProxyMessageChannelPort {
|
|
|
1175
1196
|
class ProxyMessageProvider extends BaseProviderTransport {
|
|
1176
1197
|
constructor(port) {
|
|
1177
1198
|
super();
|
|
1199
|
+
this.port = void 0;
|
|
1178
1200
|
this.register = () => {
|
|
1179
1201
|
this.port.handleMessage = message => {
|
|
1180
1202
|
this.handleMessage(message);
|
|
@@ -1246,6 +1268,7 @@ class ProxyMessageProvider extends BaseProviderTransport {
|
|
|
1246
1268
|
class ProxyMessageHandler extends BaseWalletTransport {
|
|
1247
1269
|
constructor(walletRequestHandler, port) {
|
|
1248
1270
|
super(walletRequestHandler);
|
|
1271
|
+
this.port = void 0;
|
|
1249
1272
|
this.port = port;
|
|
1250
1273
|
this._init = InitState.OK;
|
|
1251
1274
|
}
|
|
@@ -1312,6 +1335,7 @@ let registeredUnrealMessageProvider;
|
|
|
1312
1335
|
class UnrealMessageProvider extends BaseProviderTransport {
|
|
1313
1336
|
constructor(walletAppURL) {
|
|
1314
1337
|
super();
|
|
1338
|
+
this.walletURL = void 0;
|
|
1315
1339
|
this.register = () => {
|
|
1316
1340
|
var _window$ue;
|
|
1317
1341
|
overrideLogs('dapp');
|
|
@@ -1330,7 +1354,7 @@ class UnrealMessageProvider extends BaseProviderTransport {
|
|
|
1330
1354
|
console.log('registering transport!');
|
|
1331
1355
|
};
|
|
1332
1356
|
this.unregister = () => {
|
|
1333
|
-
var _window$ue2
|
|
1357
|
+
var _window$ue2;
|
|
1334
1358
|
this._registered = false;
|
|
1335
1359
|
this.closeWallet();
|
|
1336
1360
|
|
|
@@ -1338,7 +1362,7 @@ class UnrealMessageProvider extends BaseProviderTransport {
|
|
|
1338
1362
|
if (registeredUnrealMessageProvider === this) {
|
|
1339
1363
|
registeredUnrealMessageProvider = undefined;
|
|
1340
1364
|
}
|
|
1341
|
-
if (((_window$ue2 = window.ue) == null
|
|
1365
|
+
if (((_window$ue2 = window.ue) == null || (_window$ue2 = _window$ue2.sequencewallettransport) == null ? void 0 : _window$ue2.onmessagefromwallet) === this.onUnrealCallback) {
|
|
1342
1366
|
delete window.ue.sequencewallettransport.onmessagefromwallet;
|
|
1343
1367
|
}
|
|
1344
1368
|
|
|
@@ -1391,10 +1415,10 @@ class UnrealMessageProvider extends BaseProviderTransport {
|
|
|
1391
1415
|
}
|
|
1392
1416
|
// all lowercase is an annoying limitation of Unreal CEF BindUObject
|
|
1393
1417
|
sendMessage(message) {
|
|
1394
|
-
var _window$ue3
|
|
1418
|
+
var _window$ue3;
|
|
1395
1419
|
const postedMessage = typeof message !== 'string' ? JSON.stringify(message) : message;
|
|
1396
1420
|
console.log('Sending message to wallet:', postedMessage);
|
|
1397
|
-
(_window$ue3 = window.ue) == null
|
|
1421
|
+
(_window$ue3 = window.ue) == null || (_window$ue3 = _window$ue3.sequencewallettransport) == null || _window$ue3.sendmessagetowallet(postedMessage);
|
|
1398
1422
|
}
|
|
1399
1423
|
}
|
|
1400
1424
|
|
|
@@ -1477,15 +1501,15 @@ class UnrealMessageHandler extends BaseWalletTransport {
|
|
|
1477
1501
|
});
|
|
1478
1502
|
}
|
|
1479
1503
|
unregister() {
|
|
1480
|
-
var _window$ue2
|
|
1481
|
-
if (((_window$ue2 = window.ue) == null
|
|
1504
|
+
var _window$ue2;
|
|
1505
|
+
if (((_window$ue2 = window.ue) == null || (_window$ue2 = _window$ue2.sequencewallettransport) == null ? void 0 : _window$ue2.onmessagefromsequencejs) === this.onMessageFromUnreal) {
|
|
1482
1506
|
delete window.ue.sequencewallettransport.onmessagefromsequencejs;
|
|
1483
1507
|
}
|
|
1484
1508
|
this._registered = false;
|
|
1485
1509
|
}
|
|
1486
1510
|
// sendMessage sends message to the dapp window
|
|
1487
1511
|
sendMessage(message) {
|
|
1488
|
-
var _window$ue3
|
|
1512
|
+
var _window$ue3;
|
|
1489
1513
|
if (message.type !== EventType.INIT && this._init !== InitState.OK) {
|
|
1490
1514
|
utils.logger.error('impossible state, should not be calling postMessage until inited');
|
|
1491
1515
|
return;
|
|
@@ -1494,7 +1518,7 @@ class UnrealMessageHandler extends BaseWalletTransport {
|
|
|
1494
1518
|
const payload = JSON.stringify(message);
|
|
1495
1519
|
|
|
1496
1520
|
// post-message to app.
|
|
1497
|
-
(_window$ue3 = window.ue) == null
|
|
1521
|
+
(_window$ue3 = window.ue) == null || (_window$ue3 = _window$ue3.sequencewallettransport) == null || _window$ue3.sendmessagetosequencejs(payload);
|
|
1498
1522
|
}
|
|
1499
1523
|
}
|
|
1500
1524
|
|
|
@@ -1503,6 +1527,7 @@ class ExtensionMessageHandler extends BaseWalletTransport {
|
|
|
1503
1527
|
constructor(walletRequestHandler, runtime) {
|
|
1504
1528
|
super(walletRequestHandler);
|
|
1505
1529
|
this.runtime = runtime;
|
|
1530
|
+
this.port = void 0;
|
|
1506
1531
|
this._init = InitState.OK;
|
|
1507
1532
|
}
|
|
1508
1533
|
register() {
|
|
@@ -1552,6 +1577,7 @@ class BaseInjectedTransport extends eventemitter2.EventEmitter2 {
|
|
|
1552
1577
|
var _this;
|
|
1553
1578
|
super();
|
|
1554
1579
|
_this = this;
|
|
1580
|
+
this.stream = stream;
|
|
1555
1581
|
this.responseCallbacks = new Map();
|
|
1556
1582
|
this._messageIdx = 0;
|
|
1557
1583
|
this.nextMessageIdx = () => ++this._messageIdx;
|
|
@@ -1612,7 +1638,6 @@ class BaseInjectedTransport extends eventemitter2.EventEmitter2 {
|
|
|
1612
1638
|
_this.sendMessage(message);
|
|
1613
1639
|
});
|
|
1614
1640
|
};
|
|
1615
|
-
this.stream = stream;
|
|
1616
1641
|
this.stream.on('data', this.handleMessage);
|
|
1617
1642
|
}
|
|
1618
1643
|
sendMessage(message) {
|
|
@@ -1628,6 +1653,8 @@ let registeredWindowMessageProvider;
|
|
|
1628
1653
|
class WindowMessageProvider extends BaseProviderTransport {
|
|
1629
1654
|
constructor(walletAppURL) {
|
|
1630
1655
|
super();
|
|
1656
|
+
this.walletURL = void 0;
|
|
1657
|
+
this.walletWindow = void 0;
|
|
1631
1658
|
this.register = () => {
|
|
1632
1659
|
if (registeredWindowMessageProvider) {
|
|
1633
1660
|
// overriding the registered message provider
|
|
@@ -1780,7 +1807,7 @@ class WindowMessageProvider extends BaseProviderTransport {
|
|
|
1780
1807
|
closeWallet() {
|
|
1781
1808
|
var _this$walletWindow;
|
|
1782
1809
|
this.close();
|
|
1783
|
-
(_this$walletWindow = this.walletWindow) == null
|
|
1810
|
+
(_this$walletWindow = this.walletWindow) == null || _this$walletWindow.close();
|
|
1784
1811
|
}
|
|
1785
1812
|
sendMessage(message) {
|
|
1786
1813
|
if (!this.walletWindow) {
|
|
@@ -1797,6 +1824,7 @@ class WindowMessageHandler extends BaseWalletTransport {
|
|
|
1797
1824
|
var _this;
|
|
1798
1825
|
super(walletRequestHandler);
|
|
1799
1826
|
_this = this;
|
|
1827
|
+
this.parentWindow = void 0;
|
|
1800
1828
|
this._isPopup = false;
|
|
1801
1829
|
// onmessage is called when (the wallet) receives request messages from the dapp
|
|
1802
1830
|
// over the window post-messaging transport
|
|
@@ -1945,6 +1973,8 @@ function isMuxTransportTemplate(obj) {
|
|
|
1945
1973
|
class MuxMessageProvider {
|
|
1946
1974
|
constructor(...messageProviders) {
|
|
1947
1975
|
var _this = this;
|
|
1976
|
+
this.messageProviders = void 0;
|
|
1977
|
+
this.provider = void 0;
|
|
1948
1978
|
this.register = () => {
|
|
1949
1979
|
if (this.messageProviders.length === 1) {
|
|
1950
1980
|
this.provider = this.messageProviders[0];
|
|
@@ -2033,7 +2063,6 @@ class MuxMessageProvider {
|
|
|
2033
2063
|
// send all requests to the WindowMessageProvider anyways. By allowing it, if browser restarts, it will break
|
|
2034
2064
|
// the entire extension because messageProvider.provider will be undefined. So this is a hack to fix it.
|
|
2035
2065
|
}
|
|
2036
|
-
|
|
2037
2066
|
if ((_template$unrealTrans = template.unrealTransport) != null && _template$unrealTrans.enabled && template.windowTransport && template.walletAppURL) {
|
|
2038
2067
|
const unrealMessageProvider = new UnrealMessageProvider(template.walletAppURL);
|
|
2039
2068
|
muxMessageProvider.add(unrealMessageProvider);
|
|
@@ -2155,7 +2184,12 @@ class WalletRequestHandler {
|
|
|
2155
2184
|
// signer interface of the wallet. A null value means there is no signer (ie. user not signed in). An undefined
|
|
2156
2185
|
// value means the signer state is unknown, usually meaning the wallet app is booting up and initializing. Of course
|
|
2157
2186
|
// a Signer value is the actually interface to a signed-in account
|
|
2187
|
+
this.account = void 0;
|
|
2158
2188
|
this.signerReadyCallbacks = [];
|
|
2189
|
+
this.prompter = void 0;
|
|
2190
|
+
this.networks = void 0;
|
|
2191
|
+
this._openIntent = void 0;
|
|
2192
|
+
this._connectOptions = void 0;
|
|
2159
2193
|
this.events = new eventemitter2.EventEmitter2();
|
|
2160
2194
|
this.onConnectOptionsChange = undefined;
|
|
2161
2195
|
this.promptConnect = async function (options) {
|
|
@@ -2644,6 +2678,10 @@ class WalletRequestHandler {
|
|
|
2644
2678
|
}
|
|
2645
2679
|
}
|
|
2646
2680
|
signOut() {
|
|
2681
|
+
if (this.account) {
|
|
2682
|
+
this.notifyDisconnect();
|
|
2683
|
+
}
|
|
2684
|
+
|
|
2647
2685
|
// signed out state
|
|
2648
2686
|
this.setAccount(null);
|
|
2649
2687
|
}
|
|
@@ -2752,7 +2790,7 @@ class WalletRequestHandler {
|
|
|
2752
2790
|
setConnectOptions(options) {
|
|
2753
2791
|
var _this$onConnectOption;
|
|
2754
2792
|
this._connectOptions = options;
|
|
2755
|
-
(_this$onConnectOption = this.onConnectOptionsChange) == null
|
|
2793
|
+
(_this$onConnectOption = this.onConnectOptionsChange) == null || _this$onConnectOption.call(this, options);
|
|
2756
2794
|
}
|
|
2757
2795
|
async setDefaultChainId(chainId) {
|
|
2758
2796
|
var _this$prompter4;
|
|
@@ -2794,7 +2832,7 @@ class WalletRequestHandler {
|
|
|
2794
2832
|
if (network$1) {
|
|
2795
2833
|
var _session$networks;
|
|
2796
2834
|
// Delete the isDefaultChain property from the session network
|
|
2797
|
-
(_session$networks = session.networks) == null
|
|
2835
|
+
(_session$networks = session.networks) == null || _session$networks.forEach(n => delete n.isDefaultChain);
|
|
2798
2836
|
|
|
2799
2837
|
// Add the isDefaultChain property to the network with the given networkId
|
|
2800
2838
|
network$1.isDefaultChain = true;
|
|
@@ -2898,11 +2936,11 @@ class SequenceSigner {
|
|
|
2898
2936
|
return this.provider.utils;
|
|
2899
2937
|
}
|
|
2900
2938
|
constructor(client, provider) {
|
|
2939
|
+
this.client = client;
|
|
2940
|
+
this.provider = provider;
|
|
2901
2941
|
this.singleNetworkSigners = {};
|
|
2902
2942
|
this._isSigner = true;
|
|
2903
2943
|
this._isSequenceSigner = true;
|
|
2904
|
-
this.client = client;
|
|
2905
|
-
this.provider = provider;
|
|
2906
2944
|
}
|
|
2907
2945
|
async getAddress() {
|
|
2908
2946
|
return this.client.getAddress();
|
|
@@ -3060,8 +3098,8 @@ class SequenceSigner {
|
|
|
3060
3098
|
class SingleNetworkSequenceSigner extends SequenceSigner {
|
|
3061
3099
|
constructor(client, provider, chainId) {
|
|
3062
3100
|
super(client, provider.getProvider(chainId));
|
|
3063
|
-
this._isSingleNetworkSequenceSigner = true;
|
|
3064
3101
|
this.chainId = chainId;
|
|
3102
|
+
this._isSingleNetworkSequenceSigner = true;
|
|
3065
3103
|
}
|
|
3066
3104
|
_useChainId(chainId) {
|
|
3067
3105
|
const provided = this.provider.toChainId(chainId);
|
|
@@ -3169,11 +3207,13 @@ class SequenceProvider extends ethers.ethers.providers.BaseProvider {
|
|
|
3169
3207
|
super(client.getChainId());
|
|
3170
3208
|
|
|
3171
3209
|
// Emit events as defined by EIP-1193
|
|
3172
|
-
this.singleNetworkProviders = {};
|
|
3173
|
-
this._isSequenceProvider = true;
|
|
3174
3210
|
this.client = client;
|
|
3175
3211
|
this.providerFor = providerFor;
|
|
3176
3212
|
this.networks = networks;
|
|
3213
|
+
this.singleNetworkProviders = {};
|
|
3214
|
+
this._isSequenceProvider = true;
|
|
3215
|
+
this.utils = void 0;
|
|
3216
|
+
this.signer = void 0;
|
|
3177
3217
|
client.onConnect(details => {
|
|
3178
3218
|
this.emit('connect', details);
|
|
3179
3219
|
});
|
|
@@ -3484,8 +3524,8 @@ function normalizeChainId(chainId) {
|
|
|
3484
3524
|
class SingleNetworkSequenceProvider extends SequenceProvider {
|
|
3485
3525
|
constructor(client, providerFor, chainId) {
|
|
3486
3526
|
super(client, providerFor);
|
|
3487
|
-
this._isSingleNetworkSequenceProvider = true;
|
|
3488
3527
|
this.chainId = chainId;
|
|
3528
|
+
this._isSingleNetworkSequenceProvider = true;
|
|
3489
3529
|
}
|
|
3490
3530
|
_useChainId(chainId) {
|
|
3491
3531
|
const provided = this.toChainId(chainId);
|
|
@@ -3533,7 +3573,7 @@ class SingleNetworkSequenceProvider extends SequenceProvider {
|
|
|
3533
3573
|
|
|
3534
3574
|
var packageJson = {
|
|
3535
3575
|
name: "@0xsequence/provider",
|
|
3536
|
-
version: "1.
|
|
3576
|
+
version: "1.6.1",
|
|
3537
3577
|
description: "provider sub-package for Sequence",
|
|
3538
3578
|
repository: "https://github.com/0xsequence/sequence.js/tree/master/packages/provider",
|
|
3539
3579
|
source: "src/index.ts",
|
|
@@ -3544,7 +3584,7 @@ var packageJson = {
|
|
|
3544
3584
|
scripts: {
|
|
3545
3585
|
test: "pnpm test:concurrently 'pnpm test:run'",
|
|
3546
3586
|
"test:run": "pnpm test:file tests/**/*.spec.ts",
|
|
3547
|
-
"test:file": "NODE_OPTIONS='--
|
|
3587
|
+
"test:file": "NODE_OPTIONS='--import tsx' mocha --timeout 30000",
|
|
3548
3588
|
typecheck: "tsc --noEmit",
|
|
3549
3589
|
"test:concurrently": "concurrently -k --success first 'pnpm start:hardhat1' 'pnpm start:hardhat2'",
|
|
3550
3590
|
"start:hardhat1": "pnpm start:hardhat1:verbose > /dev/null 2>&1",
|
|
@@ -3626,9 +3666,9 @@ class SequenceClientSession {
|
|
|
3626
3666
|
SequenceClientSession.SESSION_LOCALSTORE_KEY = '@sequence.session';
|
|
3627
3667
|
class DefaultChainIdTracker {
|
|
3628
3668
|
constructor(store, startingChainId = 1) {
|
|
3629
|
-
this.callbacks = [];
|
|
3630
3669
|
this.store = store;
|
|
3631
3670
|
this.startingChainId = startingChainId;
|
|
3671
|
+
this.callbacks = [];
|
|
3632
3672
|
store.onItemChange(DefaultChainIdTracker.SESSION_CHAIN_ID_KEY, value => {
|
|
3633
3673
|
if (value) {
|
|
3634
3674
|
const chainId = parseInt(value);
|
|
@@ -3661,12 +3701,18 @@ DefaultChainIdTracker.SESSION_CHAIN_ID_KEY = '@sequence.session.defaultChainId';
|
|
|
3661
3701
|
* and it allows to perform all sequence specific (or write) operations related to the wallet.
|
|
3662
3702
|
*s
|
|
3663
3703
|
* It doesn't implement a full ethereum Provider, it doesn't include read-only methods.
|
|
3664
|
-
*/
|
|
3704
|
+
*/
|
|
3705
|
+
|
|
3706
|
+
// TODO: rename Client to transport.. or something.. like SequenceTransport ..
|
|
3665
3707
|
class SequenceClient {
|
|
3666
3708
|
constructor(transport, store, options, projectAccessKey) {
|
|
3667
3709
|
var _options$defaultEIP;
|
|
3668
|
-
this.callbacks = {};
|
|
3669
3710
|
this.projectAccessKey = projectAccessKey;
|
|
3711
|
+
this.session = void 0;
|
|
3712
|
+
this.defaultChainId = void 0;
|
|
3713
|
+
this.callbacks = {};
|
|
3714
|
+
this.transport = void 0;
|
|
3715
|
+
this.defaultEIP6492 = void 0;
|
|
3670
3716
|
if (isMuxTransportTemplate(transport)) {
|
|
3671
3717
|
this.transport = MuxMessageProvider.new(transport);
|
|
3672
3718
|
} else if (isProviderTransport(transport)) {
|
|
@@ -3683,12 +3729,12 @@ class SequenceClient {
|
|
|
3683
3729
|
if (accounts.length > 1) {
|
|
3684
3730
|
console.warn('SequenceClient: wallet-webapp returned more than one account');
|
|
3685
3731
|
}
|
|
3686
|
-
(_this$callbacks$accou = this.callbacks.accountsChanged) == null
|
|
3732
|
+
(_this$callbacks$accou = this.callbacks.accountsChanged) == null || _this$callbacks$accou.forEach(cb => cb(accounts));
|
|
3687
3733
|
});
|
|
3688
3734
|
this.transport.on('connect', response => {
|
|
3689
3735
|
var _this$callbacks$conne;
|
|
3690
3736
|
const chainIdHex = ethers.ethers.utils.hexValue(this.getChainId());
|
|
3691
|
-
(_this$callbacks$conne = this.callbacks.connect) == null
|
|
3737
|
+
(_this$callbacks$conne = this.callbacks.connect) == null || _this$callbacks$conne.forEach(cb => cb(_extends({}, response, {
|
|
3692
3738
|
// Ignore the full connect response
|
|
3693
3739
|
// use the chainId defined locally
|
|
3694
3740
|
chainId: chainIdHex
|
|
@@ -3696,27 +3742,27 @@ class SequenceClient {
|
|
|
3696
3742
|
});
|
|
3697
3743
|
this.transport.on('disconnect', (error, origin) => {
|
|
3698
3744
|
var _this$callbacks$disco;
|
|
3699
|
-
(_this$callbacks$disco = this.callbacks.disconnect) == null
|
|
3745
|
+
(_this$callbacks$disco = this.callbacks.disconnect) == null || _this$callbacks$disco.forEach(cb => cb(error, origin));
|
|
3700
3746
|
});
|
|
3701
3747
|
this.transport.on('networks', networks => {
|
|
3702
3748
|
var _this$callbacks$netwo;
|
|
3703
|
-
(_this$callbacks$netwo = this.callbacks.networks) == null
|
|
3749
|
+
(_this$callbacks$netwo = this.callbacks.networks) == null || _this$callbacks$netwo.forEach(cb => cb(networks));
|
|
3704
3750
|
});
|
|
3705
3751
|
this.transport.on('walletContext', context => {
|
|
3706
3752
|
var _this$callbacks$walle;
|
|
3707
|
-
(_this$callbacks$walle = this.callbacks.walletContext) == null
|
|
3753
|
+
(_this$callbacks$walle = this.callbacks.walletContext) == null || _this$callbacks$walle.forEach(cb => cb(context));
|
|
3708
3754
|
});
|
|
3709
3755
|
this.transport.on('open', info => {
|
|
3710
3756
|
var _this$callbacks$open;
|
|
3711
|
-
(_this$callbacks$open = this.callbacks.open) == null
|
|
3757
|
+
(_this$callbacks$open = this.callbacks.open) == null || _this$callbacks$open.forEach(cb => cb(info));
|
|
3712
3758
|
});
|
|
3713
3759
|
this.transport.on('close', () => {
|
|
3714
3760
|
var _this$callbacks$close;
|
|
3715
|
-
(_this$callbacks$close = this.callbacks.close) == null
|
|
3761
|
+
(_this$callbacks$close = this.callbacks.close) == null || _this$callbacks$close.forEach(cb => cb());
|
|
3716
3762
|
});
|
|
3717
3763
|
this.transport.on('chainChanged', (chainIdHex, origin) => {
|
|
3718
3764
|
var _this$callbacks$chain;
|
|
3719
|
-
(_this$callbacks$chain = this.callbacks.chainChanged) == null
|
|
3765
|
+
(_this$callbacks$chain = this.callbacks.chainChanged) == null || _this$callbacks$chain.forEach(cb => cb(chainIdHex, origin));
|
|
3720
3766
|
});
|
|
3721
3767
|
|
|
3722
3768
|
// We don't listen for the transport chainChanged event
|
|
@@ -3724,7 +3770,7 @@ class SequenceClient {
|
|
|
3724
3770
|
this.defaultChainId.onDefaultChainIdChanged(chainId => {
|
|
3725
3771
|
var _this$callbacks$chain2;
|
|
3726
3772
|
const chainIdHex = ethers.ethers.utils.hexValue(chainId);
|
|
3727
|
-
(_this$callbacks$chain2 = this.callbacks.chainChanged) == null
|
|
3773
|
+
(_this$callbacks$chain2 = this.callbacks.chainChanged) == null || _this$callbacks$chain2.forEach(cb => cb(chainIdHex));
|
|
3728
3774
|
});
|
|
3729
3775
|
}
|
|
3730
3776
|
|
|
@@ -28,6 +28,10 @@ function isProviderTransport(transport) {
|
|
|
28
28
|
// ProviderMessageCallback is used to respond to ProviderMessage requests. The error
|
|
29
29
|
// argument is for exceptions during the execution, and response is the response payload
|
|
30
30
|
// which may contain the result or an error payload from the wallet.
|
|
31
|
+
|
|
32
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
|
|
33
|
+
|
|
34
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
|
|
31
35
|
class WindowSessionParams extends URLSearchParams {
|
|
32
36
|
static new(init) {
|
|
33
37
|
return new URLSearchParams(init);
|
|
@@ -89,8 +93,17 @@ class BaseProviderTransport {
|
|
|
89
93
|
var _this = this;
|
|
90
94
|
this.pendingMessageRequests = [];
|
|
91
95
|
this.responseCallbacks = new Map();
|
|
96
|
+
this.state = void 0;
|
|
92
97
|
this.confirmationOnly = false;
|
|
93
98
|
this.events = new EventEmitter2();
|
|
99
|
+
this.openPayload = void 0;
|
|
100
|
+
this.connectPayload = void 0;
|
|
101
|
+
this.accountsChangedPayload = void 0;
|
|
102
|
+
this.networksPayload = void 0;
|
|
103
|
+
this.walletContextPayload = void 0;
|
|
104
|
+
this._sessionId = void 0;
|
|
105
|
+
this._init = void 0;
|
|
106
|
+
this._registered = void 0;
|
|
94
107
|
this.sendAsync = async function (request, callback, chainId) {
|
|
95
108
|
// here, we receive the message from the dapp provider call
|
|
96
109
|
|
|
@@ -116,7 +129,6 @@ class BaseProviderTransport {
|
|
|
116
129
|
if (!_this.isOpened()) {
|
|
117
130
|
await _this.waitUntilOpened(); // will throw on timeout
|
|
118
131
|
}
|
|
119
|
-
|
|
120
132
|
const response = await _this.sendMessageRequest({
|
|
121
133
|
idx: nextMessageIdx(),
|
|
122
134
|
type: EventType.MESSAGE,
|
|
@@ -321,7 +333,6 @@ class BaseProviderTransport {
|
|
|
321
333
|
}
|
|
322
334
|
}, 500); // TODO: be smarter about timer as we're processing the response callbacks..
|
|
323
335
|
}
|
|
324
|
-
|
|
325
336
|
if (!responseCallback) {
|
|
326
337
|
// NOTE: this would occur if 'idx' isn't set, which should never happen
|
|
327
338
|
// or when we register two handler, or duplicate messages with the same idx are sent,
|
|
@@ -702,11 +713,18 @@ async function resolveArrayProperties(object) {
|
|
|
702
713
|
|
|
703
714
|
const TRANSPORT_SESSION_LS_KEY = '@sequence.transportSession';
|
|
704
715
|
class BaseWalletTransport {
|
|
705
|
-
// appOrigin identifies the dapp's origin which opened the app. A transport
|
|
706
|
-
// will auto-detect and set this value if it can. This is determined
|
|
707
|
-
// as the parent app/window which opened the wallet.
|
|
708
716
|
constructor(walletRequestHandler) {
|
|
709
717
|
var _this = this;
|
|
718
|
+
this.walletRequestHandler = void 0;
|
|
719
|
+
this._sessionId = void 0;
|
|
720
|
+
this._registered = void 0;
|
|
721
|
+
this._init = void 0;
|
|
722
|
+
this._initNonce = void 0;
|
|
723
|
+
this._initCallback = void 0;
|
|
724
|
+
// appOrigin identifies the dapp's origin which opened the app. A transport
|
|
725
|
+
// will auto-detect and set this value if it can. This is determined
|
|
726
|
+
// as the parent app/window which opened the wallet.
|
|
727
|
+
this.appOrigin = void 0;
|
|
710
728
|
this.sendAsync = async function (request, callback, chainId) {
|
|
711
729
|
throw new Error('abstract method');
|
|
712
730
|
};
|
|
@@ -1126,6 +1144,8 @@ class BaseWalletTransport {
|
|
|
1126
1144
|
|
|
1127
1145
|
class ProxyMessageChannel {
|
|
1128
1146
|
constructor() {
|
|
1147
|
+
this.app = void 0;
|
|
1148
|
+
this.wallet = void 0;
|
|
1129
1149
|
const port1 = new ProxyMessageChannelPort();
|
|
1130
1150
|
const port2 = new ProxyMessageChannelPort();
|
|
1131
1151
|
port1.conn = port2;
|
|
@@ -1136,6 +1156,7 @@ class ProxyMessageChannel {
|
|
|
1136
1156
|
}
|
|
1137
1157
|
class ProxyMessageChannelPort {
|
|
1138
1158
|
constructor() {
|
|
1159
|
+
this.conn = void 0;
|
|
1139
1160
|
this.events = new EventEmitter2();
|
|
1140
1161
|
// handle messages which hit this port
|
|
1141
1162
|
this.handleMessage = message => {
|
|
@@ -1171,6 +1192,7 @@ class ProxyMessageChannelPort {
|
|
|
1171
1192
|
class ProxyMessageProvider extends BaseProviderTransport {
|
|
1172
1193
|
constructor(port) {
|
|
1173
1194
|
super();
|
|
1195
|
+
this.port = void 0;
|
|
1174
1196
|
this.register = () => {
|
|
1175
1197
|
this.port.handleMessage = message => {
|
|
1176
1198
|
this.handleMessage(message);
|
|
@@ -1242,6 +1264,7 @@ class ProxyMessageProvider extends BaseProviderTransport {
|
|
|
1242
1264
|
class ProxyMessageHandler extends BaseWalletTransport {
|
|
1243
1265
|
constructor(walletRequestHandler, port) {
|
|
1244
1266
|
super(walletRequestHandler);
|
|
1267
|
+
this.port = void 0;
|
|
1245
1268
|
this.port = port;
|
|
1246
1269
|
this._init = InitState.OK;
|
|
1247
1270
|
}
|
|
@@ -1308,6 +1331,7 @@ let registeredUnrealMessageProvider;
|
|
|
1308
1331
|
class UnrealMessageProvider extends BaseProviderTransport {
|
|
1309
1332
|
constructor(walletAppURL) {
|
|
1310
1333
|
super();
|
|
1334
|
+
this.walletURL = void 0;
|
|
1311
1335
|
this.register = () => {
|
|
1312
1336
|
var _window$ue;
|
|
1313
1337
|
overrideLogs('dapp');
|
|
@@ -1326,7 +1350,7 @@ class UnrealMessageProvider extends BaseProviderTransport {
|
|
|
1326
1350
|
console.log('registering transport!');
|
|
1327
1351
|
};
|
|
1328
1352
|
this.unregister = () => {
|
|
1329
|
-
var _window$ue2
|
|
1353
|
+
var _window$ue2;
|
|
1330
1354
|
this._registered = false;
|
|
1331
1355
|
this.closeWallet();
|
|
1332
1356
|
|
|
@@ -1334,7 +1358,7 @@ class UnrealMessageProvider extends BaseProviderTransport {
|
|
|
1334
1358
|
if (registeredUnrealMessageProvider === this) {
|
|
1335
1359
|
registeredUnrealMessageProvider = undefined;
|
|
1336
1360
|
}
|
|
1337
|
-
if (((_window$ue2 = window.ue) == null
|
|
1361
|
+
if (((_window$ue2 = window.ue) == null || (_window$ue2 = _window$ue2.sequencewallettransport) == null ? void 0 : _window$ue2.onmessagefromwallet) === this.onUnrealCallback) {
|
|
1338
1362
|
delete window.ue.sequencewallettransport.onmessagefromwallet;
|
|
1339
1363
|
}
|
|
1340
1364
|
|
|
@@ -1387,10 +1411,10 @@ class UnrealMessageProvider extends BaseProviderTransport {
|
|
|
1387
1411
|
}
|
|
1388
1412
|
// all lowercase is an annoying limitation of Unreal CEF BindUObject
|
|
1389
1413
|
sendMessage(message) {
|
|
1390
|
-
var _window$ue3
|
|
1414
|
+
var _window$ue3;
|
|
1391
1415
|
const postedMessage = typeof message !== 'string' ? JSON.stringify(message) : message;
|
|
1392
1416
|
console.log('Sending message to wallet:', postedMessage);
|
|
1393
|
-
(_window$ue3 = window.ue) == null
|
|
1417
|
+
(_window$ue3 = window.ue) == null || (_window$ue3 = _window$ue3.sequencewallettransport) == null || _window$ue3.sendmessagetowallet(postedMessage);
|
|
1394
1418
|
}
|
|
1395
1419
|
}
|
|
1396
1420
|
|
|
@@ -1473,15 +1497,15 @@ class UnrealMessageHandler extends BaseWalletTransport {
|
|
|
1473
1497
|
});
|
|
1474
1498
|
}
|
|
1475
1499
|
unregister() {
|
|
1476
|
-
var _window$ue2
|
|
1477
|
-
if (((_window$ue2 = window.ue) == null
|
|
1500
|
+
var _window$ue2;
|
|
1501
|
+
if (((_window$ue2 = window.ue) == null || (_window$ue2 = _window$ue2.sequencewallettransport) == null ? void 0 : _window$ue2.onmessagefromsequencejs) === this.onMessageFromUnreal) {
|
|
1478
1502
|
delete window.ue.sequencewallettransport.onmessagefromsequencejs;
|
|
1479
1503
|
}
|
|
1480
1504
|
this._registered = false;
|
|
1481
1505
|
}
|
|
1482
1506
|
// sendMessage sends message to the dapp window
|
|
1483
1507
|
sendMessage(message) {
|
|
1484
|
-
var _window$ue3
|
|
1508
|
+
var _window$ue3;
|
|
1485
1509
|
if (message.type !== EventType.INIT && this._init !== InitState.OK) {
|
|
1486
1510
|
logger.error('impossible state, should not be calling postMessage until inited');
|
|
1487
1511
|
return;
|
|
@@ -1490,7 +1514,7 @@ class UnrealMessageHandler extends BaseWalletTransport {
|
|
|
1490
1514
|
const payload = JSON.stringify(message);
|
|
1491
1515
|
|
|
1492
1516
|
// post-message to app.
|
|
1493
|
-
(_window$ue3 = window.ue) == null
|
|
1517
|
+
(_window$ue3 = window.ue) == null || (_window$ue3 = _window$ue3.sequencewallettransport) == null || _window$ue3.sendmessagetosequencejs(payload);
|
|
1494
1518
|
}
|
|
1495
1519
|
}
|
|
1496
1520
|
|
|
@@ -1499,6 +1523,7 @@ class ExtensionMessageHandler extends BaseWalletTransport {
|
|
|
1499
1523
|
constructor(walletRequestHandler, runtime) {
|
|
1500
1524
|
super(walletRequestHandler);
|
|
1501
1525
|
this.runtime = runtime;
|
|
1526
|
+
this.port = void 0;
|
|
1502
1527
|
this._init = InitState.OK;
|
|
1503
1528
|
}
|
|
1504
1529
|
register() {
|
|
@@ -1548,6 +1573,7 @@ class BaseInjectedTransport extends EventEmitter2 {
|
|
|
1548
1573
|
var _this;
|
|
1549
1574
|
super();
|
|
1550
1575
|
_this = this;
|
|
1576
|
+
this.stream = stream;
|
|
1551
1577
|
this.responseCallbacks = new Map();
|
|
1552
1578
|
this._messageIdx = 0;
|
|
1553
1579
|
this.nextMessageIdx = () => ++this._messageIdx;
|
|
@@ -1608,7 +1634,6 @@ class BaseInjectedTransport extends EventEmitter2 {
|
|
|
1608
1634
|
_this.sendMessage(message);
|
|
1609
1635
|
});
|
|
1610
1636
|
};
|
|
1611
|
-
this.stream = stream;
|
|
1612
1637
|
this.stream.on('data', this.handleMessage);
|
|
1613
1638
|
}
|
|
1614
1639
|
sendMessage(message) {
|
|
@@ -1624,6 +1649,8 @@ let registeredWindowMessageProvider;
|
|
|
1624
1649
|
class WindowMessageProvider extends BaseProviderTransport {
|
|
1625
1650
|
constructor(walletAppURL) {
|
|
1626
1651
|
super();
|
|
1652
|
+
this.walletURL = void 0;
|
|
1653
|
+
this.walletWindow = void 0;
|
|
1627
1654
|
this.register = () => {
|
|
1628
1655
|
if (registeredWindowMessageProvider) {
|
|
1629
1656
|
// overriding the registered message provider
|
|
@@ -1776,7 +1803,7 @@ class WindowMessageProvider extends BaseProviderTransport {
|
|
|
1776
1803
|
closeWallet() {
|
|
1777
1804
|
var _this$walletWindow;
|
|
1778
1805
|
this.close();
|
|
1779
|
-
(_this$walletWindow = this.walletWindow) == null
|
|
1806
|
+
(_this$walletWindow = this.walletWindow) == null || _this$walletWindow.close();
|
|
1780
1807
|
}
|
|
1781
1808
|
sendMessage(message) {
|
|
1782
1809
|
if (!this.walletWindow) {
|
|
@@ -1793,6 +1820,7 @@ class WindowMessageHandler extends BaseWalletTransport {
|
|
|
1793
1820
|
var _this;
|
|
1794
1821
|
super(walletRequestHandler);
|
|
1795
1822
|
_this = this;
|
|
1823
|
+
this.parentWindow = void 0;
|
|
1796
1824
|
this._isPopup = false;
|
|
1797
1825
|
// onmessage is called when (the wallet) receives request messages from the dapp
|
|
1798
1826
|
// over the window post-messaging transport
|
|
@@ -1941,6 +1969,8 @@ function isMuxTransportTemplate(obj) {
|
|
|
1941
1969
|
class MuxMessageProvider {
|
|
1942
1970
|
constructor(...messageProviders) {
|
|
1943
1971
|
var _this = this;
|
|
1972
|
+
this.messageProviders = void 0;
|
|
1973
|
+
this.provider = void 0;
|
|
1944
1974
|
this.register = () => {
|
|
1945
1975
|
if (this.messageProviders.length === 1) {
|
|
1946
1976
|
this.provider = this.messageProviders[0];
|
|
@@ -2029,7 +2059,6 @@ class MuxMessageProvider {
|
|
|
2029
2059
|
// send all requests to the WindowMessageProvider anyways. By allowing it, if browser restarts, it will break
|
|
2030
2060
|
// the entire extension because messageProvider.provider will be undefined. So this is a hack to fix it.
|
|
2031
2061
|
}
|
|
2032
|
-
|
|
2033
2062
|
if ((_template$unrealTrans = template.unrealTransport) != null && _template$unrealTrans.enabled && template.windowTransport && template.walletAppURL) {
|
|
2034
2063
|
const unrealMessageProvider = new UnrealMessageProvider(template.walletAppURL);
|
|
2035
2064
|
muxMessageProvider.add(unrealMessageProvider);
|
|
@@ -2151,7 +2180,12 @@ class WalletRequestHandler {
|
|
|
2151
2180
|
// signer interface of the wallet. A null value means there is no signer (ie. user not signed in). An undefined
|
|
2152
2181
|
// value means the signer state is unknown, usually meaning the wallet app is booting up and initializing. Of course
|
|
2153
2182
|
// a Signer value is the actually interface to a signed-in account
|
|
2183
|
+
this.account = void 0;
|
|
2154
2184
|
this.signerReadyCallbacks = [];
|
|
2185
|
+
this.prompter = void 0;
|
|
2186
|
+
this.networks = void 0;
|
|
2187
|
+
this._openIntent = void 0;
|
|
2188
|
+
this._connectOptions = void 0;
|
|
2155
2189
|
this.events = new EventEmitter2();
|
|
2156
2190
|
this.onConnectOptionsChange = undefined;
|
|
2157
2191
|
this.promptConnect = async function (options) {
|
|
@@ -2640,6 +2674,10 @@ class WalletRequestHandler {
|
|
|
2640
2674
|
}
|
|
2641
2675
|
}
|
|
2642
2676
|
signOut() {
|
|
2677
|
+
if (this.account) {
|
|
2678
|
+
this.notifyDisconnect();
|
|
2679
|
+
}
|
|
2680
|
+
|
|
2643
2681
|
// signed out state
|
|
2644
2682
|
this.setAccount(null);
|
|
2645
2683
|
}
|
|
@@ -2748,7 +2786,7 @@ class WalletRequestHandler {
|
|
|
2748
2786
|
setConnectOptions(options) {
|
|
2749
2787
|
var _this$onConnectOption;
|
|
2750
2788
|
this._connectOptions = options;
|
|
2751
|
-
(_this$onConnectOption = this.onConnectOptionsChange) == null
|
|
2789
|
+
(_this$onConnectOption = this.onConnectOptionsChange) == null || _this$onConnectOption.call(this, options);
|
|
2752
2790
|
}
|
|
2753
2791
|
async setDefaultChainId(chainId) {
|
|
2754
2792
|
var _this$prompter4;
|
|
@@ -2790,7 +2828,7 @@ class WalletRequestHandler {
|
|
|
2790
2828
|
if (network) {
|
|
2791
2829
|
var _session$networks;
|
|
2792
2830
|
// Delete the isDefaultChain property from the session network
|
|
2793
|
-
(_session$networks = session.networks) == null
|
|
2831
|
+
(_session$networks = session.networks) == null || _session$networks.forEach(n => delete n.isDefaultChain);
|
|
2794
2832
|
|
|
2795
2833
|
// Add the isDefaultChain property to the network with the given networkId
|
|
2796
2834
|
network.isDefaultChain = true;
|
|
@@ -2894,11 +2932,11 @@ class SequenceSigner {
|
|
|
2894
2932
|
return this.provider.utils;
|
|
2895
2933
|
}
|
|
2896
2934
|
constructor(client, provider) {
|
|
2935
|
+
this.client = client;
|
|
2936
|
+
this.provider = provider;
|
|
2897
2937
|
this.singleNetworkSigners = {};
|
|
2898
2938
|
this._isSigner = true;
|
|
2899
2939
|
this._isSequenceSigner = true;
|
|
2900
|
-
this.client = client;
|
|
2901
|
-
this.provider = provider;
|
|
2902
2940
|
}
|
|
2903
2941
|
async getAddress() {
|
|
2904
2942
|
return this.client.getAddress();
|
|
@@ -3056,8 +3094,8 @@ class SequenceSigner {
|
|
|
3056
3094
|
class SingleNetworkSequenceSigner extends SequenceSigner {
|
|
3057
3095
|
constructor(client, provider, chainId) {
|
|
3058
3096
|
super(client, provider.getProvider(chainId));
|
|
3059
|
-
this._isSingleNetworkSequenceSigner = true;
|
|
3060
3097
|
this.chainId = chainId;
|
|
3098
|
+
this._isSingleNetworkSequenceSigner = true;
|
|
3061
3099
|
}
|
|
3062
3100
|
_useChainId(chainId) {
|
|
3063
3101
|
const provided = this.provider.toChainId(chainId);
|
|
@@ -3165,11 +3203,13 @@ class SequenceProvider extends ethers.providers.BaseProvider {
|
|
|
3165
3203
|
super(client.getChainId());
|
|
3166
3204
|
|
|
3167
3205
|
// Emit events as defined by EIP-1193
|
|
3168
|
-
this.singleNetworkProviders = {};
|
|
3169
|
-
this._isSequenceProvider = true;
|
|
3170
3206
|
this.client = client;
|
|
3171
3207
|
this.providerFor = providerFor;
|
|
3172
3208
|
this.networks = networks;
|
|
3209
|
+
this.singleNetworkProviders = {};
|
|
3210
|
+
this._isSequenceProvider = true;
|
|
3211
|
+
this.utils = void 0;
|
|
3212
|
+
this.signer = void 0;
|
|
3173
3213
|
client.onConnect(details => {
|
|
3174
3214
|
this.emit('connect', details);
|
|
3175
3215
|
});
|
|
@@ -3480,8 +3520,8 @@ function normalizeChainId(chainId) {
|
|
|
3480
3520
|
class SingleNetworkSequenceProvider extends SequenceProvider {
|
|
3481
3521
|
constructor(client, providerFor, chainId) {
|
|
3482
3522
|
super(client, providerFor);
|
|
3483
|
-
this._isSingleNetworkSequenceProvider = true;
|
|
3484
3523
|
this.chainId = chainId;
|
|
3524
|
+
this._isSingleNetworkSequenceProvider = true;
|
|
3485
3525
|
}
|
|
3486
3526
|
_useChainId(chainId) {
|
|
3487
3527
|
const provided = this.toChainId(chainId);
|
|
@@ -3529,7 +3569,7 @@ class SingleNetworkSequenceProvider extends SequenceProvider {
|
|
|
3529
3569
|
|
|
3530
3570
|
var packageJson = {
|
|
3531
3571
|
name: "@0xsequence/provider",
|
|
3532
|
-
version: "1.
|
|
3572
|
+
version: "1.6.1",
|
|
3533
3573
|
description: "provider sub-package for Sequence",
|
|
3534
3574
|
repository: "https://github.com/0xsequence/sequence.js/tree/master/packages/provider",
|
|
3535
3575
|
source: "src/index.ts",
|
|
@@ -3540,7 +3580,7 @@ var packageJson = {
|
|
|
3540
3580
|
scripts: {
|
|
3541
3581
|
test: "pnpm test:concurrently 'pnpm test:run'",
|
|
3542
3582
|
"test:run": "pnpm test:file tests/**/*.spec.ts",
|
|
3543
|
-
"test:file": "NODE_OPTIONS='--
|
|
3583
|
+
"test:file": "NODE_OPTIONS='--import tsx' mocha --timeout 30000",
|
|
3544
3584
|
typecheck: "tsc --noEmit",
|
|
3545
3585
|
"test:concurrently": "concurrently -k --success first 'pnpm start:hardhat1' 'pnpm start:hardhat2'",
|
|
3546
3586
|
"start:hardhat1": "pnpm start:hardhat1:verbose > /dev/null 2>&1",
|
|
@@ -3622,9 +3662,9 @@ class SequenceClientSession {
|
|
|
3622
3662
|
SequenceClientSession.SESSION_LOCALSTORE_KEY = '@sequence.session';
|
|
3623
3663
|
class DefaultChainIdTracker {
|
|
3624
3664
|
constructor(store, startingChainId = 1) {
|
|
3625
|
-
this.callbacks = [];
|
|
3626
3665
|
this.store = store;
|
|
3627
3666
|
this.startingChainId = startingChainId;
|
|
3667
|
+
this.callbacks = [];
|
|
3628
3668
|
store.onItemChange(DefaultChainIdTracker.SESSION_CHAIN_ID_KEY, value => {
|
|
3629
3669
|
if (value) {
|
|
3630
3670
|
const chainId = parseInt(value);
|
|
@@ -3657,12 +3697,18 @@ DefaultChainIdTracker.SESSION_CHAIN_ID_KEY = '@sequence.session.defaultChainId';
|
|
|
3657
3697
|
* and it allows to perform all sequence specific (or write) operations related to the wallet.
|
|
3658
3698
|
*s
|
|
3659
3699
|
* It doesn't implement a full ethereum Provider, it doesn't include read-only methods.
|
|
3660
|
-
*/
|
|
3700
|
+
*/
|
|
3701
|
+
|
|
3702
|
+
// TODO: rename Client to transport.. or something.. like SequenceTransport ..
|
|
3661
3703
|
class SequenceClient {
|
|
3662
3704
|
constructor(transport, store, options, projectAccessKey) {
|
|
3663
3705
|
var _options$defaultEIP;
|
|
3664
|
-
this.callbacks = {};
|
|
3665
3706
|
this.projectAccessKey = projectAccessKey;
|
|
3707
|
+
this.session = void 0;
|
|
3708
|
+
this.defaultChainId = void 0;
|
|
3709
|
+
this.callbacks = {};
|
|
3710
|
+
this.transport = void 0;
|
|
3711
|
+
this.defaultEIP6492 = void 0;
|
|
3666
3712
|
if (isMuxTransportTemplate(transport)) {
|
|
3667
3713
|
this.transport = MuxMessageProvider.new(transport);
|
|
3668
3714
|
} else if (isProviderTransport(transport)) {
|
|
@@ -3679,12 +3725,12 @@ class SequenceClient {
|
|
|
3679
3725
|
if (accounts.length > 1) {
|
|
3680
3726
|
console.warn('SequenceClient: wallet-webapp returned more than one account');
|
|
3681
3727
|
}
|
|
3682
|
-
(_this$callbacks$accou = this.callbacks.accountsChanged) == null
|
|
3728
|
+
(_this$callbacks$accou = this.callbacks.accountsChanged) == null || _this$callbacks$accou.forEach(cb => cb(accounts));
|
|
3683
3729
|
});
|
|
3684
3730
|
this.transport.on('connect', response => {
|
|
3685
3731
|
var _this$callbacks$conne;
|
|
3686
3732
|
const chainIdHex = ethers.utils.hexValue(this.getChainId());
|
|
3687
|
-
(_this$callbacks$conne = this.callbacks.connect) == null
|
|
3733
|
+
(_this$callbacks$conne = this.callbacks.connect) == null || _this$callbacks$conne.forEach(cb => cb(_extends({}, response, {
|
|
3688
3734
|
// Ignore the full connect response
|
|
3689
3735
|
// use the chainId defined locally
|
|
3690
3736
|
chainId: chainIdHex
|
|
@@ -3692,27 +3738,27 @@ class SequenceClient {
|
|
|
3692
3738
|
});
|
|
3693
3739
|
this.transport.on('disconnect', (error, origin) => {
|
|
3694
3740
|
var _this$callbacks$disco;
|
|
3695
|
-
(_this$callbacks$disco = this.callbacks.disconnect) == null
|
|
3741
|
+
(_this$callbacks$disco = this.callbacks.disconnect) == null || _this$callbacks$disco.forEach(cb => cb(error, origin));
|
|
3696
3742
|
});
|
|
3697
3743
|
this.transport.on('networks', networks => {
|
|
3698
3744
|
var _this$callbacks$netwo;
|
|
3699
|
-
(_this$callbacks$netwo = this.callbacks.networks) == null
|
|
3745
|
+
(_this$callbacks$netwo = this.callbacks.networks) == null || _this$callbacks$netwo.forEach(cb => cb(networks));
|
|
3700
3746
|
});
|
|
3701
3747
|
this.transport.on('walletContext', context => {
|
|
3702
3748
|
var _this$callbacks$walle;
|
|
3703
|
-
(_this$callbacks$walle = this.callbacks.walletContext) == null
|
|
3749
|
+
(_this$callbacks$walle = this.callbacks.walletContext) == null || _this$callbacks$walle.forEach(cb => cb(context));
|
|
3704
3750
|
});
|
|
3705
3751
|
this.transport.on('open', info => {
|
|
3706
3752
|
var _this$callbacks$open;
|
|
3707
|
-
(_this$callbacks$open = this.callbacks.open) == null
|
|
3753
|
+
(_this$callbacks$open = this.callbacks.open) == null || _this$callbacks$open.forEach(cb => cb(info));
|
|
3708
3754
|
});
|
|
3709
3755
|
this.transport.on('close', () => {
|
|
3710
3756
|
var _this$callbacks$close;
|
|
3711
|
-
(_this$callbacks$close = this.callbacks.close) == null
|
|
3757
|
+
(_this$callbacks$close = this.callbacks.close) == null || _this$callbacks$close.forEach(cb => cb());
|
|
3712
3758
|
});
|
|
3713
3759
|
this.transport.on('chainChanged', (chainIdHex, origin) => {
|
|
3714
3760
|
var _this$callbacks$chain;
|
|
3715
|
-
(_this$callbacks$chain = this.callbacks.chainChanged) == null
|
|
3761
|
+
(_this$callbacks$chain = this.callbacks.chainChanged) == null || _this$callbacks$chain.forEach(cb => cb(chainIdHex, origin));
|
|
3716
3762
|
});
|
|
3717
3763
|
|
|
3718
3764
|
// We don't listen for the transport chainChanged event
|
|
@@ -3720,7 +3766,7 @@ class SequenceClient {
|
|
|
3720
3766
|
this.defaultChainId.onDefaultChainIdChanged(chainId => {
|
|
3721
3767
|
var _this$callbacks$chain2;
|
|
3722
3768
|
const chainIdHex = ethers.utils.hexValue(chainId);
|
|
3723
|
-
(_this$callbacks$chain2 = this.callbacks.chainChanged) == null
|
|
3769
|
+
(_this$callbacks$chain2 = this.callbacks.chainChanged) == null || _this$callbacks$chain2.forEach(cb => cb(chainIdHex));
|
|
3724
3770
|
});
|
|
3725
3771
|
}
|
|
3726
3772
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0xsequence/provider",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.1",
|
|
4
4
|
"description": "provider sub-package for Sequence",
|
|
5
5
|
"repository": "https://github.com/0xsequence/sequence.js/tree/master/packages/provider",
|
|
6
6
|
"source": "src/index.ts",
|
|
@@ -11,15 +11,15 @@
|
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"eventemitter2": "^6.4.5",
|
|
13
13
|
"webextension-polyfill": "^0.10.0",
|
|
14
|
-
"@0xsequence/abi": "1.
|
|
15
|
-
"@0xsequence/account": "1.
|
|
16
|
-
"@0xsequence/auth": "1.
|
|
17
|
-
"@0xsequence/core": "1.
|
|
18
|
-
"@0xsequence/migration": "1.
|
|
19
|
-
"@0xsequence/network": "1.
|
|
20
|
-
"@0xsequence/relayer": "1.
|
|
21
|
-
"@0xsequence/utils": "1.
|
|
22
|
-
"@0xsequence/wallet": "1.
|
|
14
|
+
"@0xsequence/abi": "1.6.1",
|
|
15
|
+
"@0xsequence/account": "1.6.1",
|
|
16
|
+
"@0xsequence/auth": "1.6.1",
|
|
17
|
+
"@0xsequence/core": "1.6.1",
|
|
18
|
+
"@0xsequence/migration": "1.6.1",
|
|
19
|
+
"@0xsequence/network": "1.6.1",
|
|
20
|
+
"@0xsequence/relayer": "1.6.1",
|
|
21
|
+
"@0xsequence/utils": "1.6.1",
|
|
22
|
+
"@0xsequence/wallet": "1.6.1"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"ethers": ">=5.5 < 6"
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"scripts": {
|
|
37
37
|
"test": "pnpm test:concurrently 'pnpm test:run'",
|
|
38
38
|
"test:run": "pnpm test:file tests/**/*.spec.ts",
|
|
39
|
-
"test:file": "NODE_OPTIONS='--
|
|
39
|
+
"test:file": "NODE_OPTIONS='--import tsx' mocha --timeout 30000",
|
|
40
40
|
"typecheck": "tsc --noEmit",
|
|
41
41
|
"test:concurrently": "concurrently -k --success first 'pnpm start:hardhat1' 'pnpm start:hardhat2'",
|
|
42
42
|
"start:hardhat1": "pnpm start:hardhat1:verbose > /dev/null 2>&1",
|
package/src/types.ts
CHANGED
|
@@ -90,11 +90,13 @@ export interface ProviderMessageTransport {
|
|
|
90
90
|
|
|
91
91
|
export type WindowSessionParam = 'sid' | 'net' | 'intent'
|
|
92
92
|
|
|
93
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
|
|
93
94
|
export interface WindowSessionParams extends URLSearchParams {
|
|
94
95
|
get(name: WindowSessionParam): string | null
|
|
95
96
|
set(name: WindowSessionParam, value: string): void
|
|
96
97
|
}
|
|
97
98
|
|
|
99
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
|
|
98
100
|
export class WindowSessionParams extends URLSearchParams {
|
|
99
101
|
static new(init?: Record<WindowSessionParam, string> | string) {
|
|
100
102
|
return new URLSearchParams(init) as WindowSessionParams
|