@0xsequence/provider 0.0.0-20230726172246 → 0.0.0-20230726193528
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 +25 -19
- package/dist/0xsequence-provider.cjs.prod.js +25 -19
- package/dist/0xsequence-provider.esm.js +25 -19
- package/dist/declarations/src/client.d.ts +3 -3
- package/package.json +10 -10
- package/src/client.ts +16 -17
- package/src/utils.ts +10 -2
|
@@ -654,11 +654,10 @@ class LocalStorage {
|
|
|
654
654
|
}
|
|
655
655
|
window.addEventListener('storage', e => {
|
|
656
656
|
const {
|
|
657
|
-
key
|
|
658
|
-
newValue
|
|
657
|
+
key
|
|
659
658
|
} = e;
|
|
660
659
|
const cb = this.callbacks.filter(c => c.key === key);
|
|
661
|
-
cb.forEach(c => c.cb(
|
|
660
|
+
cb.forEach(c => c.cb(this.getItem(key)));
|
|
662
661
|
});
|
|
663
662
|
}
|
|
664
663
|
getItem(key) {
|
|
@@ -666,9 +665,17 @@ class LocalStorage {
|
|
|
666
665
|
}
|
|
667
666
|
setItem(key, value) {
|
|
668
667
|
window.localStorage.setItem(key, value);
|
|
668
|
+
|
|
669
|
+
// Trigger callbacks
|
|
670
|
+
// NOTICE: the event is not triggered on the same window
|
|
671
|
+
this.callbacks.filter(c => c.key === key).forEach(c => c.cb(value));
|
|
669
672
|
}
|
|
670
673
|
removeItem(key) {
|
|
671
674
|
window.localStorage.removeItem(key);
|
|
675
|
+
|
|
676
|
+
// Trigger callbacks
|
|
677
|
+
// NOTICE: the event is not triggered on the same window
|
|
678
|
+
this.callbacks.filter(c => c.key === key).forEach(c => c.cb(null));
|
|
672
679
|
}
|
|
673
680
|
onItemChange(key, cb) {
|
|
674
681
|
this.callbacks.push({
|
|
@@ -3495,7 +3502,7 @@ class DefaultChainIdTracker {
|
|
|
3495
3502
|
this.callbacks = [];
|
|
3496
3503
|
this.store = store;
|
|
3497
3504
|
this.startingChainId = startingChainId;
|
|
3498
|
-
store.onItemChange(DefaultChainIdTracker.
|
|
3505
|
+
store.onItemChange(DefaultChainIdTracker.SESSION_CHAIN_ID_KEY, value => {
|
|
3499
3506
|
if (value) {
|
|
3500
3507
|
const chainId = parseInt(value);
|
|
3501
3508
|
this.callbacks.forEach(cb => cb(chainId));
|
|
@@ -3510,11 +3517,11 @@ class DefaultChainIdTracker {
|
|
|
3510
3517
|
}
|
|
3511
3518
|
setDefaultChainId(chainId) {
|
|
3512
3519
|
if (chainId !== this.getDefaultChainId()) {
|
|
3513
|
-
this.store.setItem(DefaultChainIdTracker.
|
|
3520
|
+
this.store.setItem(DefaultChainIdTracker.SESSION_CHAIN_ID_KEY, chainId.toString());
|
|
3514
3521
|
}
|
|
3515
3522
|
}
|
|
3516
3523
|
getDefaultChainId() {
|
|
3517
|
-
const read = this.store.getItem(DefaultChainIdTracker.
|
|
3524
|
+
const read = this.store.getItem(DefaultChainIdTracker.SESSION_CHAIN_ID_KEY);
|
|
3518
3525
|
if (!read || read.length === 0) {
|
|
3519
3526
|
return this.startingChainId;
|
|
3520
3527
|
}
|
|
@@ -3528,7 +3535,7 @@ class DefaultChainIdTracker {
|
|
|
3528
3535
|
*
|
|
3529
3536
|
* It doesn't implement a full ethereum Provider, it doesn't include read-only methods.
|
|
3530
3537
|
*/
|
|
3531
|
-
DefaultChainIdTracker.
|
|
3538
|
+
DefaultChainIdTracker.SESSION_CHAIN_ID_KEY = '@sequence.session.defaultChainId';
|
|
3532
3539
|
class SequenceClient {
|
|
3533
3540
|
constructor(transport, store, defaultChainId) {
|
|
3534
3541
|
this.callbacks = {};
|
|
@@ -3705,8 +3712,12 @@ class SequenceClient {
|
|
|
3705
3712
|
reject(error);
|
|
3706
3713
|
} else if (response === undefined) {
|
|
3707
3714
|
reject(new Error(`Got undefined response for request: ${request}`));
|
|
3715
|
+
} else if (typeof response === 'object' && response.error) {
|
|
3716
|
+
reject(response.error);
|
|
3717
|
+
} else if (typeof response === 'object' && response.result) {
|
|
3718
|
+
resolve(response.result);
|
|
3708
3719
|
} else {
|
|
3709
|
-
|
|
3720
|
+
reject(new Error(`Got invalid response for request: ${request}`));
|
|
3710
3721
|
}
|
|
3711
3722
|
}, chainId || this.getChainId());
|
|
3712
3723
|
});
|
|
@@ -3714,10 +3725,9 @@ class SequenceClient {
|
|
|
3714
3725
|
async getNetworks(pull) {
|
|
3715
3726
|
const connectedSession = this.session.connectedSession();
|
|
3716
3727
|
if (pull) {
|
|
3717
|
-
|
|
3728
|
+
connectedSession.networks = await this.send({
|
|
3718
3729
|
method: 'sequence_getNetworks'
|
|
3719
3730
|
});
|
|
3720
|
-
connectedSession.networks = nextNetworks.result;
|
|
3721
3731
|
this.session.setSession(connectedSession);
|
|
3722
3732
|
}
|
|
3723
3733
|
return connectedSession.networks;
|
|
@@ -3726,11 +3736,10 @@ class SequenceClient {
|
|
|
3726
3736
|
const method = options != null && options.eip6492 ? 'sequence_sign' : 'personal_sign';
|
|
3727
3737
|
|
|
3728
3738
|
// Address is ignored by the wallet webapp
|
|
3729
|
-
|
|
3739
|
+
return this.send({
|
|
3730
3740
|
method,
|
|
3731
3741
|
params: [message, this.getAddress()]
|
|
3732
3742
|
}, options == null ? void 0 : options.chainId);
|
|
3733
|
-
return res.result;
|
|
3734
3743
|
}
|
|
3735
3744
|
async signTypedData(typedData, options) {
|
|
3736
3745
|
const method = options != null && options.eip6492 ? 'sequence_signTypedData_v4' : 'eth_signTypedData_v4';
|
|
@@ -3744,26 +3753,23 @@ class SequenceClient {
|
|
|
3744
3753
|
// - The one provided in the typedData.domain.chainId
|
|
3745
3754
|
// - The default chainId
|
|
3746
3755
|
|
|
3747
|
-
|
|
3756
|
+
return this.send({
|
|
3748
3757
|
method,
|
|
3749
3758
|
params: [this.getAddress(), encoded]
|
|
3750
3759
|
}, (options == null ? void 0 : options.chainId) || typedData.domain.chainId && ethers.ethers.BigNumber.from(typedData.domain.chainId).toNumber() || this.getChainId());
|
|
3751
|
-
return res.result;
|
|
3752
3760
|
}
|
|
3753
3761
|
async sendTransaction(tx, options) {
|
|
3754
3762
|
const sequenceTxs = Array.isArray(tx) ? tx : [tx];
|
|
3755
3763
|
const extendedTxs = toExtended(sequenceTxs);
|
|
3756
|
-
|
|
3764
|
+
return this.send({
|
|
3757
3765
|
method: 'eth_sendTransaction',
|
|
3758
3766
|
params: [extendedTxs]
|
|
3759
3767
|
}, options == null ? void 0 : options.chainId);
|
|
3760
|
-
return res.result;
|
|
3761
3768
|
}
|
|
3762
3769
|
async getWalletContext() {
|
|
3763
|
-
|
|
3770
|
+
return this.send({
|
|
3764
3771
|
method: 'sequence_getWalletContext'
|
|
3765
3772
|
});
|
|
3766
|
-
return res.result;
|
|
3767
3773
|
}
|
|
3768
3774
|
async getOnchainWalletConfig(options) {
|
|
3769
3775
|
// NOTICE: sequence_getWalletConfig sends the chainId as a param
|
|
@@ -3771,7 +3777,7 @@ class SequenceClient {
|
|
|
3771
3777
|
method: 'sequence_getWalletConfig',
|
|
3772
3778
|
params: [(options == null ? void 0 : options.chainId) || this.getChainId()]
|
|
3773
3779
|
}, options == null ? void 0 : options.chainId);
|
|
3774
|
-
return Array.isArray(res
|
|
3780
|
+
return Array.isArray(res) ? res[0] : res;
|
|
3775
3781
|
}
|
|
3776
3782
|
|
|
3777
3783
|
// NOTICE: We are leaving out all the "regular" methods os a tipical
|
|
@@ -654,11 +654,10 @@ class LocalStorage {
|
|
|
654
654
|
}
|
|
655
655
|
window.addEventListener('storage', e => {
|
|
656
656
|
const {
|
|
657
|
-
key
|
|
658
|
-
newValue
|
|
657
|
+
key
|
|
659
658
|
} = e;
|
|
660
659
|
const cb = this.callbacks.filter(c => c.key === key);
|
|
661
|
-
cb.forEach(c => c.cb(
|
|
660
|
+
cb.forEach(c => c.cb(this.getItem(key)));
|
|
662
661
|
});
|
|
663
662
|
}
|
|
664
663
|
getItem(key) {
|
|
@@ -666,9 +665,17 @@ class LocalStorage {
|
|
|
666
665
|
}
|
|
667
666
|
setItem(key, value) {
|
|
668
667
|
window.localStorage.setItem(key, value);
|
|
668
|
+
|
|
669
|
+
// Trigger callbacks
|
|
670
|
+
// NOTICE: the event is not triggered on the same window
|
|
671
|
+
this.callbacks.filter(c => c.key === key).forEach(c => c.cb(value));
|
|
669
672
|
}
|
|
670
673
|
removeItem(key) {
|
|
671
674
|
window.localStorage.removeItem(key);
|
|
675
|
+
|
|
676
|
+
// Trigger callbacks
|
|
677
|
+
// NOTICE: the event is not triggered on the same window
|
|
678
|
+
this.callbacks.filter(c => c.key === key).forEach(c => c.cb(null));
|
|
672
679
|
}
|
|
673
680
|
onItemChange(key, cb) {
|
|
674
681
|
this.callbacks.push({
|
|
@@ -3495,7 +3502,7 @@ class DefaultChainIdTracker {
|
|
|
3495
3502
|
this.callbacks = [];
|
|
3496
3503
|
this.store = store;
|
|
3497
3504
|
this.startingChainId = startingChainId;
|
|
3498
|
-
store.onItemChange(DefaultChainIdTracker.
|
|
3505
|
+
store.onItemChange(DefaultChainIdTracker.SESSION_CHAIN_ID_KEY, value => {
|
|
3499
3506
|
if (value) {
|
|
3500
3507
|
const chainId = parseInt(value);
|
|
3501
3508
|
this.callbacks.forEach(cb => cb(chainId));
|
|
@@ -3510,11 +3517,11 @@ class DefaultChainIdTracker {
|
|
|
3510
3517
|
}
|
|
3511
3518
|
setDefaultChainId(chainId) {
|
|
3512
3519
|
if (chainId !== this.getDefaultChainId()) {
|
|
3513
|
-
this.store.setItem(DefaultChainIdTracker.
|
|
3520
|
+
this.store.setItem(DefaultChainIdTracker.SESSION_CHAIN_ID_KEY, chainId.toString());
|
|
3514
3521
|
}
|
|
3515
3522
|
}
|
|
3516
3523
|
getDefaultChainId() {
|
|
3517
|
-
const read = this.store.getItem(DefaultChainIdTracker.
|
|
3524
|
+
const read = this.store.getItem(DefaultChainIdTracker.SESSION_CHAIN_ID_KEY);
|
|
3518
3525
|
if (!read || read.length === 0) {
|
|
3519
3526
|
return this.startingChainId;
|
|
3520
3527
|
}
|
|
@@ -3528,7 +3535,7 @@ class DefaultChainIdTracker {
|
|
|
3528
3535
|
*
|
|
3529
3536
|
* It doesn't implement a full ethereum Provider, it doesn't include read-only methods.
|
|
3530
3537
|
*/
|
|
3531
|
-
DefaultChainIdTracker.
|
|
3538
|
+
DefaultChainIdTracker.SESSION_CHAIN_ID_KEY = '@sequence.session.defaultChainId';
|
|
3532
3539
|
class SequenceClient {
|
|
3533
3540
|
constructor(transport, store, defaultChainId) {
|
|
3534
3541
|
this.callbacks = {};
|
|
@@ -3705,8 +3712,12 @@ class SequenceClient {
|
|
|
3705
3712
|
reject(error);
|
|
3706
3713
|
} else if (response === undefined) {
|
|
3707
3714
|
reject(new Error(`Got undefined response for request: ${request}`));
|
|
3715
|
+
} else if (typeof response === 'object' && response.error) {
|
|
3716
|
+
reject(response.error);
|
|
3717
|
+
} else if (typeof response === 'object' && response.result) {
|
|
3718
|
+
resolve(response.result);
|
|
3708
3719
|
} else {
|
|
3709
|
-
|
|
3720
|
+
reject(new Error(`Got invalid response for request: ${request}`));
|
|
3710
3721
|
}
|
|
3711
3722
|
}, chainId || this.getChainId());
|
|
3712
3723
|
});
|
|
@@ -3714,10 +3725,9 @@ class SequenceClient {
|
|
|
3714
3725
|
async getNetworks(pull) {
|
|
3715
3726
|
const connectedSession = this.session.connectedSession();
|
|
3716
3727
|
if (pull) {
|
|
3717
|
-
|
|
3728
|
+
connectedSession.networks = await this.send({
|
|
3718
3729
|
method: 'sequence_getNetworks'
|
|
3719
3730
|
});
|
|
3720
|
-
connectedSession.networks = nextNetworks.result;
|
|
3721
3731
|
this.session.setSession(connectedSession);
|
|
3722
3732
|
}
|
|
3723
3733
|
return connectedSession.networks;
|
|
@@ -3726,11 +3736,10 @@ class SequenceClient {
|
|
|
3726
3736
|
const method = options != null && options.eip6492 ? 'sequence_sign' : 'personal_sign';
|
|
3727
3737
|
|
|
3728
3738
|
// Address is ignored by the wallet webapp
|
|
3729
|
-
|
|
3739
|
+
return this.send({
|
|
3730
3740
|
method,
|
|
3731
3741
|
params: [message, this.getAddress()]
|
|
3732
3742
|
}, options == null ? void 0 : options.chainId);
|
|
3733
|
-
return res.result;
|
|
3734
3743
|
}
|
|
3735
3744
|
async signTypedData(typedData, options) {
|
|
3736
3745
|
const method = options != null && options.eip6492 ? 'sequence_signTypedData_v4' : 'eth_signTypedData_v4';
|
|
@@ -3744,26 +3753,23 @@ class SequenceClient {
|
|
|
3744
3753
|
// - The one provided in the typedData.domain.chainId
|
|
3745
3754
|
// - The default chainId
|
|
3746
3755
|
|
|
3747
|
-
|
|
3756
|
+
return this.send({
|
|
3748
3757
|
method,
|
|
3749
3758
|
params: [this.getAddress(), encoded]
|
|
3750
3759
|
}, (options == null ? void 0 : options.chainId) || typedData.domain.chainId && ethers.ethers.BigNumber.from(typedData.domain.chainId).toNumber() || this.getChainId());
|
|
3751
|
-
return res.result;
|
|
3752
3760
|
}
|
|
3753
3761
|
async sendTransaction(tx, options) {
|
|
3754
3762
|
const sequenceTxs = Array.isArray(tx) ? tx : [tx];
|
|
3755
3763
|
const extendedTxs = toExtended(sequenceTxs);
|
|
3756
|
-
|
|
3764
|
+
return this.send({
|
|
3757
3765
|
method: 'eth_sendTransaction',
|
|
3758
3766
|
params: [extendedTxs]
|
|
3759
3767
|
}, options == null ? void 0 : options.chainId);
|
|
3760
|
-
return res.result;
|
|
3761
3768
|
}
|
|
3762
3769
|
async getWalletContext() {
|
|
3763
|
-
|
|
3770
|
+
return this.send({
|
|
3764
3771
|
method: 'sequence_getWalletContext'
|
|
3765
3772
|
});
|
|
3766
|
-
return res.result;
|
|
3767
3773
|
}
|
|
3768
3774
|
async getOnchainWalletConfig(options) {
|
|
3769
3775
|
// NOTICE: sequence_getWalletConfig sends the chainId as a param
|
|
@@ -3771,7 +3777,7 @@ class SequenceClient {
|
|
|
3771
3777
|
method: 'sequence_getWalletConfig',
|
|
3772
3778
|
params: [(options == null ? void 0 : options.chainId) || this.getChainId()]
|
|
3773
3779
|
}, options == null ? void 0 : options.chainId);
|
|
3774
|
-
return Array.isArray(res
|
|
3780
|
+
return Array.isArray(res) ? res[0] : res;
|
|
3775
3781
|
}
|
|
3776
3782
|
|
|
3777
3783
|
// NOTICE: We are leaving out all the "regular" methods os a tipical
|
|
@@ -650,11 +650,10 @@ class LocalStorage {
|
|
|
650
650
|
}
|
|
651
651
|
window.addEventListener('storage', e => {
|
|
652
652
|
const {
|
|
653
|
-
key
|
|
654
|
-
newValue
|
|
653
|
+
key
|
|
655
654
|
} = e;
|
|
656
655
|
const cb = this.callbacks.filter(c => c.key === key);
|
|
657
|
-
cb.forEach(c => c.cb(
|
|
656
|
+
cb.forEach(c => c.cb(this.getItem(key)));
|
|
658
657
|
});
|
|
659
658
|
}
|
|
660
659
|
getItem(key) {
|
|
@@ -662,9 +661,17 @@ class LocalStorage {
|
|
|
662
661
|
}
|
|
663
662
|
setItem(key, value) {
|
|
664
663
|
window.localStorage.setItem(key, value);
|
|
664
|
+
|
|
665
|
+
// Trigger callbacks
|
|
666
|
+
// NOTICE: the event is not triggered on the same window
|
|
667
|
+
this.callbacks.filter(c => c.key === key).forEach(c => c.cb(value));
|
|
665
668
|
}
|
|
666
669
|
removeItem(key) {
|
|
667
670
|
window.localStorage.removeItem(key);
|
|
671
|
+
|
|
672
|
+
// Trigger callbacks
|
|
673
|
+
// NOTICE: the event is not triggered on the same window
|
|
674
|
+
this.callbacks.filter(c => c.key === key).forEach(c => c.cb(null));
|
|
668
675
|
}
|
|
669
676
|
onItemChange(key, cb) {
|
|
670
677
|
this.callbacks.push({
|
|
@@ -3491,7 +3498,7 @@ class DefaultChainIdTracker {
|
|
|
3491
3498
|
this.callbacks = [];
|
|
3492
3499
|
this.store = store;
|
|
3493
3500
|
this.startingChainId = startingChainId;
|
|
3494
|
-
store.onItemChange(DefaultChainIdTracker.
|
|
3501
|
+
store.onItemChange(DefaultChainIdTracker.SESSION_CHAIN_ID_KEY, value => {
|
|
3495
3502
|
if (value) {
|
|
3496
3503
|
const chainId = parseInt(value);
|
|
3497
3504
|
this.callbacks.forEach(cb => cb(chainId));
|
|
@@ -3506,11 +3513,11 @@ class DefaultChainIdTracker {
|
|
|
3506
3513
|
}
|
|
3507
3514
|
setDefaultChainId(chainId) {
|
|
3508
3515
|
if (chainId !== this.getDefaultChainId()) {
|
|
3509
|
-
this.store.setItem(DefaultChainIdTracker.
|
|
3516
|
+
this.store.setItem(DefaultChainIdTracker.SESSION_CHAIN_ID_KEY, chainId.toString());
|
|
3510
3517
|
}
|
|
3511
3518
|
}
|
|
3512
3519
|
getDefaultChainId() {
|
|
3513
|
-
const read = this.store.getItem(DefaultChainIdTracker.
|
|
3520
|
+
const read = this.store.getItem(DefaultChainIdTracker.SESSION_CHAIN_ID_KEY);
|
|
3514
3521
|
if (!read || read.length === 0) {
|
|
3515
3522
|
return this.startingChainId;
|
|
3516
3523
|
}
|
|
@@ -3524,7 +3531,7 @@ class DefaultChainIdTracker {
|
|
|
3524
3531
|
*
|
|
3525
3532
|
* It doesn't implement a full ethereum Provider, it doesn't include read-only methods.
|
|
3526
3533
|
*/
|
|
3527
|
-
DefaultChainIdTracker.
|
|
3534
|
+
DefaultChainIdTracker.SESSION_CHAIN_ID_KEY = '@sequence.session.defaultChainId';
|
|
3528
3535
|
class SequenceClient {
|
|
3529
3536
|
constructor(transport, store, defaultChainId) {
|
|
3530
3537
|
this.callbacks = {};
|
|
@@ -3701,8 +3708,12 @@ class SequenceClient {
|
|
|
3701
3708
|
reject(error);
|
|
3702
3709
|
} else if (response === undefined) {
|
|
3703
3710
|
reject(new Error(`Got undefined response for request: ${request}`));
|
|
3711
|
+
} else if (typeof response === 'object' && response.error) {
|
|
3712
|
+
reject(response.error);
|
|
3713
|
+
} else if (typeof response === 'object' && response.result) {
|
|
3714
|
+
resolve(response.result);
|
|
3704
3715
|
} else {
|
|
3705
|
-
|
|
3716
|
+
reject(new Error(`Got invalid response for request: ${request}`));
|
|
3706
3717
|
}
|
|
3707
3718
|
}, chainId || this.getChainId());
|
|
3708
3719
|
});
|
|
@@ -3710,10 +3721,9 @@ class SequenceClient {
|
|
|
3710
3721
|
async getNetworks(pull) {
|
|
3711
3722
|
const connectedSession = this.session.connectedSession();
|
|
3712
3723
|
if (pull) {
|
|
3713
|
-
|
|
3724
|
+
connectedSession.networks = await this.send({
|
|
3714
3725
|
method: 'sequence_getNetworks'
|
|
3715
3726
|
});
|
|
3716
|
-
connectedSession.networks = nextNetworks.result;
|
|
3717
3727
|
this.session.setSession(connectedSession);
|
|
3718
3728
|
}
|
|
3719
3729
|
return connectedSession.networks;
|
|
@@ -3722,11 +3732,10 @@ class SequenceClient {
|
|
|
3722
3732
|
const method = options != null && options.eip6492 ? 'sequence_sign' : 'personal_sign';
|
|
3723
3733
|
|
|
3724
3734
|
// Address is ignored by the wallet webapp
|
|
3725
|
-
|
|
3735
|
+
return this.send({
|
|
3726
3736
|
method,
|
|
3727
3737
|
params: [message, this.getAddress()]
|
|
3728
3738
|
}, options == null ? void 0 : options.chainId);
|
|
3729
|
-
return res.result;
|
|
3730
3739
|
}
|
|
3731
3740
|
async signTypedData(typedData, options) {
|
|
3732
3741
|
const method = options != null && options.eip6492 ? 'sequence_signTypedData_v4' : 'eth_signTypedData_v4';
|
|
@@ -3740,26 +3749,23 @@ class SequenceClient {
|
|
|
3740
3749
|
// - The one provided in the typedData.domain.chainId
|
|
3741
3750
|
// - The default chainId
|
|
3742
3751
|
|
|
3743
|
-
|
|
3752
|
+
return this.send({
|
|
3744
3753
|
method,
|
|
3745
3754
|
params: [this.getAddress(), encoded]
|
|
3746
3755
|
}, (options == null ? void 0 : options.chainId) || typedData.domain.chainId && ethers.BigNumber.from(typedData.domain.chainId).toNumber() || this.getChainId());
|
|
3747
|
-
return res.result;
|
|
3748
3756
|
}
|
|
3749
3757
|
async sendTransaction(tx, options) {
|
|
3750
3758
|
const sequenceTxs = Array.isArray(tx) ? tx : [tx];
|
|
3751
3759
|
const extendedTxs = toExtended(sequenceTxs);
|
|
3752
|
-
|
|
3760
|
+
return this.send({
|
|
3753
3761
|
method: 'eth_sendTransaction',
|
|
3754
3762
|
params: [extendedTxs]
|
|
3755
3763
|
}, options == null ? void 0 : options.chainId);
|
|
3756
|
-
return res.result;
|
|
3757
3764
|
}
|
|
3758
3765
|
async getWalletContext() {
|
|
3759
|
-
|
|
3766
|
+
return this.send({
|
|
3760
3767
|
method: 'sequence_getWalletContext'
|
|
3761
3768
|
});
|
|
3762
|
-
return res.result;
|
|
3763
3769
|
}
|
|
3764
3770
|
async getOnchainWalletConfig(options) {
|
|
3765
3771
|
// NOTICE: sequence_getWalletConfig sends the chainId as a param
|
|
@@ -3767,7 +3773,7 @@ class SequenceClient {
|
|
|
3767
3773
|
method: 'sequence_getWalletConfig',
|
|
3768
3774
|
params: [(options == null ? void 0 : options.chainId) || this.getChainId()]
|
|
3769
3775
|
}, options == null ? void 0 : options.chainId);
|
|
3770
|
-
return Array.isArray(res
|
|
3776
|
+
return Array.isArray(res) ? res[0] : res;
|
|
3771
3777
|
}
|
|
3772
3778
|
|
|
3773
3779
|
// NOTICE: We are leaving out all the "regular" methods os a tipical
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { JsonRpcRequest,
|
|
1
|
+
import { JsonRpcRequest, NetworkConfig } from "@0xsequence/network";
|
|
2
2
|
import { ConnectDetails, ConnectOptions, ItemStore, MuxTransportTemplate, OpenWalletIntent, OptionalChainId, OptionalEIP6492, ProviderTransport, WalletSession } from "./index.js";
|
|
3
3
|
import { commons } from "@0xsequence/core";
|
|
4
4
|
import { TypedData } from "@0xsequence/utils";
|
|
@@ -34,7 +34,7 @@ export declare class SequenceClientSession {
|
|
|
34
34
|
export declare class DefaultChainIdTracker {
|
|
35
35
|
private store;
|
|
36
36
|
private startingChainId;
|
|
37
|
-
static readonly
|
|
37
|
+
static readonly SESSION_CHAIN_ID_KEY = "@sequence.session.defaultChainId";
|
|
38
38
|
callbacks: ((chainId: number) => void)[];
|
|
39
39
|
constructor(store: ItemStore, startingChainId?: number);
|
|
40
40
|
onDefaultChainIdChanged(callback: (chainId: number) => void): () => void;
|
|
@@ -70,7 +70,7 @@ export declare class SequenceClient {
|
|
|
70
70
|
getAddress(): string;
|
|
71
71
|
connect(options: ConnectOptions): Promise<ConnectDetails>;
|
|
72
72
|
disconnect(): Promise<void>;
|
|
73
|
-
send(request: JsonRpcRequest, chainId?: number): Promise<
|
|
73
|
+
send(request: JsonRpcRequest, chainId?: number): Promise<any>;
|
|
74
74
|
getNetworks(pull?: boolean): Promise<NetworkConfig[]>;
|
|
75
75
|
signMessage(message: ethers.BytesLike, options?: OptionalEIP6492 & OptionalChainId): Promise<string>;
|
|
76
76
|
signTypedData(typedData: TypedData, options?: OptionalEIP6492 & OptionalChainId): Promise<string>;
|
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-20230726193528",
|
|
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": "0.0.0-
|
|
15
|
-
"@0xsequence/
|
|
16
|
-
"@0xsequence/
|
|
17
|
-
"@0xsequence/
|
|
18
|
-
"@0xsequence/
|
|
19
|
-
"@0xsequence/network": "0.0.0-
|
|
20
|
-
"@0xsequence/
|
|
21
|
-
"@0xsequence/
|
|
22
|
-
"@0xsequence/
|
|
14
|
+
"@0xsequence/abi": "0.0.0-20230726193528",
|
|
15
|
+
"@0xsequence/account": "0.0.0-20230726193528",
|
|
16
|
+
"@0xsequence/migration": "0.0.0-20230726193528",
|
|
17
|
+
"@0xsequence/auth": "0.0.0-20230726193528",
|
|
18
|
+
"@0xsequence/core": "0.0.0-20230726193528",
|
|
19
|
+
"@0xsequence/network": "0.0.0-20230726193528",
|
|
20
|
+
"@0xsequence/relayer": "0.0.0-20230726193528",
|
|
21
|
+
"@0xsequence/utils": "0.0.0-20230726193528",
|
|
22
|
+
"@0xsequence/wallet": "0.0.0-20230726193528"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"ethers": ">=5.5 < 6"
|
package/src/client.ts
CHANGED
|
@@ -74,7 +74,7 @@ export class SequenceClientSession {
|
|
|
74
74
|
* track it locally using storage, that way the data stays always in sync.
|
|
75
75
|
*/
|
|
76
76
|
export class DefaultChainIdTracker {
|
|
77
|
-
static readonly
|
|
77
|
+
static readonly SESSION_CHAIN_ID_KEY = '@sequence.session.defaultChainId'
|
|
78
78
|
|
|
79
79
|
callbacks: ((chainId: number) => void)[] = []
|
|
80
80
|
|
|
@@ -82,7 +82,7 @@ export class DefaultChainIdTracker {
|
|
|
82
82
|
private store: ItemStore,
|
|
83
83
|
private startingChainId: number = 1
|
|
84
84
|
) {
|
|
85
|
-
store.onItemChange(DefaultChainIdTracker.
|
|
85
|
+
store.onItemChange(DefaultChainIdTracker.SESSION_CHAIN_ID_KEY, (value: string | null) => {
|
|
86
86
|
if (value) {
|
|
87
87
|
const chainId = parseInt(value)
|
|
88
88
|
this.callbacks.forEach(cb => cb(chainId))
|
|
@@ -99,12 +99,12 @@ export class DefaultChainIdTracker {
|
|
|
99
99
|
|
|
100
100
|
setDefaultChainId(chainId: number) {
|
|
101
101
|
if (chainId !== this.getDefaultChainId()) {
|
|
102
|
-
this.store.setItem(DefaultChainIdTracker.
|
|
102
|
+
this.store.setItem(DefaultChainIdTracker.SESSION_CHAIN_ID_KEY, chainId.toString())
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
getDefaultChainId(): number {
|
|
107
|
-
const read = this.store.getItem(DefaultChainIdTracker.
|
|
107
|
+
const read = this.store.getItem(DefaultChainIdTracker.SESSION_CHAIN_ID_KEY)
|
|
108
108
|
|
|
109
109
|
if (!read || read.length === 0) {
|
|
110
110
|
return this.startingChainId
|
|
@@ -312,15 +312,19 @@ export class SequenceClient {
|
|
|
312
312
|
|
|
313
313
|
// Working with sendAsync is less idiomatic
|
|
314
314
|
// but transport uses it instead of send, so we wrap it
|
|
315
|
-
send(request: JsonRpcRequest, chainId?: number): Promise<
|
|
315
|
+
send(request: JsonRpcRequest, chainId?: number): Promise<any> {
|
|
316
316
|
return new Promise((resolve, reject) => {
|
|
317
317
|
this.transport.sendAsync(request, (error, response) => {
|
|
318
318
|
if (error) {
|
|
319
319
|
reject(error)
|
|
320
320
|
} else if (response === undefined) {
|
|
321
321
|
reject(new Error(`Got undefined response for request: ${request}`))
|
|
322
|
+
} else if (typeof response === 'object' && response.error) {
|
|
323
|
+
reject(response.error)
|
|
324
|
+
} else if (typeof response === 'object' && response.result) {
|
|
325
|
+
resolve(response.result)
|
|
322
326
|
} else {
|
|
323
|
-
|
|
327
|
+
reject(new Error(`Got invalid response for request: ${request}`))
|
|
324
328
|
}
|
|
325
329
|
}, chainId || this.getChainId())
|
|
326
330
|
})
|
|
@@ -330,8 +334,7 @@ export class SequenceClient {
|
|
|
330
334
|
const connectedSession = this.session.connectedSession()
|
|
331
335
|
|
|
332
336
|
if (pull) {
|
|
333
|
-
|
|
334
|
-
connectedSession.networks = nextNetworks.result
|
|
337
|
+
connectedSession.networks = await this.send({ method: 'sequence_getNetworks' })
|
|
335
338
|
this.session.setSession(connectedSession)
|
|
336
339
|
}
|
|
337
340
|
|
|
@@ -345,8 +348,7 @@ export class SequenceClient {
|
|
|
345
348
|
const method = options?.eip6492 ? 'sequence_sign' : 'personal_sign'
|
|
346
349
|
|
|
347
350
|
// Address is ignored by the wallet webapp
|
|
348
|
-
|
|
349
|
-
return res.result
|
|
351
|
+
return this.send({ method, params: [message, this.getAddress()] }, options?.chainId)
|
|
350
352
|
}
|
|
351
353
|
|
|
352
354
|
async signTypedData(
|
|
@@ -364,7 +366,7 @@ export class SequenceClient {
|
|
|
364
366
|
// - The one provided in the typedData.domain.chainId
|
|
365
367
|
// - The default chainId
|
|
366
368
|
|
|
367
|
-
|
|
369
|
+
return this.send({ method, params: [this.getAddress(), encoded] }, (
|
|
368
370
|
options?.chainId ||
|
|
369
371
|
(
|
|
370
372
|
typedData.domain.chainId &&
|
|
@@ -372,7 +374,6 @@ export class SequenceClient {
|
|
|
372
374
|
) ||
|
|
373
375
|
this.getChainId()
|
|
374
376
|
))
|
|
375
|
-
return res.result
|
|
376
377
|
}
|
|
377
378
|
|
|
378
379
|
async sendTransaction(
|
|
@@ -385,19 +386,17 @@ export class SequenceClient {
|
|
|
385
386
|
const sequenceTxs = Array.isArray(tx) ? tx : [tx]
|
|
386
387
|
const extendedTxs = toExtended(sequenceTxs)
|
|
387
388
|
|
|
388
|
-
|
|
389
|
-
return res.result
|
|
389
|
+
return this.send({ method: 'eth_sendTransaction', params: [extendedTxs] }, options?.chainId )
|
|
390
390
|
}
|
|
391
391
|
|
|
392
392
|
async getWalletContext(): Promise<commons.context.VersionedContext> {
|
|
393
|
-
|
|
394
|
-
return res.result
|
|
393
|
+
return this.send({ method: 'sequence_getWalletContext' })
|
|
395
394
|
}
|
|
396
395
|
|
|
397
396
|
async getOnchainWalletConfig(options?: OptionalChainId): Promise<commons.config.Config> {
|
|
398
397
|
// NOTICE: sequence_getWalletConfig sends the chainId as a param
|
|
399
398
|
const res = await this.send({ method: 'sequence_getWalletConfig', params: [options?.chainId || this.getChainId()] }, options?.chainId)
|
|
400
|
-
return Array.isArray(res
|
|
399
|
+
return Array.isArray(res) ? res[0] : res
|
|
401
400
|
}
|
|
402
401
|
|
|
403
402
|
// NOTICE: We are leaving out all the "regular" methods os a tipical
|
package/src/utils.ts
CHANGED
|
@@ -158,9 +158,9 @@ export class LocalStorage implements ItemStore {
|
|
|
158
158
|
}
|
|
159
159
|
|
|
160
160
|
window.addEventListener('storage', (e) => {
|
|
161
|
-
const { key
|
|
161
|
+
const { key } = e
|
|
162
162
|
const cb = this.callbacks.filter((c) => c.key === key)
|
|
163
|
-
cb.forEach((c) => c.cb(
|
|
163
|
+
cb.forEach((c) => c.cb(this.getItem(key!)))
|
|
164
164
|
})
|
|
165
165
|
}
|
|
166
166
|
|
|
@@ -170,10 +170,18 @@ export class LocalStorage implements ItemStore {
|
|
|
170
170
|
|
|
171
171
|
setItem(key: string, value: string): void {
|
|
172
172
|
window.localStorage.setItem(key, value)
|
|
173
|
+
|
|
174
|
+
// Trigger callbacks
|
|
175
|
+
// NOTICE: the event is not triggered on the same window
|
|
176
|
+
this.callbacks.filter((c) => c.key === key).forEach((c) => c.cb(value))
|
|
173
177
|
}
|
|
174
178
|
|
|
175
179
|
removeItem(key: string): void {
|
|
176
180
|
window.localStorage.removeItem(key)
|
|
181
|
+
|
|
182
|
+
// Trigger callbacks
|
|
183
|
+
// NOTICE: the event is not triggered on the same window
|
|
184
|
+
this.callbacks.filter((c) => c.key === key).forEach((c) => c.cb(null))
|
|
177
185
|
}
|
|
178
186
|
|
|
179
187
|
onItemChange(key: string, cb: (value: string | null) => void): () => void {
|