@0xsequence/provider 0.0.0-20230726193528 → 0.0.0-20230727132905
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 +63 -24
- package/dist/0xsequence-provider.cjs.prod.js +63 -24
- package/dist/0xsequence-provider.esm.js +63 -24
- package/dist/declarations/src/client.d.ts +10 -17
- package/package.json +10 -10
- package/src/client.ts +49 -32
- package/src/provider.ts +23 -2
|
@@ -3101,20 +3101,36 @@ class WalletUtils {
|
|
|
3101
3101
|
|
|
3102
3102
|
class SequenceProvider extends ethers.ethers.providers.BaseProvider {
|
|
3103
3103
|
constructor(client, providerFor, networks = network.allNetworks) {
|
|
3104
|
-
var _this;
|
|
3105
3104
|
// We support a lot of networks
|
|
3106
3105
|
// but we start with the default one
|
|
3107
3106
|
super(client.getChainId());
|
|
3108
|
-
|
|
3107
|
+
|
|
3108
|
+
// Emit events as defined by EIP-1193
|
|
3109
3109
|
this.singleNetworkProviders = {};
|
|
3110
3110
|
this._isSequenceProvider = true;
|
|
3111
3111
|
this.client = client;
|
|
3112
3112
|
this.providerFor = providerFor;
|
|
3113
3113
|
this.networks = networks;
|
|
3114
|
-
client.
|
|
3115
|
-
|
|
3116
|
-
|
|
3114
|
+
client.onConnect(details => {
|
|
3115
|
+
this.emit('connect', details);
|
|
3116
|
+
});
|
|
3117
|
+
client.onDisconnect(error => {
|
|
3118
|
+
this.emit('disconnect', error);
|
|
3117
3119
|
});
|
|
3120
|
+
client.onDefaultChainIdChanged(chainId => {
|
|
3121
|
+
this.emit('chainChanged', chainId);
|
|
3122
|
+
});
|
|
3123
|
+
client.onAccountsChanged(accounts => {
|
|
3124
|
+
this.emit('accountsChanged', accounts);
|
|
3125
|
+
});
|
|
3126
|
+
|
|
3127
|
+
// NOTICE: We don't emit 'open' and 'close' events
|
|
3128
|
+
// because these are handled by the library, and they
|
|
3129
|
+
// are not part of EIP-1193
|
|
3130
|
+
|
|
3131
|
+
// devs can still access them using
|
|
3132
|
+
// client.onOpen()
|
|
3133
|
+
// client.onClose()
|
|
3118
3134
|
|
|
3119
3135
|
// Create a Sequence signer too
|
|
3120
3136
|
this.signer = new SequenceSigner(this.client, this);
|
|
@@ -3549,31 +3565,48 @@ class SequenceClient {
|
|
|
3549
3565
|
this.session = new SequenceClientSession(store);
|
|
3550
3566
|
this.defaultChainId = new DefaultChainIdTracker(store, defaultChainId);
|
|
3551
3567
|
this.transport.on('accountsChanged', accounts => {
|
|
3552
|
-
var _this$callbacks$
|
|
3568
|
+
var _this$callbacks$accou;
|
|
3553
3569
|
if (accounts.length > 1) {
|
|
3554
3570
|
console.warn('SequenceClient: wallet-webapp returned more than one account');
|
|
3555
3571
|
}
|
|
3556
|
-
(_this$callbacks$
|
|
3572
|
+
(_this$callbacks$accou = this.callbacks.accountsChanged) == null ? void 0 : _this$callbacks$accou.forEach(cb => cb(accounts));
|
|
3573
|
+
});
|
|
3574
|
+
this.transport.on('connect', response => {
|
|
3575
|
+
var _this$callbacks$conne;
|
|
3576
|
+
const chainIdHex = ethers.ethers.BigNumber.from(this.getChainId()).toHexString();
|
|
3577
|
+
(_this$callbacks$conne = this.callbacks.connect) == null ? void 0 : _this$callbacks$conne.forEach(cb => cb(_extends({}, response, {
|
|
3578
|
+
// Ignore the full connect response
|
|
3579
|
+
// use the chainId defined locally
|
|
3580
|
+
chainId: chainIdHex
|
|
3581
|
+
})));
|
|
3582
|
+
});
|
|
3583
|
+
this.transport.on('disconnect', error => {
|
|
3584
|
+
var _this$callbacks$disco;
|
|
3585
|
+
(_this$callbacks$disco = this.callbacks.disconnect) == null ? void 0 : _this$callbacks$disco.forEach(cb => cb(error));
|
|
3557
3586
|
});
|
|
3558
3587
|
this.transport.on('networks', networks => {
|
|
3559
|
-
var _this$callbacks$
|
|
3560
|
-
(_this$callbacks$
|
|
3588
|
+
var _this$callbacks$netwo;
|
|
3589
|
+
(_this$callbacks$netwo = this.callbacks.networks) == null ? void 0 : _this$callbacks$netwo.forEach(cb => cb(networks));
|
|
3561
3590
|
});
|
|
3562
3591
|
this.transport.on('walletContext', context => {
|
|
3563
|
-
var _this$callbacks$
|
|
3564
|
-
(_this$callbacks$
|
|
3592
|
+
var _this$callbacks$walle;
|
|
3593
|
+
(_this$callbacks$walle = this.callbacks.walletContext) == null ? void 0 : _this$callbacks$walle.forEach(cb => cb(context));
|
|
3565
3594
|
});
|
|
3566
|
-
this.transport.on('open',
|
|
3567
|
-
var _this$callbacks$
|
|
3568
|
-
(_this$callbacks$
|
|
3595
|
+
this.transport.on('open', info => {
|
|
3596
|
+
var _this$callbacks$open;
|
|
3597
|
+
(_this$callbacks$open = this.callbacks.open) == null ? void 0 : _this$callbacks$open.forEach(cb => cb(info));
|
|
3569
3598
|
});
|
|
3570
3599
|
this.transport.on('close', () => {
|
|
3571
|
-
var _this$callbacks$
|
|
3572
|
-
(_this$callbacks$
|
|
3600
|
+
var _this$callbacks$close;
|
|
3601
|
+
(_this$callbacks$close = this.callbacks.close) == null ? void 0 : _this$callbacks$close.forEach(cb => cb());
|
|
3573
3602
|
});
|
|
3603
|
+
|
|
3604
|
+
// We don't listen for the transport chainChanged event
|
|
3605
|
+
// instead we handle it locally, so we listen for changes in the store
|
|
3574
3606
|
this.defaultChainId.onDefaultChainIdChanged(chainId => {
|
|
3575
|
-
var _this$callbacks$
|
|
3576
|
-
|
|
3607
|
+
var _this$callbacks$chain;
|
|
3608
|
+
const chainIdHex = ethers.ethers.BigNumber.from(chainId).toHexString();
|
|
3609
|
+
(_this$callbacks$chain = this.callbacks.chainChanged) == null ? void 0 : _this$callbacks$chain.forEach(cb => cb(chainIdHex));
|
|
3577
3610
|
});
|
|
3578
3611
|
}
|
|
3579
3612
|
|
|
@@ -3592,24 +3625,30 @@ class SequenceClient {
|
|
|
3592
3625
|
// Individual callbacks lead to more idiomatic code
|
|
3593
3626
|
|
|
3594
3627
|
onOpen(callback) {
|
|
3595
|
-
return this.registerCallback('
|
|
3628
|
+
return this.registerCallback('open', callback);
|
|
3596
3629
|
}
|
|
3597
3630
|
onClose(callback) {
|
|
3598
|
-
return this.registerCallback('
|
|
3631
|
+
return this.registerCallback('close', callback);
|
|
3632
|
+
}
|
|
3633
|
+
onConnect(callback) {
|
|
3634
|
+
return this.registerCallback('connect', callback);
|
|
3635
|
+
}
|
|
3636
|
+
onDisconnect(callback) {
|
|
3637
|
+
return this.registerCallback('disconnect', callback);
|
|
3599
3638
|
}
|
|
3600
3639
|
onNetworks(callback) {
|
|
3601
|
-
return this.registerCallback('
|
|
3640
|
+
return this.registerCallback('networks', callback);
|
|
3602
3641
|
}
|
|
3603
3642
|
onAccountsChanged(callback) {
|
|
3604
|
-
return this.registerCallback('
|
|
3643
|
+
return this.registerCallback('accountsChanged', callback);
|
|
3605
3644
|
}
|
|
3606
3645
|
|
|
3607
3646
|
// @deprecated
|
|
3608
3647
|
onWalletContext(callback) {
|
|
3609
|
-
return this.registerCallback('
|
|
3648
|
+
return this.registerCallback('walletContext', callback);
|
|
3610
3649
|
}
|
|
3611
3650
|
onDefaultChainIdChanged(callback) {
|
|
3612
|
-
return this.registerCallback('
|
|
3651
|
+
return this.registerCallback('chainChanged', callback);
|
|
3613
3652
|
}
|
|
3614
3653
|
getChainId() {
|
|
3615
3654
|
return this.defaultChainId.getDefaultChainId();
|
|
@@ -3101,20 +3101,36 @@ class WalletUtils {
|
|
|
3101
3101
|
|
|
3102
3102
|
class SequenceProvider extends ethers.ethers.providers.BaseProvider {
|
|
3103
3103
|
constructor(client, providerFor, networks = network.allNetworks) {
|
|
3104
|
-
var _this;
|
|
3105
3104
|
// We support a lot of networks
|
|
3106
3105
|
// but we start with the default one
|
|
3107
3106
|
super(client.getChainId());
|
|
3108
|
-
|
|
3107
|
+
|
|
3108
|
+
// Emit events as defined by EIP-1193
|
|
3109
3109
|
this.singleNetworkProviders = {};
|
|
3110
3110
|
this._isSequenceProvider = true;
|
|
3111
3111
|
this.client = client;
|
|
3112
3112
|
this.providerFor = providerFor;
|
|
3113
3113
|
this.networks = networks;
|
|
3114
|
-
client.
|
|
3115
|
-
|
|
3116
|
-
|
|
3114
|
+
client.onConnect(details => {
|
|
3115
|
+
this.emit('connect', details);
|
|
3116
|
+
});
|
|
3117
|
+
client.onDisconnect(error => {
|
|
3118
|
+
this.emit('disconnect', error);
|
|
3117
3119
|
});
|
|
3120
|
+
client.onDefaultChainIdChanged(chainId => {
|
|
3121
|
+
this.emit('chainChanged', chainId);
|
|
3122
|
+
});
|
|
3123
|
+
client.onAccountsChanged(accounts => {
|
|
3124
|
+
this.emit('accountsChanged', accounts);
|
|
3125
|
+
});
|
|
3126
|
+
|
|
3127
|
+
// NOTICE: We don't emit 'open' and 'close' events
|
|
3128
|
+
// because these are handled by the library, and they
|
|
3129
|
+
// are not part of EIP-1193
|
|
3130
|
+
|
|
3131
|
+
// devs can still access them using
|
|
3132
|
+
// client.onOpen()
|
|
3133
|
+
// client.onClose()
|
|
3118
3134
|
|
|
3119
3135
|
// Create a Sequence signer too
|
|
3120
3136
|
this.signer = new SequenceSigner(this.client, this);
|
|
@@ -3549,31 +3565,48 @@ class SequenceClient {
|
|
|
3549
3565
|
this.session = new SequenceClientSession(store);
|
|
3550
3566
|
this.defaultChainId = new DefaultChainIdTracker(store, defaultChainId);
|
|
3551
3567
|
this.transport.on('accountsChanged', accounts => {
|
|
3552
|
-
var _this$callbacks$
|
|
3568
|
+
var _this$callbacks$accou;
|
|
3553
3569
|
if (accounts.length > 1) {
|
|
3554
3570
|
console.warn('SequenceClient: wallet-webapp returned more than one account');
|
|
3555
3571
|
}
|
|
3556
|
-
(_this$callbacks$
|
|
3572
|
+
(_this$callbacks$accou = this.callbacks.accountsChanged) == null ? void 0 : _this$callbacks$accou.forEach(cb => cb(accounts));
|
|
3573
|
+
});
|
|
3574
|
+
this.transport.on('connect', response => {
|
|
3575
|
+
var _this$callbacks$conne;
|
|
3576
|
+
const chainIdHex = ethers.ethers.BigNumber.from(this.getChainId()).toHexString();
|
|
3577
|
+
(_this$callbacks$conne = this.callbacks.connect) == null ? void 0 : _this$callbacks$conne.forEach(cb => cb(_extends({}, response, {
|
|
3578
|
+
// Ignore the full connect response
|
|
3579
|
+
// use the chainId defined locally
|
|
3580
|
+
chainId: chainIdHex
|
|
3581
|
+
})));
|
|
3582
|
+
});
|
|
3583
|
+
this.transport.on('disconnect', error => {
|
|
3584
|
+
var _this$callbacks$disco;
|
|
3585
|
+
(_this$callbacks$disco = this.callbacks.disconnect) == null ? void 0 : _this$callbacks$disco.forEach(cb => cb(error));
|
|
3557
3586
|
});
|
|
3558
3587
|
this.transport.on('networks', networks => {
|
|
3559
|
-
var _this$callbacks$
|
|
3560
|
-
(_this$callbacks$
|
|
3588
|
+
var _this$callbacks$netwo;
|
|
3589
|
+
(_this$callbacks$netwo = this.callbacks.networks) == null ? void 0 : _this$callbacks$netwo.forEach(cb => cb(networks));
|
|
3561
3590
|
});
|
|
3562
3591
|
this.transport.on('walletContext', context => {
|
|
3563
|
-
var _this$callbacks$
|
|
3564
|
-
(_this$callbacks$
|
|
3592
|
+
var _this$callbacks$walle;
|
|
3593
|
+
(_this$callbacks$walle = this.callbacks.walletContext) == null ? void 0 : _this$callbacks$walle.forEach(cb => cb(context));
|
|
3565
3594
|
});
|
|
3566
|
-
this.transport.on('open',
|
|
3567
|
-
var _this$callbacks$
|
|
3568
|
-
(_this$callbacks$
|
|
3595
|
+
this.transport.on('open', info => {
|
|
3596
|
+
var _this$callbacks$open;
|
|
3597
|
+
(_this$callbacks$open = this.callbacks.open) == null ? void 0 : _this$callbacks$open.forEach(cb => cb(info));
|
|
3569
3598
|
});
|
|
3570
3599
|
this.transport.on('close', () => {
|
|
3571
|
-
var _this$callbacks$
|
|
3572
|
-
(_this$callbacks$
|
|
3600
|
+
var _this$callbacks$close;
|
|
3601
|
+
(_this$callbacks$close = this.callbacks.close) == null ? void 0 : _this$callbacks$close.forEach(cb => cb());
|
|
3573
3602
|
});
|
|
3603
|
+
|
|
3604
|
+
// We don't listen for the transport chainChanged event
|
|
3605
|
+
// instead we handle it locally, so we listen for changes in the store
|
|
3574
3606
|
this.defaultChainId.onDefaultChainIdChanged(chainId => {
|
|
3575
|
-
var _this$callbacks$
|
|
3576
|
-
|
|
3607
|
+
var _this$callbacks$chain;
|
|
3608
|
+
const chainIdHex = ethers.ethers.BigNumber.from(chainId).toHexString();
|
|
3609
|
+
(_this$callbacks$chain = this.callbacks.chainChanged) == null ? void 0 : _this$callbacks$chain.forEach(cb => cb(chainIdHex));
|
|
3577
3610
|
});
|
|
3578
3611
|
}
|
|
3579
3612
|
|
|
@@ -3592,24 +3625,30 @@ class SequenceClient {
|
|
|
3592
3625
|
// Individual callbacks lead to more idiomatic code
|
|
3593
3626
|
|
|
3594
3627
|
onOpen(callback) {
|
|
3595
|
-
return this.registerCallback('
|
|
3628
|
+
return this.registerCallback('open', callback);
|
|
3596
3629
|
}
|
|
3597
3630
|
onClose(callback) {
|
|
3598
|
-
return this.registerCallback('
|
|
3631
|
+
return this.registerCallback('close', callback);
|
|
3632
|
+
}
|
|
3633
|
+
onConnect(callback) {
|
|
3634
|
+
return this.registerCallback('connect', callback);
|
|
3635
|
+
}
|
|
3636
|
+
onDisconnect(callback) {
|
|
3637
|
+
return this.registerCallback('disconnect', callback);
|
|
3599
3638
|
}
|
|
3600
3639
|
onNetworks(callback) {
|
|
3601
|
-
return this.registerCallback('
|
|
3640
|
+
return this.registerCallback('networks', callback);
|
|
3602
3641
|
}
|
|
3603
3642
|
onAccountsChanged(callback) {
|
|
3604
|
-
return this.registerCallback('
|
|
3643
|
+
return this.registerCallback('accountsChanged', callback);
|
|
3605
3644
|
}
|
|
3606
3645
|
|
|
3607
3646
|
// @deprecated
|
|
3608
3647
|
onWalletContext(callback) {
|
|
3609
|
-
return this.registerCallback('
|
|
3648
|
+
return this.registerCallback('walletContext', callback);
|
|
3610
3649
|
}
|
|
3611
3650
|
onDefaultChainIdChanged(callback) {
|
|
3612
|
-
return this.registerCallback('
|
|
3651
|
+
return this.registerCallback('chainChanged', callback);
|
|
3613
3652
|
}
|
|
3614
3653
|
getChainId() {
|
|
3615
3654
|
return this.defaultChainId.getDefaultChainId();
|
|
@@ -3097,20 +3097,36 @@ class WalletUtils {
|
|
|
3097
3097
|
|
|
3098
3098
|
class SequenceProvider extends ethers.providers.BaseProvider {
|
|
3099
3099
|
constructor(client, providerFor, networks = allNetworks) {
|
|
3100
|
-
var _this;
|
|
3101
3100
|
// We support a lot of networks
|
|
3102
3101
|
// but we start with the default one
|
|
3103
3102
|
super(client.getChainId());
|
|
3104
|
-
|
|
3103
|
+
|
|
3104
|
+
// Emit events as defined by EIP-1193
|
|
3105
3105
|
this.singleNetworkProviders = {};
|
|
3106
3106
|
this._isSequenceProvider = true;
|
|
3107
3107
|
this.client = client;
|
|
3108
3108
|
this.providerFor = providerFor;
|
|
3109
3109
|
this.networks = networks;
|
|
3110
|
-
client.
|
|
3111
|
-
|
|
3112
|
-
|
|
3110
|
+
client.onConnect(details => {
|
|
3111
|
+
this.emit('connect', details);
|
|
3112
|
+
});
|
|
3113
|
+
client.onDisconnect(error => {
|
|
3114
|
+
this.emit('disconnect', error);
|
|
3113
3115
|
});
|
|
3116
|
+
client.onDefaultChainIdChanged(chainId => {
|
|
3117
|
+
this.emit('chainChanged', chainId);
|
|
3118
|
+
});
|
|
3119
|
+
client.onAccountsChanged(accounts => {
|
|
3120
|
+
this.emit('accountsChanged', accounts);
|
|
3121
|
+
});
|
|
3122
|
+
|
|
3123
|
+
// NOTICE: We don't emit 'open' and 'close' events
|
|
3124
|
+
// because these are handled by the library, and they
|
|
3125
|
+
// are not part of EIP-1193
|
|
3126
|
+
|
|
3127
|
+
// devs can still access them using
|
|
3128
|
+
// client.onOpen()
|
|
3129
|
+
// client.onClose()
|
|
3114
3130
|
|
|
3115
3131
|
// Create a Sequence signer too
|
|
3116
3132
|
this.signer = new SequenceSigner(this.client, this);
|
|
@@ -3545,31 +3561,48 @@ class SequenceClient {
|
|
|
3545
3561
|
this.session = new SequenceClientSession(store);
|
|
3546
3562
|
this.defaultChainId = new DefaultChainIdTracker(store, defaultChainId);
|
|
3547
3563
|
this.transport.on('accountsChanged', accounts => {
|
|
3548
|
-
var _this$callbacks$
|
|
3564
|
+
var _this$callbacks$accou;
|
|
3549
3565
|
if (accounts.length > 1) {
|
|
3550
3566
|
console.warn('SequenceClient: wallet-webapp returned more than one account');
|
|
3551
3567
|
}
|
|
3552
|
-
(_this$callbacks$
|
|
3568
|
+
(_this$callbacks$accou = this.callbacks.accountsChanged) == null ? void 0 : _this$callbacks$accou.forEach(cb => cb(accounts));
|
|
3569
|
+
});
|
|
3570
|
+
this.transport.on('connect', response => {
|
|
3571
|
+
var _this$callbacks$conne;
|
|
3572
|
+
const chainIdHex = ethers.BigNumber.from(this.getChainId()).toHexString();
|
|
3573
|
+
(_this$callbacks$conne = this.callbacks.connect) == null ? void 0 : _this$callbacks$conne.forEach(cb => cb(_extends({}, response, {
|
|
3574
|
+
// Ignore the full connect response
|
|
3575
|
+
// use the chainId defined locally
|
|
3576
|
+
chainId: chainIdHex
|
|
3577
|
+
})));
|
|
3578
|
+
});
|
|
3579
|
+
this.transport.on('disconnect', error => {
|
|
3580
|
+
var _this$callbacks$disco;
|
|
3581
|
+
(_this$callbacks$disco = this.callbacks.disconnect) == null ? void 0 : _this$callbacks$disco.forEach(cb => cb(error));
|
|
3553
3582
|
});
|
|
3554
3583
|
this.transport.on('networks', networks => {
|
|
3555
|
-
var _this$callbacks$
|
|
3556
|
-
(_this$callbacks$
|
|
3584
|
+
var _this$callbacks$netwo;
|
|
3585
|
+
(_this$callbacks$netwo = this.callbacks.networks) == null ? void 0 : _this$callbacks$netwo.forEach(cb => cb(networks));
|
|
3557
3586
|
});
|
|
3558
3587
|
this.transport.on('walletContext', context => {
|
|
3559
|
-
var _this$callbacks$
|
|
3560
|
-
(_this$callbacks$
|
|
3588
|
+
var _this$callbacks$walle;
|
|
3589
|
+
(_this$callbacks$walle = this.callbacks.walletContext) == null ? void 0 : _this$callbacks$walle.forEach(cb => cb(context));
|
|
3561
3590
|
});
|
|
3562
|
-
this.transport.on('open',
|
|
3563
|
-
var _this$callbacks$
|
|
3564
|
-
(_this$callbacks$
|
|
3591
|
+
this.transport.on('open', info => {
|
|
3592
|
+
var _this$callbacks$open;
|
|
3593
|
+
(_this$callbacks$open = this.callbacks.open) == null ? void 0 : _this$callbacks$open.forEach(cb => cb(info));
|
|
3565
3594
|
});
|
|
3566
3595
|
this.transport.on('close', () => {
|
|
3567
|
-
var _this$callbacks$
|
|
3568
|
-
(_this$callbacks$
|
|
3596
|
+
var _this$callbacks$close;
|
|
3597
|
+
(_this$callbacks$close = this.callbacks.close) == null ? void 0 : _this$callbacks$close.forEach(cb => cb());
|
|
3569
3598
|
});
|
|
3599
|
+
|
|
3600
|
+
// We don't listen for the transport chainChanged event
|
|
3601
|
+
// instead we handle it locally, so we listen for changes in the store
|
|
3570
3602
|
this.defaultChainId.onDefaultChainIdChanged(chainId => {
|
|
3571
|
-
var _this$callbacks$
|
|
3572
|
-
|
|
3603
|
+
var _this$callbacks$chain;
|
|
3604
|
+
const chainIdHex = ethers.BigNumber.from(chainId).toHexString();
|
|
3605
|
+
(_this$callbacks$chain = this.callbacks.chainChanged) == null ? void 0 : _this$callbacks$chain.forEach(cb => cb(chainIdHex));
|
|
3573
3606
|
});
|
|
3574
3607
|
}
|
|
3575
3608
|
|
|
@@ -3588,24 +3621,30 @@ class SequenceClient {
|
|
|
3588
3621
|
// Individual callbacks lead to more idiomatic code
|
|
3589
3622
|
|
|
3590
3623
|
onOpen(callback) {
|
|
3591
|
-
return this.registerCallback('
|
|
3624
|
+
return this.registerCallback('open', callback);
|
|
3592
3625
|
}
|
|
3593
3626
|
onClose(callback) {
|
|
3594
|
-
return this.registerCallback('
|
|
3627
|
+
return this.registerCallback('close', callback);
|
|
3628
|
+
}
|
|
3629
|
+
onConnect(callback) {
|
|
3630
|
+
return this.registerCallback('connect', callback);
|
|
3631
|
+
}
|
|
3632
|
+
onDisconnect(callback) {
|
|
3633
|
+
return this.registerCallback('disconnect', callback);
|
|
3595
3634
|
}
|
|
3596
3635
|
onNetworks(callback) {
|
|
3597
|
-
return this.registerCallback('
|
|
3636
|
+
return this.registerCallback('networks', callback);
|
|
3598
3637
|
}
|
|
3599
3638
|
onAccountsChanged(callback) {
|
|
3600
|
-
return this.registerCallback('
|
|
3639
|
+
return this.registerCallback('accountsChanged', callback);
|
|
3601
3640
|
}
|
|
3602
3641
|
|
|
3603
3642
|
// @deprecated
|
|
3604
3643
|
onWalletContext(callback) {
|
|
3605
|
-
return this.registerCallback('
|
|
3644
|
+
return this.registerCallback('walletContext', callback);
|
|
3606
3645
|
}
|
|
3607
3646
|
onDefaultChainIdChanged(callback) {
|
|
3608
|
-
return this.registerCallback('
|
|
3647
|
+
return this.registerCallback('chainChanged', callback);
|
|
3609
3648
|
}
|
|
3610
3649
|
getChainId() {
|
|
3611
3650
|
return this.defaultChainId.getDefaultChainId();
|
|
@@ -1,16 +1,8 @@
|
|
|
1
1
|
import { JsonRpcRequest, NetworkConfig } from "@0xsequence/network";
|
|
2
|
-
import { ConnectDetails, ConnectOptions, ItemStore, MuxTransportTemplate, OpenWalletIntent, OptionalChainId, OptionalEIP6492, ProviderTransport, WalletSession } from "./index.js";
|
|
2
|
+
import { ConnectDetails, ConnectOptions, ItemStore, MuxTransportTemplate, OpenWalletIntent, OptionalChainId, OptionalEIP6492, ProviderTransport, WalletEventTypes, WalletSession } from "./index.js";
|
|
3
3
|
import { commons } from "@0xsequence/core";
|
|
4
4
|
import { TypedData } from "@0xsequence/utils";
|
|
5
5
|
import { ethers } from "ethers";
|
|
6
|
-
type Callbacks = {
|
|
7
|
-
onOpen: () => void;
|
|
8
|
-
onClose: () => void;
|
|
9
|
-
onNetworks: (networks: NetworkConfig[]) => void;
|
|
10
|
-
onAccountsChanged: (accounts: string[]) => void;
|
|
11
|
-
onWalletContext: (context: commons.context.VersionedContext) => void;
|
|
12
|
-
onDefaultChainIdChanged: (chainId: number) => void;
|
|
13
|
-
};
|
|
14
6
|
/**
|
|
15
7
|
* This session class is meant to persist the state of the wallet connection
|
|
16
8
|
* whitin the dapp. This enables the client to retain the wallet address (and some more)
|
|
@@ -53,13 +45,15 @@ export declare class SequenceClient {
|
|
|
53
45
|
private readonly callbacks;
|
|
54
46
|
readonly transport: ProviderTransport;
|
|
55
47
|
constructor(transport: ProviderTransport | MuxTransportTemplate, store: ItemStore, defaultChainId?: number);
|
|
56
|
-
registerCallback<K extends keyof
|
|
57
|
-
onOpen(callback:
|
|
58
|
-
onClose(callback:
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
48
|
+
registerCallback<K extends keyof WalletEventTypes>(eventName: K, callback: WalletEventTypes[K]): () => void;
|
|
49
|
+
onOpen(callback: WalletEventTypes['open']): () => void;
|
|
50
|
+
onClose(callback: WalletEventTypes['close']): () => void;
|
|
51
|
+
onConnect(callback: WalletEventTypes['connect']): () => void;
|
|
52
|
+
onDisconnect(callback: WalletEventTypes['disconnect']): () => void;
|
|
53
|
+
onNetworks(callback: WalletEventTypes['networks']): () => void;
|
|
54
|
+
onAccountsChanged(callback: WalletEventTypes['accountsChanged']): () => void;
|
|
55
|
+
onWalletContext(callback: WalletEventTypes['walletContext']): () => void;
|
|
56
|
+
onDefaultChainIdChanged(callback: WalletEventTypes['chainChanged']): () => void;
|
|
63
57
|
getChainId(): number;
|
|
64
58
|
setDefaultChainId(chainId: number): void;
|
|
65
59
|
openWallet(path?: string, intent?: OpenWalletIntent): Promise<boolean>;
|
|
@@ -78,4 +72,3 @@ export declare class SequenceClient {
|
|
|
78
72
|
getWalletContext(): Promise<commons.context.VersionedContext>;
|
|
79
73
|
getOnchainWalletConfig(options?: OptionalChainId): Promise<commons.config.Config>;
|
|
80
74
|
}
|
|
81
|
-
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0xsequence/provider",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-20230727132905",
|
|
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/
|
|
15
|
-
"@0xsequence/
|
|
16
|
-
"@0xsequence/
|
|
17
|
-
"@0xsequence/auth": "0.0.0-
|
|
18
|
-
"@0xsequence/
|
|
19
|
-
"@0xsequence/network": "0.0.0-
|
|
20
|
-
"@0xsequence/
|
|
21
|
-
"@0xsequence/
|
|
22
|
-
"@0xsequence/wallet": "0.0.0-
|
|
14
|
+
"@0xsequence/account": "0.0.0-20230727132905",
|
|
15
|
+
"@0xsequence/core": "0.0.0-20230727132905",
|
|
16
|
+
"@0xsequence/abi": "0.0.0-20230727132905",
|
|
17
|
+
"@0xsequence/auth": "0.0.0-20230727132905",
|
|
18
|
+
"@0xsequence/migration": "0.0.0-20230727132905",
|
|
19
|
+
"@0xsequence/network": "0.0.0-20230727132905",
|
|
20
|
+
"@0xsequence/utils": "0.0.0-20230727132905",
|
|
21
|
+
"@0xsequence/relayer": "0.0.0-20230727132905",
|
|
22
|
+
"@0xsequence/wallet": "0.0.0-20230727132905"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"ethers": ">=5.5 < 6"
|
package/src/client.ts
CHANGED
|
@@ -1,18 +1,10 @@
|
|
|
1
1
|
import { JsonRpcRequest, JsonRpcResponse, NetworkConfig } from "@0xsequence/network"
|
|
2
|
-
import { ConnectDetails, ConnectOptions, ItemStore, MuxMessageProvider, MuxTransportTemplate, OpenWalletIntent, OptionalChainId, OptionalEIP6492, ProviderTransport, WalletSession, isMuxTransportTemplate, isProviderTransport } from "."
|
|
2
|
+
import { ConnectDetails, ConnectOptions, ItemStore, MuxMessageProvider, MuxTransportTemplate, OpenWalletIntent, OptionalChainId, OptionalEIP6492, ProviderTransport, WalletEventTypes, WalletSession, isMuxTransportTemplate, isProviderTransport } from "."
|
|
3
3
|
import { commons } from "@0xsequence/core"
|
|
4
4
|
import { TypedData } from "@0xsequence/utils"
|
|
5
5
|
import { toExtended } from "./extended"
|
|
6
6
|
import { ethers } from "ethers"
|
|
7
7
|
|
|
8
|
-
type Callbacks = {
|
|
9
|
-
onOpen: () => void
|
|
10
|
-
onClose: () => void
|
|
11
|
-
onNetworks: (networks: NetworkConfig[]) => void
|
|
12
|
-
onAccountsChanged: (accounts: string[]) => void
|
|
13
|
-
onWalletContext: (context: commons.context.VersionedContext) => void
|
|
14
|
-
onDefaultChainIdChanged: (chainId: number) => void
|
|
15
|
-
}
|
|
16
8
|
|
|
17
9
|
/**
|
|
18
10
|
* This session class is meant to persist the state of the wallet connection
|
|
@@ -123,7 +115,7 @@ export class DefaultChainIdTracker {
|
|
|
123
115
|
export class SequenceClient {
|
|
124
116
|
private readonly session: SequenceClientSession
|
|
125
117
|
private readonly defaultChainId: DefaultChainIdTracker
|
|
126
|
-
private readonly callbacks: { [K in keyof
|
|
118
|
+
private readonly callbacks: { [K in keyof WalletEventTypes]?: WalletEventTypes[K][] } = {}
|
|
127
119
|
|
|
128
120
|
public readonly transport: ProviderTransport
|
|
129
121
|
|
|
@@ -148,33 +140,50 @@ export class SequenceClient {
|
|
|
148
140
|
console.warn('SequenceClient: wallet-webapp returned more than one account')
|
|
149
141
|
}
|
|
150
142
|
|
|
151
|
-
this.callbacks.
|
|
143
|
+
this.callbacks.accountsChanged?.forEach(cb => cb(accounts))
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
this.transport.on('connect', (response: ConnectDetails) => {
|
|
147
|
+
const chainIdHex = ethers.BigNumber.from(this.getChainId()).toHexString()
|
|
148
|
+
this.callbacks.connect?.forEach(cb => cb({
|
|
149
|
+
...response,
|
|
150
|
+
// Ignore the full connect response
|
|
151
|
+
// use the chainId defined locally
|
|
152
|
+
chainId: chainIdHex
|
|
153
|
+
}))
|
|
154
|
+
})
|
|
155
|
+
|
|
156
|
+
this.transport.on('disconnect', (error) => {
|
|
157
|
+
this.callbacks.disconnect?.forEach(cb => cb(error))
|
|
152
158
|
})
|
|
153
159
|
|
|
154
|
-
this.transport.on('networks', (networks
|
|
155
|
-
this.callbacks.
|
|
160
|
+
this.transport.on('networks', (networks) => {
|
|
161
|
+
this.callbacks.networks?.forEach(cb => cb(networks))
|
|
156
162
|
})
|
|
157
163
|
|
|
158
|
-
this.transport.on('walletContext', (context
|
|
159
|
-
this.callbacks.
|
|
164
|
+
this.transport.on('walletContext', (context) => {
|
|
165
|
+
this.callbacks.walletContext?.forEach(cb => cb(context))
|
|
160
166
|
})
|
|
161
167
|
|
|
162
|
-
this.transport.on('open', () => {
|
|
163
|
-
this.callbacks.
|
|
168
|
+
this.transport.on('open', (info) => {
|
|
169
|
+
this.callbacks.open?.forEach(cb => cb(info))
|
|
164
170
|
})
|
|
165
171
|
|
|
166
172
|
this.transport.on('close', () => {
|
|
167
|
-
this.callbacks.
|
|
173
|
+
this.callbacks.close?.forEach(cb => cb())
|
|
168
174
|
})
|
|
169
175
|
|
|
176
|
+
// We don't listen for the transport chainChanged event
|
|
177
|
+
// instead we handle it locally, so we listen for changes in the store
|
|
170
178
|
this.defaultChainId.onDefaultChainIdChanged((chainId: number) => {
|
|
171
|
-
|
|
179
|
+
const chainIdHex = ethers.BigNumber.from(chainId).toHexString()
|
|
180
|
+
this.callbacks.chainChanged?.forEach(cb => cb(chainIdHex))
|
|
172
181
|
})
|
|
173
182
|
}
|
|
174
183
|
|
|
175
184
|
// Callbacks
|
|
176
185
|
|
|
177
|
-
registerCallback<K extends keyof
|
|
186
|
+
registerCallback<K extends keyof WalletEventTypes>(eventName: K, callback: WalletEventTypes[K]) {
|
|
178
187
|
if (!this.callbacks[eventName]) {
|
|
179
188
|
this.callbacks[eventName] = []
|
|
180
189
|
}
|
|
@@ -188,29 +197,37 @@ export class SequenceClient {
|
|
|
188
197
|
|
|
189
198
|
// Individual callbacks lead to more idiomatic code
|
|
190
199
|
|
|
191
|
-
onOpen(callback:
|
|
192
|
-
return this.registerCallback('
|
|
200
|
+
onOpen(callback: WalletEventTypes['open']) {
|
|
201
|
+
return this.registerCallback('open', callback)
|
|
193
202
|
}
|
|
194
203
|
|
|
195
|
-
onClose(callback:
|
|
196
|
-
return this.registerCallback('
|
|
204
|
+
onClose(callback: WalletEventTypes['close']) {
|
|
205
|
+
return this.registerCallback('close', callback)
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
onConnect(callback: WalletEventTypes['connect']) {
|
|
209
|
+
return this.registerCallback('connect', callback)
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
onDisconnect(callback: WalletEventTypes['disconnect']) {
|
|
213
|
+
return this.registerCallback('disconnect', callback)
|
|
197
214
|
}
|
|
198
215
|
|
|
199
|
-
onNetworks(callback:
|
|
200
|
-
return this.registerCallback('
|
|
216
|
+
onNetworks(callback: WalletEventTypes['networks']) {
|
|
217
|
+
return this.registerCallback('networks', callback)
|
|
201
218
|
}
|
|
202
219
|
|
|
203
|
-
onAccountsChanged(callback:
|
|
204
|
-
return this.registerCallback('
|
|
220
|
+
onAccountsChanged(callback: WalletEventTypes['accountsChanged']) {
|
|
221
|
+
return this.registerCallback('accountsChanged', callback)
|
|
205
222
|
}
|
|
206
223
|
|
|
207
224
|
// @deprecated
|
|
208
|
-
onWalletContext(callback:
|
|
209
|
-
return this.registerCallback('
|
|
225
|
+
onWalletContext(callback: WalletEventTypes['walletContext']) {
|
|
226
|
+
return this.registerCallback('walletContext', callback)
|
|
210
227
|
}
|
|
211
228
|
|
|
212
|
-
onDefaultChainIdChanged(callback:
|
|
213
|
-
return this.registerCallback('
|
|
229
|
+
onDefaultChainIdChanged(callback: WalletEventTypes['chainChanged']) {
|
|
230
|
+
return this.registerCallback('chainChanged', callback)
|
|
214
231
|
}
|
|
215
232
|
|
|
216
233
|
getChainId(): number {
|
package/src/provider.ts
CHANGED
|
@@ -63,11 +63,32 @@ export class SequenceProvider extends ethers.providers.BaseProvider implements I
|
|
|
63
63
|
// We support a lot of networks
|
|
64
64
|
// but we start with the default one
|
|
65
65
|
super(client.getChainId())
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
|
|
67
|
+
// Emit events as defined by EIP-1193
|
|
68
|
+
client.onConnect((details) => {
|
|
69
|
+
this.emit('connect', details)
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
client.onDisconnect((error) => {
|
|
73
|
+
this.emit('disconnect', error)
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
client.onDefaultChainIdChanged((chainId) => {
|
|
68
77
|
this.emit('chainChanged', chainId)
|
|
69
78
|
})
|
|
70
79
|
|
|
80
|
+
client.onAccountsChanged((accounts) => {
|
|
81
|
+
this.emit('accountsChanged', accounts)
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
// NOTICE: We don't emit 'open' and 'close' events
|
|
85
|
+
// because these are handled by the library, and they
|
|
86
|
+
// are not part of EIP-1193
|
|
87
|
+
|
|
88
|
+
// devs can still access them using
|
|
89
|
+
// client.onOpen()
|
|
90
|
+
// client.onClose()
|
|
91
|
+
|
|
71
92
|
// Create a Sequence signer too
|
|
72
93
|
this.signer = new SequenceSigner(this.client, this)
|
|
73
94
|
|