@0xsequence/provider 1.1.8 → 1.1.10
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 +56 -7
- package/dist/0xsequence-provider.cjs.prod.js +56 -7
- package/dist/0xsequence-provider.esm.js +56 -7
- package/dist/declarations/src/client.d.ts +10 -2
- package/dist/declarations/src/init.d.ts +1 -0
- package/package.json +10 -10
- package/src/client.ts +68 -4
- package/src/init.ts +8 -2
|
@@ -3585,16 +3585,16 @@ class DefaultChainIdTracker {
|
|
|
3585
3585
|
return parseInt(read);
|
|
3586
3586
|
}
|
|
3587
3587
|
}
|
|
3588
|
-
|
|
3588
|
+
DefaultChainIdTracker.SESSION_CHAIN_ID_KEY = '@sequence.session.defaultChainId';
|
|
3589
3589
|
/**
|
|
3590
3590
|
* This is a wallet client for sequence wallet-webapp. It connects using *some* transport
|
|
3591
3591
|
* and it allows to perform all sequence specific (or write) operations related to the wallet.
|
|
3592
|
-
*
|
|
3592
|
+
*s
|
|
3593
3593
|
* It doesn't implement a full ethereum Provider, it doesn't include read-only methods.
|
|
3594
3594
|
*/
|
|
3595
|
-
DefaultChainIdTracker.SESSION_CHAIN_ID_KEY = '@sequence.session.defaultChainId';
|
|
3596
3595
|
class SequenceClient {
|
|
3597
|
-
constructor(transport, store,
|
|
3596
|
+
constructor(transport, store, options) {
|
|
3597
|
+
var _options$defaultEIP;
|
|
3598
3598
|
this.callbacks = {};
|
|
3599
3599
|
if (isMuxTransportTemplate(transport)) {
|
|
3600
3600
|
this.transport = MuxMessageProvider.new(transport);
|
|
@@ -3603,6 +3603,8 @@ class SequenceClient {
|
|
|
3603
3603
|
} else {
|
|
3604
3604
|
throw new Error('Invalid transport');
|
|
3605
3605
|
}
|
|
3606
|
+
const defaultChainId = typeof options === 'number' ? options : options == null ? void 0 : options.defaultChainId;
|
|
3607
|
+
this.defaultEIP6492 = typeof options === 'number' ? false : (_options$defaultEIP = options == null ? void 0 : options.defaultEIP6492) != null ? _options$defaultEIP : false;
|
|
3606
3608
|
this.session = new SequenceClientSession(store);
|
|
3607
3609
|
this.defaultChainId = new DefaultChainIdTracker(store, defaultChainId);
|
|
3608
3610
|
this.transport.on('accountsChanged', accounts => {
|
|
@@ -3786,6 +3788,10 @@ class SequenceClient {
|
|
|
3786
3788
|
// Working with sendAsync is less idiomatic
|
|
3787
3789
|
// but transport uses it instead of send, so we wrap it
|
|
3788
3790
|
send(request, chainId) {
|
|
3791
|
+
// Internally when sending requests we use `legacy_sign`
|
|
3792
|
+
// to avoid the default EIP6492 behavior overriding an explicit
|
|
3793
|
+
// "legacy sign" request, so we map the method here.
|
|
3794
|
+
request.method = this.mapSignMethod(request.method);
|
|
3789
3795
|
return new Promise((resolve, reject) => {
|
|
3790
3796
|
this.transport.sendAsync(request, (error, response) => {
|
|
3791
3797
|
if (error) {
|
|
@@ -3812,8 +3818,48 @@ class SequenceClient {
|
|
|
3812
3818
|
}
|
|
3813
3819
|
return connectedSession.networks;
|
|
3814
3820
|
}
|
|
3821
|
+
|
|
3822
|
+
// NOTICE: `legacy_sign` will get overriden by `send`
|
|
3823
|
+
// it is done this way to ensure that:
|
|
3824
|
+
// - `send` handles `personal_sign` as a request for the default sign method
|
|
3825
|
+
// - explicit `personal_sign` is not replaced by `sequence_sign` (if default is EI6492)
|
|
3826
|
+
signMethod(options) {
|
|
3827
|
+
if ((options == null ? void 0 : options.eip6492) === undefined) {
|
|
3828
|
+
return 'personal_sign';
|
|
3829
|
+
}
|
|
3830
|
+
return options.eip6492 ? 'sequence_sign' : 'legacy_sign';
|
|
3831
|
+
}
|
|
3832
|
+
signTypedDataMethod(options) {
|
|
3833
|
+
if ((options == null ? void 0 : options.eip6492) === undefined) {
|
|
3834
|
+
return 'eth_signTypedData_v4';
|
|
3835
|
+
}
|
|
3836
|
+
return options.eip6492 ? 'sequence_signTypedData_v4' : 'legacy_signTypedData_v4';
|
|
3837
|
+
}
|
|
3838
|
+
mapSignMethod(method) {
|
|
3839
|
+
if (method === 'personal_sign') {
|
|
3840
|
+
if (this.defaultEIP6492) {
|
|
3841
|
+
return 'sequence_sign';
|
|
3842
|
+
} else {
|
|
3843
|
+
return 'personal_sign';
|
|
3844
|
+
}
|
|
3845
|
+
}
|
|
3846
|
+
if (method === 'eth_signTypedData_v4') {
|
|
3847
|
+
if (this.defaultEIP6492) {
|
|
3848
|
+
return 'sequence_signTypedData_v4';
|
|
3849
|
+
} else {
|
|
3850
|
+
return 'eth_signTypedData_v4';
|
|
3851
|
+
}
|
|
3852
|
+
}
|
|
3853
|
+
if (method === 'legacy_sign') {
|
|
3854
|
+
return 'personal_sign';
|
|
3855
|
+
}
|
|
3856
|
+
if (method === 'legacy_signTypedData_v4') {
|
|
3857
|
+
return 'eth_signTypedData_v4';
|
|
3858
|
+
}
|
|
3859
|
+
return method;
|
|
3860
|
+
}
|
|
3815
3861
|
async signMessage(message, options) {
|
|
3816
|
-
const method = options
|
|
3862
|
+
const method = this.signMethod(options);
|
|
3817
3863
|
|
|
3818
3864
|
// Address is ignored by the wallet webapp
|
|
3819
3865
|
return this.send({
|
|
@@ -3822,7 +3868,7 @@ class SequenceClient {
|
|
|
3822
3868
|
}, options == null ? void 0 : options.chainId);
|
|
3823
3869
|
}
|
|
3824
3870
|
async signTypedData(typedData, options) {
|
|
3825
|
-
const method = options
|
|
3871
|
+
const method = this.signTypedDataMethod(options);
|
|
3826
3872
|
|
|
3827
3873
|
// TODO: Stop using ethers for this, this is the only place where we use it
|
|
3828
3874
|
// and it makes the client depend on ethers.
|
|
@@ -3932,7 +3978,10 @@ const initWallet = partialConfig => {
|
|
|
3932
3978
|
const itemStore = config.localStorage || useBestStore();
|
|
3933
3979
|
|
|
3934
3980
|
// Create client, provider and return signer
|
|
3935
|
-
const client = new SequenceClient(config.transports, itemStore,
|
|
3981
|
+
const client = new SequenceClient(config.transports, itemStore, {
|
|
3982
|
+
defaultChainId: defaultNetwork,
|
|
3983
|
+
defaultEIP6492: config.defaultEIP6492
|
|
3984
|
+
});
|
|
3936
3985
|
sequenceWalletProvider = new SequenceProvider(client, providerForChainId);
|
|
3937
3986
|
return sequenceWalletProvider;
|
|
3938
3987
|
};
|
|
@@ -3585,16 +3585,16 @@ class DefaultChainIdTracker {
|
|
|
3585
3585
|
return parseInt(read);
|
|
3586
3586
|
}
|
|
3587
3587
|
}
|
|
3588
|
-
|
|
3588
|
+
DefaultChainIdTracker.SESSION_CHAIN_ID_KEY = '@sequence.session.defaultChainId';
|
|
3589
3589
|
/**
|
|
3590
3590
|
* This is a wallet client for sequence wallet-webapp. It connects using *some* transport
|
|
3591
3591
|
* and it allows to perform all sequence specific (or write) operations related to the wallet.
|
|
3592
|
-
*
|
|
3592
|
+
*s
|
|
3593
3593
|
* It doesn't implement a full ethereum Provider, it doesn't include read-only methods.
|
|
3594
3594
|
*/
|
|
3595
|
-
DefaultChainIdTracker.SESSION_CHAIN_ID_KEY = '@sequence.session.defaultChainId';
|
|
3596
3595
|
class SequenceClient {
|
|
3597
|
-
constructor(transport, store,
|
|
3596
|
+
constructor(transport, store, options) {
|
|
3597
|
+
var _options$defaultEIP;
|
|
3598
3598
|
this.callbacks = {};
|
|
3599
3599
|
if (isMuxTransportTemplate(transport)) {
|
|
3600
3600
|
this.transport = MuxMessageProvider.new(transport);
|
|
@@ -3603,6 +3603,8 @@ class SequenceClient {
|
|
|
3603
3603
|
} else {
|
|
3604
3604
|
throw new Error('Invalid transport');
|
|
3605
3605
|
}
|
|
3606
|
+
const defaultChainId = typeof options === 'number' ? options : options == null ? void 0 : options.defaultChainId;
|
|
3607
|
+
this.defaultEIP6492 = typeof options === 'number' ? false : (_options$defaultEIP = options == null ? void 0 : options.defaultEIP6492) != null ? _options$defaultEIP : false;
|
|
3606
3608
|
this.session = new SequenceClientSession(store);
|
|
3607
3609
|
this.defaultChainId = new DefaultChainIdTracker(store, defaultChainId);
|
|
3608
3610
|
this.transport.on('accountsChanged', accounts => {
|
|
@@ -3786,6 +3788,10 @@ class SequenceClient {
|
|
|
3786
3788
|
// Working with sendAsync is less idiomatic
|
|
3787
3789
|
// but transport uses it instead of send, so we wrap it
|
|
3788
3790
|
send(request, chainId) {
|
|
3791
|
+
// Internally when sending requests we use `legacy_sign`
|
|
3792
|
+
// to avoid the default EIP6492 behavior overriding an explicit
|
|
3793
|
+
// "legacy sign" request, so we map the method here.
|
|
3794
|
+
request.method = this.mapSignMethod(request.method);
|
|
3789
3795
|
return new Promise((resolve, reject) => {
|
|
3790
3796
|
this.transport.sendAsync(request, (error, response) => {
|
|
3791
3797
|
if (error) {
|
|
@@ -3812,8 +3818,48 @@ class SequenceClient {
|
|
|
3812
3818
|
}
|
|
3813
3819
|
return connectedSession.networks;
|
|
3814
3820
|
}
|
|
3821
|
+
|
|
3822
|
+
// NOTICE: `legacy_sign` will get overriden by `send`
|
|
3823
|
+
// it is done this way to ensure that:
|
|
3824
|
+
// - `send` handles `personal_sign` as a request for the default sign method
|
|
3825
|
+
// - explicit `personal_sign` is not replaced by `sequence_sign` (if default is EI6492)
|
|
3826
|
+
signMethod(options) {
|
|
3827
|
+
if ((options == null ? void 0 : options.eip6492) === undefined) {
|
|
3828
|
+
return 'personal_sign';
|
|
3829
|
+
}
|
|
3830
|
+
return options.eip6492 ? 'sequence_sign' : 'legacy_sign';
|
|
3831
|
+
}
|
|
3832
|
+
signTypedDataMethod(options) {
|
|
3833
|
+
if ((options == null ? void 0 : options.eip6492) === undefined) {
|
|
3834
|
+
return 'eth_signTypedData_v4';
|
|
3835
|
+
}
|
|
3836
|
+
return options.eip6492 ? 'sequence_signTypedData_v4' : 'legacy_signTypedData_v4';
|
|
3837
|
+
}
|
|
3838
|
+
mapSignMethod(method) {
|
|
3839
|
+
if (method === 'personal_sign') {
|
|
3840
|
+
if (this.defaultEIP6492) {
|
|
3841
|
+
return 'sequence_sign';
|
|
3842
|
+
} else {
|
|
3843
|
+
return 'personal_sign';
|
|
3844
|
+
}
|
|
3845
|
+
}
|
|
3846
|
+
if (method === 'eth_signTypedData_v4') {
|
|
3847
|
+
if (this.defaultEIP6492) {
|
|
3848
|
+
return 'sequence_signTypedData_v4';
|
|
3849
|
+
} else {
|
|
3850
|
+
return 'eth_signTypedData_v4';
|
|
3851
|
+
}
|
|
3852
|
+
}
|
|
3853
|
+
if (method === 'legacy_sign') {
|
|
3854
|
+
return 'personal_sign';
|
|
3855
|
+
}
|
|
3856
|
+
if (method === 'legacy_signTypedData_v4') {
|
|
3857
|
+
return 'eth_signTypedData_v4';
|
|
3858
|
+
}
|
|
3859
|
+
return method;
|
|
3860
|
+
}
|
|
3815
3861
|
async signMessage(message, options) {
|
|
3816
|
-
const method = options
|
|
3862
|
+
const method = this.signMethod(options);
|
|
3817
3863
|
|
|
3818
3864
|
// Address is ignored by the wallet webapp
|
|
3819
3865
|
return this.send({
|
|
@@ -3822,7 +3868,7 @@ class SequenceClient {
|
|
|
3822
3868
|
}, options == null ? void 0 : options.chainId);
|
|
3823
3869
|
}
|
|
3824
3870
|
async signTypedData(typedData, options) {
|
|
3825
|
-
const method = options
|
|
3871
|
+
const method = this.signTypedDataMethod(options);
|
|
3826
3872
|
|
|
3827
3873
|
// TODO: Stop using ethers for this, this is the only place where we use it
|
|
3828
3874
|
// and it makes the client depend on ethers.
|
|
@@ -3932,7 +3978,10 @@ const initWallet = partialConfig => {
|
|
|
3932
3978
|
const itemStore = config.localStorage || useBestStore();
|
|
3933
3979
|
|
|
3934
3980
|
// Create client, provider and return signer
|
|
3935
|
-
const client = new SequenceClient(config.transports, itemStore,
|
|
3981
|
+
const client = new SequenceClient(config.transports, itemStore, {
|
|
3982
|
+
defaultChainId: defaultNetwork,
|
|
3983
|
+
defaultEIP6492: config.defaultEIP6492
|
|
3984
|
+
});
|
|
3936
3985
|
sequenceWalletProvider = new SequenceProvider(client, providerForChainId);
|
|
3937
3986
|
return sequenceWalletProvider;
|
|
3938
3987
|
};
|
|
@@ -3581,16 +3581,16 @@ class DefaultChainIdTracker {
|
|
|
3581
3581
|
return parseInt(read);
|
|
3582
3582
|
}
|
|
3583
3583
|
}
|
|
3584
|
-
|
|
3584
|
+
DefaultChainIdTracker.SESSION_CHAIN_ID_KEY = '@sequence.session.defaultChainId';
|
|
3585
3585
|
/**
|
|
3586
3586
|
* This is a wallet client for sequence wallet-webapp. It connects using *some* transport
|
|
3587
3587
|
* and it allows to perform all sequence specific (or write) operations related to the wallet.
|
|
3588
|
-
*
|
|
3588
|
+
*s
|
|
3589
3589
|
* It doesn't implement a full ethereum Provider, it doesn't include read-only methods.
|
|
3590
3590
|
*/
|
|
3591
|
-
DefaultChainIdTracker.SESSION_CHAIN_ID_KEY = '@sequence.session.defaultChainId';
|
|
3592
3591
|
class SequenceClient {
|
|
3593
|
-
constructor(transport, store,
|
|
3592
|
+
constructor(transport, store, options) {
|
|
3593
|
+
var _options$defaultEIP;
|
|
3594
3594
|
this.callbacks = {};
|
|
3595
3595
|
if (isMuxTransportTemplate(transport)) {
|
|
3596
3596
|
this.transport = MuxMessageProvider.new(transport);
|
|
@@ -3599,6 +3599,8 @@ class SequenceClient {
|
|
|
3599
3599
|
} else {
|
|
3600
3600
|
throw new Error('Invalid transport');
|
|
3601
3601
|
}
|
|
3602
|
+
const defaultChainId = typeof options === 'number' ? options : options == null ? void 0 : options.defaultChainId;
|
|
3603
|
+
this.defaultEIP6492 = typeof options === 'number' ? false : (_options$defaultEIP = options == null ? void 0 : options.defaultEIP6492) != null ? _options$defaultEIP : false;
|
|
3602
3604
|
this.session = new SequenceClientSession(store);
|
|
3603
3605
|
this.defaultChainId = new DefaultChainIdTracker(store, defaultChainId);
|
|
3604
3606
|
this.transport.on('accountsChanged', accounts => {
|
|
@@ -3782,6 +3784,10 @@ class SequenceClient {
|
|
|
3782
3784
|
// Working with sendAsync is less idiomatic
|
|
3783
3785
|
// but transport uses it instead of send, so we wrap it
|
|
3784
3786
|
send(request, chainId) {
|
|
3787
|
+
// Internally when sending requests we use `legacy_sign`
|
|
3788
|
+
// to avoid the default EIP6492 behavior overriding an explicit
|
|
3789
|
+
// "legacy sign" request, so we map the method here.
|
|
3790
|
+
request.method = this.mapSignMethod(request.method);
|
|
3785
3791
|
return new Promise((resolve, reject) => {
|
|
3786
3792
|
this.transport.sendAsync(request, (error, response) => {
|
|
3787
3793
|
if (error) {
|
|
@@ -3808,8 +3814,48 @@ class SequenceClient {
|
|
|
3808
3814
|
}
|
|
3809
3815
|
return connectedSession.networks;
|
|
3810
3816
|
}
|
|
3817
|
+
|
|
3818
|
+
// NOTICE: `legacy_sign` will get overriden by `send`
|
|
3819
|
+
// it is done this way to ensure that:
|
|
3820
|
+
// - `send` handles `personal_sign` as a request for the default sign method
|
|
3821
|
+
// - explicit `personal_sign` is not replaced by `sequence_sign` (if default is EI6492)
|
|
3822
|
+
signMethod(options) {
|
|
3823
|
+
if ((options == null ? void 0 : options.eip6492) === undefined) {
|
|
3824
|
+
return 'personal_sign';
|
|
3825
|
+
}
|
|
3826
|
+
return options.eip6492 ? 'sequence_sign' : 'legacy_sign';
|
|
3827
|
+
}
|
|
3828
|
+
signTypedDataMethod(options) {
|
|
3829
|
+
if ((options == null ? void 0 : options.eip6492) === undefined) {
|
|
3830
|
+
return 'eth_signTypedData_v4';
|
|
3831
|
+
}
|
|
3832
|
+
return options.eip6492 ? 'sequence_signTypedData_v4' : 'legacy_signTypedData_v4';
|
|
3833
|
+
}
|
|
3834
|
+
mapSignMethod(method) {
|
|
3835
|
+
if (method === 'personal_sign') {
|
|
3836
|
+
if (this.defaultEIP6492) {
|
|
3837
|
+
return 'sequence_sign';
|
|
3838
|
+
} else {
|
|
3839
|
+
return 'personal_sign';
|
|
3840
|
+
}
|
|
3841
|
+
}
|
|
3842
|
+
if (method === 'eth_signTypedData_v4') {
|
|
3843
|
+
if (this.defaultEIP6492) {
|
|
3844
|
+
return 'sequence_signTypedData_v4';
|
|
3845
|
+
} else {
|
|
3846
|
+
return 'eth_signTypedData_v4';
|
|
3847
|
+
}
|
|
3848
|
+
}
|
|
3849
|
+
if (method === 'legacy_sign') {
|
|
3850
|
+
return 'personal_sign';
|
|
3851
|
+
}
|
|
3852
|
+
if (method === 'legacy_signTypedData_v4') {
|
|
3853
|
+
return 'eth_signTypedData_v4';
|
|
3854
|
+
}
|
|
3855
|
+
return method;
|
|
3856
|
+
}
|
|
3811
3857
|
async signMessage(message, options) {
|
|
3812
|
-
const method = options
|
|
3858
|
+
const method = this.signMethod(options);
|
|
3813
3859
|
|
|
3814
3860
|
// Address is ignored by the wallet webapp
|
|
3815
3861
|
return this.send({
|
|
@@ -3818,7 +3864,7 @@ class SequenceClient {
|
|
|
3818
3864
|
}, options == null ? void 0 : options.chainId);
|
|
3819
3865
|
}
|
|
3820
3866
|
async signTypedData(typedData, options) {
|
|
3821
|
-
const method = options
|
|
3867
|
+
const method = this.signTypedDataMethod(options);
|
|
3822
3868
|
|
|
3823
3869
|
// TODO: Stop using ethers for this, this is the only place where we use it
|
|
3824
3870
|
// and it makes the client depend on ethers.
|
|
@@ -3928,7 +3974,10 @@ const initWallet = partialConfig => {
|
|
|
3928
3974
|
const itemStore = config.localStorage || useBestStore();
|
|
3929
3975
|
|
|
3930
3976
|
// Create client, provider and return signer
|
|
3931
|
-
const client = new SequenceClient(config.transports, itemStore,
|
|
3977
|
+
const client = new SequenceClient(config.transports, itemStore, {
|
|
3978
|
+
defaultChainId: defaultNetwork,
|
|
3979
|
+
defaultEIP6492: config.defaultEIP6492
|
|
3980
|
+
});
|
|
3932
3981
|
sequenceWalletProvider = new SequenceProvider(client, providerForChainId);
|
|
3933
3982
|
return sequenceWalletProvider;
|
|
3934
3983
|
};
|
|
@@ -33,10 +33,14 @@ export declare class DefaultChainIdTracker {
|
|
|
33
33
|
setDefaultChainId(chainId: number): void;
|
|
34
34
|
getDefaultChainId(): number;
|
|
35
35
|
}
|
|
36
|
+
export type SequenceClientOptions = {
|
|
37
|
+
defaultChainId?: number;
|
|
38
|
+
defaultEIP6492?: boolean;
|
|
39
|
+
};
|
|
36
40
|
/**
|
|
37
41
|
* This is a wallet client for sequence wallet-webapp. It connects using *some* transport
|
|
38
42
|
* and it allows to perform all sequence specific (or write) operations related to the wallet.
|
|
39
|
-
*
|
|
43
|
+
*s
|
|
40
44
|
* It doesn't implement a full ethereum Provider, it doesn't include read-only methods.
|
|
41
45
|
*/
|
|
42
46
|
export declare class SequenceClient {
|
|
@@ -44,7 +48,8 @@ export declare class SequenceClient {
|
|
|
44
48
|
private readonly defaultChainId;
|
|
45
49
|
private readonly callbacks;
|
|
46
50
|
readonly transport: ProviderTransport;
|
|
47
|
-
|
|
51
|
+
readonly defaultEIP6492: boolean;
|
|
52
|
+
constructor(transport: ProviderTransport | MuxTransportTemplate, store: ItemStore, options?: SequenceClientOptions | number);
|
|
48
53
|
registerCallback<K extends keyof WalletEventTypes>(eventName: K, callback: WalletEventTypes[K]): () => void;
|
|
49
54
|
onOpen(callback: WalletEventTypes['open']): () => void;
|
|
50
55
|
onClose(callback: WalletEventTypes['close']): () => void;
|
|
@@ -66,6 +71,9 @@ export declare class SequenceClient {
|
|
|
66
71
|
disconnect(): Promise<void>;
|
|
67
72
|
send(request: JsonRpcRequest, chainId?: number): Promise<any>;
|
|
68
73
|
getNetworks(pull?: boolean): Promise<NetworkConfig[]>;
|
|
74
|
+
private signMethod;
|
|
75
|
+
private signTypedDataMethod;
|
|
76
|
+
private mapSignMethod;
|
|
69
77
|
signMessage(message: ethers.BytesLike, options?: OptionalEIP6492 & OptionalChainId): Promise<string>;
|
|
70
78
|
signTypedData(typedData: TypedData, options?: OptionalEIP6492 & OptionalChainId): Promise<string>;
|
|
71
79
|
sendTransaction(tx: ethers.providers.TransactionRequest[] | ethers.providers.TransactionRequest, options?: OptionalChainId): Promise<string>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0xsequence/provider",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.10",
|
|
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.1.
|
|
15
|
-
"@0xsequence/
|
|
16
|
-
"@0xsequence/
|
|
17
|
-
"@0xsequence/migration": "1.1.
|
|
18
|
-
"@0xsequence/
|
|
19
|
-
"@0xsequence/network": "1.1.
|
|
20
|
-
"@0xsequence/relayer": "1.1.
|
|
21
|
-
"@0xsequence/utils": "1.1.
|
|
22
|
-
"@0xsequence/wallet": "1.1.
|
|
14
|
+
"@0xsequence/abi": "1.1.10",
|
|
15
|
+
"@0xsequence/auth": "1.1.10",
|
|
16
|
+
"@0xsequence/core": "1.1.10",
|
|
17
|
+
"@0xsequence/migration": "1.1.10",
|
|
18
|
+
"@0xsequence/account": "1.1.10",
|
|
19
|
+
"@0xsequence/network": "1.1.10",
|
|
20
|
+
"@0xsequence/relayer": "1.1.10",
|
|
21
|
+
"@0xsequence/utils": "1.1.10",
|
|
22
|
+
"@0xsequence/wallet": "1.1.10"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"ethers": ">=5.5 < 6"
|
package/src/client.ts
CHANGED
|
@@ -112,10 +112,15 @@ export class DefaultChainIdTracker {
|
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
+
export type SequenceClientOptions = {
|
|
116
|
+
defaultChainId?: number
|
|
117
|
+
defaultEIP6492?: boolean
|
|
118
|
+
}
|
|
119
|
+
|
|
115
120
|
/**
|
|
116
121
|
* This is a wallet client for sequence wallet-webapp. It connects using *some* transport
|
|
117
122
|
* and it allows to perform all sequence specific (or write) operations related to the wallet.
|
|
118
|
-
*
|
|
123
|
+
*s
|
|
119
124
|
* It doesn't implement a full ethereum Provider, it doesn't include read-only methods.
|
|
120
125
|
*/
|
|
121
126
|
export class SequenceClient {
|
|
@@ -125,7 +130,9 @@ export class SequenceClient {
|
|
|
125
130
|
|
|
126
131
|
public readonly transport: ProviderTransport
|
|
127
132
|
|
|
128
|
-
|
|
133
|
+
public readonly defaultEIP6492: boolean
|
|
134
|
+
|
|
135
|
+
constructor(transport: ProviderTransport | MuxTransportTemplate, store: ItemStore, options?: SequenceClientOptions | number) {
|
|
129
136
|
if (isMuxTransportTemplate(transport)) {
|
|
130
137
|
this.transport = MuxMessageProvider.new(transport)
|
|
131
138
|
} else if (isProviderTransport(transport)) {
|
|
@@ -134,6 +141,9 @@ export class SequenceClient {
|
|
|
134
141
|
throw new Error('Invalid transport')
|
|
135
142
|
}
|
|
136
143
|
|
|
144
|
+
const defaultChainId = typeof options === 'number' ? options : options?.defaultChainId
|
|
145
|
+
this.defaultEIP6492 = typeof options === 'number' ? false : options?.defaultEIP6492 ?? false
|
|
146
|
+
|
|
137
147
|
this.session = new SequenceClientSession(store)
|
|
138
148
|
this.defaultChainId = new DefaultChainIdTracker(store, defaultChainId)
|
|
139
149
|
|
|
@@ -334,6 +344,12 @@ export class SequenceClient {
|
|
|
334
344
|
// Working with sendAsync is less idiomatic
|
|
335
345
|
// but transport uses it instead of send, so we wrap it
|
|
336
346
|
send(request: JsonRpcRequest, chainId?: number): Promise<any> {
|
|
347
|
+
|
|
348
|
+
// Internally when sending requests we use `legacy_sign`
|
|
349
|
+
// to avoid the default EIP6492 behavior overriding an explicit
|
|
350
|
+
// "legacy sign" request, so we map the method here.
|
|
351
|
+
request.method = this.mapSignMethod(request.method)
|
|
352
|
+
|
|
337
353
|
return new Promise((resolve, reject) => {
|
|
338
354
|
this.transport.sendAsync(
|
|
339
355
|
request,
|
|
@@ -366,15 +382,63 @@ export class SequenceClient {
|
|
|
366
382
|
return connectedSession.networks
|
|
367
383
|
}
|
|
368
384
|
|
|
385
|
+
// NOTICE: `legacy_sign` will get overriden by `send`
|
|
386
|
+
// it is done this way to ensure that:
|
|
387
|
+
// - `send` handles `personal_sign` as a request for the default sign method
|
|
388
|
+
// - explicit `personal_sign` is not replaced by `sequence_sign` (if default is EI6492)
|
|
389
|
+
private signMethod(options?: OptionalEIP6492) {
|
|
390
|
+
if (options?.eip6492 === undefined) {
|
|
391
|
+
return 'personal_sign'
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
return options.eip6492 ? 'sequence_sign' : 'legacy_sign'
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
private signTypedDataMethod(options?: OptionalEIP6492) {
|
|
398
|
+
if (options?.eip6492 === undefined) {
|
|
399
|
+
return 'eth_signTypedData_v4'
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
return options.eip6492 ? 'sequence_signTypedData_v4' : 'legacy_signTypedData_v4'
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
private mapSignMethod(method: string): string {
|
|
406
|
+
if (method === 'personal_sign') {
|
|
407
|
+
if (this.defaultEIP6492) {
|
|
408
|
+
return 'sequence_sign'
|
|
409
|
+
} else {
|
|
410
|
+
return 'personal_sign'
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
if (method === 'eth_signTypedData_v4') {
|
|
415
|
+
if (this.defaultEIP6492) {
|
|
416
|
+
return 'sequence_signTypedData_v4'
|
|
417
|
+
} else {
|
|
418
|
+
return 'eth_signTypedData_v4'
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
if (method === 'legacy_sign') {
|
|
423
|
+
return 'personal_sign'
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
if (method === 'legacy_signTypedData_v4') {
|
|
427
|
+
return 'eth_signTypedData_v4'
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
return method
|
|
431
|
+
}
|
|
432
|
+
|
|
369
433
|
async signMessage(message: ethers.BytesLike, options?: OptionalEIP6492 & OptionalChainId): Promise<string> {
|
|
370
|
-
const method = options
|
|
434
|
+
const method = this.signMethod(options)
|
|
371
435
|
|
|
372
436
|
// Address is ignored by the wallet webapp
|
|
373
437
|
return this.send({ method, params: [message, this.getAddress()] }, options?.chainId)
|
|
374
438
|
}
|
|
375
439
|
|
|
376
440
|
async signTypedData(typedData: TypedData, options?: OptionalEIP6492 & OptionalChainId): Promise<string> {
|
|
377
|
-
const method = options
|
|
441
|
+
const method = this.signTypedDataMethod(options)
|
|
378
442
|
|
|
379
443
|
// TODO: Stop using ethers for this, this is the only place where we use it
|
|
380
444
|
// and it makes the client depend on ethers.
|
package/src/init.ts
CHANGED
|
@@ -26,6 +26,9 @@ export interface ProviderConfig {
|
|
|
26
26
|
// need to match
|
|
27
27
|
defaultNetwork?: ChainIdLike
|
|
28
28
|
|
|
29
|
+
// defaultEIP6492 defines if EIP-6492 is enabled by default when signing messages.
|
|
30
|
+
defaultEIP6492?: boolean
|
|
31
|
+
|
|
29
32
|
// networks is a configuration list of networks used by the wallet. This list
|
|
30
33
|
// is combined with the network list specified by sequence.js.
|
|
31
34
|
// notice that this can only replace the rpc urls on the dapp side,
|
|
@@ -115,9 +118,12 @@ export const initWallet = (partialConfig?: Partial<ProviderConfig>) => {
|
|
|
115
118
|
const itemStore = config.localStorage || useBestStore()
|
|
116
119
|
|
|
117
120
|
// Create client, provider and return signer
|
|
118
|
-
const client = new SequenceClient(config.transports, itemStore,
|
|
119
|
-
|
|
121
|
+
const client = new SequenceClient(config.transports, itemStore, {
|
|
122
|
+
defaultChainId: defaultNetwork,
|
|
123
|
+
defaultEIP6492: config.defaultEIP6492
|
|
124
|
+
})
|
|
120
125
|
|
|
126
|
+
sequenceWalletProvider = new SequenceProvider(client, providerForChainId)
|
|
121
127
|
return sequenceWalletProvider
|
|
122
128
|
}
|
|
123
129
|
|