@0xsequence/provider 0.0.0-20230321200348 → 0.0.0-20230327140007

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.
@@ -1774,19 +1774,23 @@ class WalletRequestHandler {
1774
1774
  // fetch the provider for the specific chain, or undefined will select defaultChain
1775
1775
  const provider = (_this$account = _this.account) == null ? void 0 : _this$account.provider(chainId != null ? chainId : _this.defaultNetworkId);
1776
1776
  if (!provider) throw new Error(`WalletRequestHandler: wallet provider is not configured for chainId ${chainId}`);
1777
- if (provider.send === undefined) {
1778
- throw new Error(`Account provider doesn't support send method`);
1779
- }
1777
+ const jsonRpcProvider = provider instanceof ethers.ethers.providers.JsonRpcProvider ? provider : undefined;
1780
1778
  switch (request.method) {
1781
1779
  case 'net_version':
1782
1780
  {
1783
- const result = await provider.send('net_version', []);
1781
+ if (!jsonRpcProvider) {
1782
+ throw new Error(`Account provider doesn't support send method`);
1783
+ }
1784
+ const result = await jsonRpcProvider.send('net_version', []);
1784
1785
  response.result = result;
1785
1786
  break;
1786
1787
  }
1787
1788
  case 'eth_chainId':
1788
1789
  {
1789
- const result = await provider.send('eth_chainId', []);
1790
+ if (!jsonRpcProvider) {
1791
+ throw new Error(`Account provider doesn't support send method`);
1792
+ }
1793
+ const result = await jsonRpcProvider.send('eth_chainId', []);
1790
1794
  response.result = result;
1791
1795
  break;
1792
1796
  }
@@ -1803,6 +1807,7 @@ class WalletRequestHandler {
1803
1807
  response.result = walletBalance.toHexString();
1804
1808
  break;
1805
1809
  }
1810
+ case 'sequence_sign':
1806
1811
  case 'personal_sign':
1807
1812
  case 'eth_sign':
1808
1813
  {
@@ -1810,14 +1815,22 @@ class WalletRequestHandler {
1810
1815
  let message;
1811
1816
 
1812
1817
  // there is a difference in the order of the params:
1813
- // personal_sign: [data, address]
1818
+ // sequence_sign, personal_sign: [data, address]
1814
1819
  // eth_sign: [address, data]
1815
- if (request.method === 'personal_sign') {
1816
- const [data, address] = request.params;
1817
- message = data;
1818
- } else {
1819
- const [address, data] = request.params;
1820
- message = data;
1820
+ switch (request.method) {
1821
+ case 'sequence_sign':
1822
+ case 'personal_sign':
1823
+ {
1824
+ const [data, _address] = request.params;
1825
+ message = data;
1826
+ break;
1827
+ }
1828
+ case 'eth_sign':
1829
+ {
1830
+ const [_address, data] = request.params;
1831
+ message = data;
1832
+ break;
1833
+ }
1821
1834
  }
1822
1835
  let sig = '';
1823
1836
 
@@ -1831,7 +1844,7 @@ class WalletRequestHandler {
1831
1844
  // prompter is null, so we'll sign from here
1832
1845
  sig = await account.signMessage(prefixedMessage, chainId != null ? chainId : _this.defaultNetworkId);
1833
1846
  } else {
1834
- const promptResultForDeployment = await _this.handleConfirmWalletDeployPrompt(_this.prompter, account, chainId);
1847
+ const promptResultForDeployment = request.method === 'sequence_sign' || (await _this.handleConfirmWalletDeployPrompt(_this.prompter, account, chainId));
1835
1848
  if (promptResultForDeployment) {
1836
1849
  sig = await _this.prompter.promptSignMessage({
1837
1850
  chainId: chainId,
@@ -1847,6 +1860,7 @@ class WalletRequestHandler {
1847
1860
  }
1848
1861
  break;
1849
1862
  }
1863
+ case 'sequence_signTypedData_v4':
1850
1864
  case 'eth_signTypedData':
1851
1865
  case 'eth_signTypedData_v4':
1852
1866
  {
@@ -1869,7 +1883,7 @@ class WalletRequestHandler {
1869
1883
  // prompter is null, so we'll sign from here
1870
1884
  sig = await account.signTypedData(typedData.domain, typedData.types, typedData.message, chainId != null ? chainId : _this.defaultNetworkId);
1871
1885
  } else {
1872
- const promptResultForDeployment = await _this.handleConfirmWalletDeployPrompt(_this.prompter, account, chainId);
1886
+ const promptResultForDeployment = request.method === 'sequence_signTypedData_v4' || (await _this.handleConfirmWalletDeployPrompt(_this.prompter, account, chainId));
1873
1887
  if (promptResultForDeployment) {
1874
1888
  sig = await _this.prompter.promptSignMessage({
1875
1889
  chainId: chainId,
@@ -2106,8 +2120,12 @@ class WalletRequestHandler {
2106
2120
  }
2107
2121
  default:
2108
2122
  {
2123
+ if (!jsonRpcProvider) {
2124
+ throw new Error(`Account provider doesn't support send method`);
2125
+ }
2126
+
2109
2127
  // NOTE: provider here will be chain-bound if chainId is provided
2110
- const providerResponse = await provider.send(request.method, request.params);
2128
+ const providerResponse = await jsonRpcProvider.send(request.method, request.params);
2111
2129
  response.result = providerResponse;
2112
2130
  }
2113
2131
  }
@@ -2932,7 +2950,7 @@ class Web3Signer extends wallet.Signer {
2932
2950
 
2933
2951
  // signMessage matches implementation from ethers JsonRpcSigner for compatibility, but with
2934
2952
  // multi-chain support.
2935
- async signMessage(message, chainId, allSigners) {
2953
+ async signMessage(message, chainId, allSigners, sequenceVerified) {
2936
2954
  const provider = await this.getSender(network.maybeChainId(chainId) || this.defaultChainId);
2937
2955
  const data = typeof message === 'string' ? ethers.ethers.utils.toUtf8Bytes(message) : message;
2938
2956
  const address = await this.getAddress();
@@ -2940,18 +2958,18 @@ class Web3Signer extends wallet.Signer {
2940
2958
  // NOTE: as of ethers v5.5, it switched to using personal_sign, see
2941
2959
  // https://github.com/ethers-io/ethers.js/pull/1542 and see
2942
2960
  // https://github.com/WalletConnect/walletconnect-docs/issues/32 for additional info.
2943
- return await provider.send('personal_sign', [ethers.ethers.utils.hexlify(data), address]);
2961
+ return provider.send(sequenceVerified ? 'sequence_sign' : 'personal_sign', [ethers.ethers.utils.hexlify(data), address]);
2944
2962
  }
2945
2963
 
2946
2964
  // signTypedData matches implementation from ethers JsonRpcSigner for compatibility, but with
2947
2965
  // multi-chain support.
2948
- async signTypedData(domain, types, message, chainId, allSigners) {
2966
+ async signTypedData(domain, types, message, chainId, allSigners, sequenceVerified) {
2949
2967
  // Populate any ENS names (in-place)
2950
2968
  // const populated = await ethers.utils._TypedDataEncoder.resolveNames(domain, types, message, (name: string) => {
2951
2969
  // return this.provider.resolveName(name)
2952
2970
  // })
2953
2971
 
2954
- return await this.provider.send('eth_signTypedData_v4', [await this.getAddress(), ethers.ethers.utils._TypedDataEncoder.getPayload(domain, types, message)], network.maybeChainId(chainId) || this.defaultChainId);
2972
+ return this.provider.send(sequenceVerified ? 'sequence_signTypedData_v4' : 'eth_signTypedData_v4', [await this.getAddress(), ethers.ethers.utils._TypedDataEncoder.getPayload(domain, types, message)], network.maybeChainId(chainId) || this.defaultChainId);
2955
2973
  }
2956
2974
 
2957
2975
  // sendTransaction matches implementation from ethers JsonRpcSigner for compatibility, but with
@@ -1774,19 +1774,23 @@ class WalletRequestHandler {
1774
1774
  // fetch the provider for the specific chain, or undefined will select defaultChain
1775
1775
  const provider = (_this$account = _this.account) == null ? void 0 : _this$account.provider(chainId != null ? chainId : _this.defaultNetworkId);
1776
1776
  if (!provider) throw new Error(`WalletRequestHandler: wallet provider is not configured for chainId ${chainId}`);
1777
- if (provider.send === undefined) {
1778
- throw new Error(`Account provider doesn't support send method`);
1779
- }
1777
+ const jsonRpcProvider = provider instanceof ethers.ethers.providers.JsonRpcProvider ? provider : undefined;
1780
1778
  switch (request.method) {
1781
1779
  case 'net_version':
1782
1780
  {
1783
- const result = await provider.send('net_version', []);
1781
+ if (!jsonRpcProvider) {
1782
+ throw new Error(`Account provider doesn't support send method`);
1783
+ }
1784
+ const result = await jsonRpcProvider.send('net_version', []);
1784
1785
  response.result = result;
1785
1786
  break;
1786
1787
  }
1787
1788
  case 'eth_chainId':
1788
1789
  {
1789
- const result = await provider.send('eth_chainId', []);
1790
+ if (!jsonRpcProvider) {
1791
+ throw new Error(`Account provider doesn't support send method`);
1792
+ }
1793
+ const result = await jsonRpcProvider.send('eth_chainId', []);
1790
1794
  response.result = result;
1791
1795
  break;
1792
1796
  }
@@ -1803,6 +1807,7 @@ class WalletRequestHandler {
1803
1807
  response.result = walletBalance.toHexString();
1804
1808
  break;
1805
1809
  }
1810
+ case 'sequence_sign':
1806
1811
  case 'personal_sign':
1807
1812
  case 'eth_sign':
1808
1813
  {
@@ -1810,14 +1815,22 @@ class WalletRequestHandler {
1810
1815
  let message;
1811
1816
 
1812
1817
  // there is a difference in the order of the params:
1813
- // personal_sign: [data, address]
1818
+ // sequence_sign, personal_sign: [data, address]
1814
1819
  // eth_sign: [address, data]
1815
- if (request.method === 'personal_sign') {
1816
- const [data, address] = request.params;
1817
- message = data;
1818
- } else {
1819
- const [address, data] = request.params;
1820
- message = data;
1820
+ switch (request.method) {
1821
+ case 'sequence_sign':
1822
+ case 'personal_sign':
1823
+ {
1824
+ const [data, _address] = request.params;
1825
+ message = data;
1826
+ break;
1827
+ }
1828
+ case 'eth_sign':
1829
+ {
1830
+ const [_address, data] = request.params;
1831
+ message = data;
1832
+ break;
1833
+ }
1821
1834
  }
1822
1835
  let sig = '';
1823
1836
 
@@ -1831,7 +1844,7 @@ class WalletRequestHandler {
1831
1844
  // prompter is null, so we'll sign from here
1832
1845
  sig = await account.signMessage(prefixedMessage, chainId != null ? chainId : _this.defaultNetworkId);
1833
1846
  } else {
1834
- const promptResultForDeployment = await _this.handleConfirmWalletDeployPrompt(_this.prompter, account, chainId);
1847
+ const promptResultForDeployment = request.method === 'sequence_sign' || (await _this.handleConfirmWalletDeployPrompt(_this.prompter, account, chainId));
1835
1848
  if (promptResultForDeployment) {
1836
1849
  sig = await _this.prompter.promptSignMessage({
1837
1850
  chainId: chainId,
@@ -1847,6 +1860,7 @@ class WalletRequestHandler {
1847
1860
  }
1848
1861
  break;
1849
1862
  }
1863
+ case 'sequence_signTypedData_v4':
1850
1864
  case 'eth_signTypedData':
1851
1865
  case 'eth_signTypedData_v4':
1852
1866
  {
@@ -1869,7 +1883,7 @@ class WalletRequestHandler {
1869
1883
  // prompter is null, so we'll sign from here
1870
1884
  sig = await account.signTypedData(typedData.domain, typedData.types, typedData.message, chainId != null ? chainId : _this.defaultNetworkId);
1871
1885
  } else {
1872
- const promptResultForDeployment = await _this.handleConfirmWalletDeployPrompt(_this.prompter, account, chainId);
1886
+ const promptResultForDeployment = request.method === 'sequence_signTypedData_v4' || (await _this.handleConfirmWalletDeployPrompt(_this.prompter, account, chainId));
1873
1887
  if (promptResultForDeployment) {
1874
1888
  sig = await _this.prompter.promptSignMessage({
1875
1889
  chainId: chainId,
@@ -2106,8 +2120,12 @@ class WalletRequestHandler {
2106
2120
  }
2107
2121
  default:
2108
2122
  {
2123
+ if (!jsonRpcProvider) {
2124
+ throw new Error(`Account provider doesn't support send method`);
2125
+ }
2126
+
2109
2127
  // NOTE: provider here will be chain-bound if chainId is provided
2110
- const providerResponse = await provider.send(request.method, request.params);
2128
+ const providerResponse = await jsonRpcProvider.send(request.method, request.params);
2111
2129
  response.result = providerResponse;
2112
2130
  }
2113
2131
  }
@@ -2932,7 +2950,7 @@ class Web3Signer extends wallet.Signer {
2932
2950
 
2933
2951
  // signMessage matches implementation from ethers JsonRpcSigner for compatibility, but with
2934
2952
  // multi-chain support.
2935
- async signMessage(message, chainId, allSigners) {
2953
+ async signMessage(message, chainId, allSigners, sequenceVerified) {
2936
2954
  const provider = await this.getSender(network.maybeChainId(chainId) || this.defaultChainId);
2937
2955
  const data = typeof message === 'string' ? ethers.ethers.utils.toUtf8Bytes(message) : message;
2938
2956
  const address = await this.getAddress();
@@ -2940,18 +2958,18 @@ class Web3Signer extends wallet.Signer {
2940
2958
  // NOTE: as of ethers v5.5, it switched to using personal_sign, see
2941
2959
  // https://github.com/ethers-io/ethers.js/pull/1542 and see
2942
2960
  // https://github.com/WalletConnect/walletconnect-docs/issues/32 for additional info.
2943
- return await provider.send('personal_sign', [ethers.ethers.utils.hexlify(data), address]);
2961
+ return provider.send(sequenceVerified ? 'sequence_sign' : 'personal_sign', [ethers.ethers.utils.hexlify(data), address]);
2944
2962
  }
2945
2963
 
2946
2964
  // signTypedData matches implementation from ethers JsonRpcSigner for compatibility, but with
2947
2965
  // multi-chain support.
2948
- async signTypedData(domain, types, message, chainId, allSigners) {
2966
+ async signTypedData(domain, types, message, chainId, allSigners, sequenceVerified) {
2949
2967
  // Populate any ENS names (in-place)
2950
2968
  // const populated = await ethers.utils._TypedDataEncoder.resolveNames(domain, types, message, (name: string) => {
2951
2969
  // return this.provider.resolveName(name)
2952
2970
  // })
2953
2971
 
2954
- return await this.provider.send('eth_signTypedData_v4', [await this.getAddress(), ethers.ethers.utils._TypedDataEncoder.getPayload(domain, types, message)], network.maybeChainId(chainId) || this.defaultChainId);
2972
+ return this.provider.send(sequenceVerified ? 'sequence_signTypedData_v4' : 'eth_signTypedData_v4', [await this.getAddress(), ethers.ethers.utils._TypedDataEncoder.getPayload(domain, types, message)], network.maybeChainId(chainId) || this.defaultChainId);
2955
2973
  }
2956
2974
 
2957
2975
  // sendTransaction matches implementation from ethers JsonRpcSigner for compatibility, but with
@@ -1770,19 +1770,23 @@ class WalletRequestHandler {
1770
1770
  // fetch the provider for the specific chain, or undefined will select defaultChain
1771
1771
  const provider = (_this$account = _this.account) == null ? void 0 : _this$account.provider(chainId != null ? chainId : _this.defaultNetworkId);
1772
1772
  if (!provider) throw new Error(`WalletRequestHandler: wallet provider is not configured for chainId ${chainId}`);
1773
- if (provider.send === undefined) {
1774
- throw new Error(`Account provider doesn't support send method`);
1775
- }
1773
+ const jsonRpcProvider = provider instanceof ethers.providers.JsonRpcProvider ? provider : undefined;
1776
1774
  switch (request.method) {
1777
1775
  case 'net_version':
1778
1776
  {
1779
- const result = await provider.send('net_version', []);
1777
+ if (!jsonRpcProvider) {
1778
+ throw new Error(`Account provider doesn't support send method`);
1779
+ }
1780
+ const result = await jsonRpcProvider.send('net_version', []);
1780
1781
  response.result = result;
1781
1782
  break;
1782
1783
  }
1783
1784
  case 'eth_chainId':
1784
1785
  {
1785
- const result = await provider.send('eth_chainId', []);
1786
+ if (!jsonRpcProvider) {
1787
+ throw new Error(`Account provider doesn't support send method`);
1788
+ }
1789
+ const result = await jsonRpcProvider.send('eth_chainId', []);
1786
1790
  response.result = result;
1787
1791
  break;
1788
1792
  }
@@ -1799,6 +1803,7 @@ class WalletRequestHandler {
1799
1803
  response.result = walletBalance.toHexString();
1800
1804
  break;
1801
1805
  }
1806
+ case 'sequence_sign':
1802
1807
  case 'personal_sign':
1803
1808
  case 'eth_sign':
1804
1809
  {
@@ -1806,14 +1811,22 @@ class WalletRequestHandler {
1806
1811
  let message;
1807
1812
 
1808
1813
  // there is a difference in the order of the params:
1809
- // personal_sign: [data, address]
1814
+ // sequence_sign, personal_sign: [data, address]
1810
1815
  // eth_sign: [address, data]
1811
- if (request.method === 'personal_sign') {
1812
- const [data, address] = request.params;
1813
- message = data;
1814
- } else {
1815
- const [address, data] = request.params;
1816
- message = data;
1816
+ switch (request.method) {
1817
+ case 'sequence_sign':
1818
+ case 'personal_sign':
1819
+ {
1820
+ const [data, _address] = request.params;
1821
+ message = data;
1822
+ break;
1823
+ }
1824
+ case 'eth_sign':
1825
+ {
1826
+ const [_address, data] = request.params;
1827
+ message = data;
1828
+ break;
1829
+ }
1817
1830
  }
1818
1831
  let sig = '';
1819
1832
 
@@ -1827,7 +1840,7 @@ class WalletRequestHandler {
1827
1840
  // prompter is null, so we'll sign from here
1828
1841
  sig = await account.signMessage(prefixedMessage, chainId != null ? chainId : _this.defaultNetworkId);
1829
1842
  } else {
1830
- const promptResultForDeployment = await _this.handleConfirmWalletDeployPrompt(_this.prompter, account, chainId);
1843
+ const promptResultForDeployment = request.method === 'sequence_sign' || (await _this.handleConfirmWalletDeployPrompt(_this.prompter, account, chainId));
1831
1844
  if (promptResultForDeployment) {
1832
1845
  sig = await _this.prompter.promptSignMessage({
1833
1846
  chainId: chainId,
@@ -1843,6 +1856,7 @@ class WalletRequestHandler {
1843
1856
  }
1844
1857
  break;
1845
1858
  }
1859
+ case 'sequence_signTypedData_v4':
1846
1860
  case 'eth_signTypedData':
1847
1861
  case 'eth_signTypedData_v4':
1848
1862
  {
@@ -1865,7 +1879,7 @@ class WalletRequestHandler {
1865
1879
  // prompter is null, so we'll sign from here
1866
1880
  sig = await account.signTypedData(typedData.domain, typedData.types, typedData.message, chainId != null ? chainId : _this.defaultNetworkId);
1867
1881
  } else {
1868
- const promptResultForDeployment = await _this.handleConfirmWalletDeployPrompt(_this.prompter, account, chainId);
1882
+ const promptResultForDeployment = request.method === 'sequence_signTypedData_v4' || (await _this.handleConfirmWalletDeployPrompt(_this.prompter, account, chainId));
1869
1883
  if (promptResultForDeployment) {
1870
1884
  sig = await _this.prompter.promptSignMessage({
1871
1885
  chainId: chainId,
@@ -2102,8 +2116,12 @@ class WalletRequestHandler {
2102
2116
  }
2103
2117
  default:
2104
2118
  {
2119
+ if (!jsonRpcProvider) {
2120
+ throw new Error(`Account provider doesn't support send method`);
2121
+ }
2122
+
2105
2123
  // NOTE: provider here will be chain-bound if chainId is provided
2106
- const providerResponse = await provider.send(request.method, request.params);
2124
+ const providerResponse = await jsonRpcProvider.send(request.method, request.params);
2107
2125
  response.result = providerResponse;
2108
2126
  }
2109
2127
  }
@@ -2928,7 +2946,7 @@ class Web3Signer extends Signer {
2928
2946
 
2929
2947
  // signMessage matches implementation from ethers JsonRpcSigner for compatibility, but with
2930
2948
  // multi-chain support.
2931
- async signMessage(message, chainId, allSigners) {
2949
+ async signMessage(message, chainId, allSigners, sequenceVerified) {
2932
2950
  const provider = await this.getSender(maybeChainId(chainId) || this.defaultChainId);
2933
2951
  const data = typeof message === 'string' ? ethers.utils.toUtf8Bytes(message) : message;
2934
2952
  const address = await this.getAddress();
@@ -2936,18 +2954,18 @@ class Web3Signer extends Signer {
2936
2954
  // NOTE: as of ethers v5.5, it switched to using personal_sign, see
2937
2955
  // https://github.com/ethers-io/ethers.js/pull/1542 and see
2938
2956
  // https://github.com/WalletConnect/walletconnect-docs/issues/32 for additional info.
2939
- return await provider.send('personal_sign', [ethers.utils.hexlify(data), address]);
2957
+ return provider.send(sequenceVerified ? 'sequence_sign' : 'personal_sign', [ethers.utils.hexlify(data), address]);
2940
2958
  }
2941
2959
 
2942
2960
  // signTypedData matches implementation from ethers JsonRpcSigner for compatibility, but with
2943
2961
  // multi-chain support.
2944
- async signTypedData(domain, types, message, chainId, allSigners) {
2962
+ async signTypedData(domain, types, message, chainId, allSigners, sequenceVerified) {
2945
2963
  // Populate any ENS names (in-place)
2946
2964
  // const populated = await ethers.utils._TypedDataEncoder.resolveNames(domain, types, message, (name: string) => {
2947
2965
  // return this.provider.resolveName(name)
2948
2966
  // })
2949
2967
 
2950
- return await this.provider.send('eth_signTypedData_v4', [await this.getAddress(), ethers.utils._TypedDataEncoder.getPayload(domain, types, message)], maybeChainId(chainId) || this.defaultChainId);
2968
+ return this.provider.send(sequenceVerified ? 'sequence_signTypedData_v4' : 'eth_signTypedData_v4', [await this.getAddress(), ethers.utils._TypedDataEncoder.getPayload(domain, types, message)], maybeChainId(chainId) || this.defaultChainId);
2951
2969
  }
2952
2970
 
2953
2971
  // sendTransaction matches implementation from ethers JsonRpcSigner for compatibility, but with
@@ -50,8 +50,8 @@ export declare class Web3Signer extends Signer implements TypedDataSigner {
50
50
  getWalletState(chainId?: ChainIdLike): Promise<AccountStatus>;
51
51
  getNetworks(): Promise<NetworkConfig[]>;
52
52
  getSigners(): Promise<string[]>;
53
- signMessage(message: BytesLike, chainId?: ChainIdLike, allSigners?: boolean): Promise<string>;
54
- signTypedData(domain: TypedDataDomain, types: Record<string, Array<TypedDataField>>, message: Record<string, any>, chainId?: ChainIdLike, allSigners?: boolean): Promise<string>;
53
+ signMessage(message: BytesLike, chainId?: ChainIdLike, allSigners?: boolean, sequenceVerified?: boolean): Promise<string>;
54
+ signTypedData(domain: TypedDataDomain, types: Record<string, Array<TypedDataField>>, message: Record<string, any>, chainId?: ChainIdLike, allSigners?: boolean, sequenceVerified?: boolean): Promise<string>;
55
55
  sendTransaction(transaction: Deferrable<ExtendedTransactionRequest>, chainId?: ChainIdLike): Promise<commons.transaction.TransactionResponse>;
56
56
  sendTransactionBatch(transactions: Deferrable<ethers.providers.TransactionRequest[]>, chainId?: ChainIdLike): Promise<ethers.providers.TransactionResponse>;
57
57
  signTransactions(transaction: Deferrable<ethers.providers.TransactionRequest>, chainId?: ChainIdLike): Promise<commons.transaction.SignedTransactionBundle>;
@@ -1,5 +1,6 @@
1
+ import { ETHAuthProof as AuthETHAuthProof } from '@0xsequence/auth';
1
2
  import { commons } from '@0xsequence/core';
2
- import { NetworkConfig, JsonRpcRequest, JsonRpcResponse, JsonRpcHandler } from '@0xsequence/network';
3
+ import { JsonRpcHandler, JsonRpcRequest, JsonRpcResponse, NetworkConfig, ProviderRpcError as NetworkProviderRpcError } from '@0xsequence/network';
3
4
  import { TypedData } from '@0xsequence/utils';
4
5
  export interface ProviderTransport extends JsonRpcHandler, ProviderMessageTransport, ProviderMessageRequestHandler {
5
6
  register(): void;
@@ -39,13 +40,7 @@ export interface ProviderMessage<T> {
39
40
  export type ProviderMessageRequest = ProviderMessage<JsonRpcRequest>;
40
41
  export type ProviderMessageResponse = ProviderMessage<JsonRpcResponse>;
41
42
  export type ProviderMessageResponseCallback = (error?: ProviderRpcError, response?: ProviderMessageResponse) => void;
42
- export interface ProviderRpcError extends Error {
43
- message: string;
44
- code?: number;
45
- data?: {
46
- [key: string]: any;
47
- };
48
- }
43
+ export type ProviderRpcError = NetworkProviderRpcError;
49
44
  export interface ProviderMessageRequestHandler {
50
45
  sendMessageRequest(message: ProviderMessageRequest): Promise<ProviderMessageResponse>;
51
46
  }
@@ -208,10 +203,7 @@ export interface MessageToSign {
208
203
  typedData?: TypedData;
209
204
  chainId?: number;
210
205
  }
211
- export interface ETHAuthProof {
212
- typedData: TypedData;
213
- proofString: string;
214
- }
206
+ export type ETHAuthProof = AuthETHAuthProof;
215
207
  export interface WalletSession {
216
208
  walletContext?: commons.context.VersionedContext;
217
209
  accountAddress?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0xsequence/provider",
3
- "version": "0.0.0-20230321200348",
3
+ "version": "0.0.0-20230327140007",
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",
@@ -9,17 +9,17 @@
9
9
  "author": "Horizon Blockchain Games",
10
10
  "license": "Apache-2.0",
11
11
  "dependencies": {
12
- "@0xsequence/abi": "0.0.0-20230321200348",
13
- "@0xsequence/account": "0.0.0-20230321200348",
14
- "@0xsequence/auth": "0.0.0-20230321200348",
15
- "@0xsequence/core": "0.0.0-20230321200348",
16
- "@0xsequence/migration": "0.0.0-20230321200348",
17
- "@0xsequence/network": "0.0.0-20230321200348",
18
- "@0xsequence/relayer": "0.0.0-20230321200348",
19
- "@0xsequence/utils": "0.0.0-20230321200348",
20
- "@0xsequence/wallet": "0.0.0-20230321200348",
21
12
  "eventemitter2": "^6.4.5",
22
- "webextension-polyfill": "^0.10.0"
13
+ "webextension-polyfill": "^0.10.0",
14
+ "@0xsequence/abi": "0.0.0-20230327140007",
15
+ "@0xsequence/auth": "0.0.0-20230327140007",
16
+ "@0xsequence/account": "0.0.0-20230327140007",
17
+ "@0xsequence/migration": "0.0.0-20230327140007",
18
+ "@0xsequence/core": "0.0.0-20230327140007",
19
+ "@0xsequence/network": "0.0.0-20230327140007",
20
+ "@0xsequence/relayer": "0.0.0-20230327140007",
21
+ "@0xsequence/utils": "0.0.0-20230327140007",
22
+ "@0xsequence/wallet": "0.0.0-20230327140007"
23
23
  },
24
24
  "peerDependencies": {
25
25
  "ethers": ">=5.5 < 6"
package/src/provider.ts CHANGED
@@ -229,7 +229,7 @@ export class Web3Signer extends Signer implements TypedDataSigner {
229
229
 
230
230
  // signMessage matches implementation from ethers JsonRpcSigner for compatibility, but with
231
231
  // multi-chain support.
232
- async signMessage(message: BytesLike, chainId?: ChainIdLike, allSigners?: boolean): Promise<string> {
232
+ async signMessage(message: BytesLike, chainId?: ChainIdLike, allSigners?: boolean, sequenceVerified?: boolean): Promise<string> {
233
233
  const provider = await this.getSender(maybeChainId(chainId) || this.defaultChainId)
234
234
 
235
235
  const data = typeof message === 'string' ? ethers.utils.toUtf8Bytes(message) : message
@@ -238,7 +238,10 @@ export class Web3Signer extends Signer implements TypedDataSigner {
238
238
  // NOTE: as of ethers v5.5, it switched to using personal_sign, see
239
239
  // https://github.com/ethers-io/ethers.js/pull/1542 and see
240
240
  // https://github.com/WalletConnect/walletconnect-docs/issues/32 for additional info.
241
- return await provider!.send('personal_sign', [ethers.utils.hexlify(data), address])
241
+ return provider!.send(
242
+ sequenceVerified ? 'sequence_sign' : 'personal_sign',
243
+ [ethers.utils.hexlify(data), address]
244
+ )
242
245
  }
243
246
 
244
247
  // signTypedData matches implementation from ethers JsonRpcSigner for compatibility, but with
@@ -248,15 +251,16 @@ export class Web3Signer extends Signer implements TypedDataSigner {
248
251
  types: Record<string, Array<TypedDataField>>,
249
252
  message: Record<string, any>,
250
253
  chainId?: ChainIdLike,
251
- allSigners?: boolean
254
+ allSigners?: boolean,
255
+ sequenceVerified?: boolean
252
256
  ): Promise<string> {
253
257
  // Populate any ENS names (in-place)
254
258
  // const populated = await ethers.utils._TypedDataEncoder.resolveNames(domain, types, message, (name: string) => {
255
259
  // return this.provider.resolveName(name)
256
260
  // })
257
261
 
258
- return await this.provider.send(
259
- 'eth_signTypedData_v4',
262
+ return this.provider.send(
263
+ sequenceVerified ? 'sequence_signTypedData_v4' : 'eth_signTypedData_v4',
260
264
  [await this.getAddress(), ethers.utils._TypedDataEncoder.getPayload(domain, types, message)],
261
265
  maybeChainId(chainId) || this.defaultChainId
262
266
  )
@@ -280,22 +280,27 @@ export class WalletRequestHandler implements ExternalProvider, JsonRpcHandler, P
280
280
  if (!account) throw new Error('WalletRequestHandler: wallet account is not configured')
281
281
 
282
282
  // fetch the provider for the specific chain, or undefined will select defaultChain
283
- const provider = this.account?.provider(chainId ?? this.defaultNetworkId) as ethers.providers.JsonRpcProvider
283
+ const provider = this.account?.provider(chainId ?? this.defaultNetworkId)
284
284
  if (!provider) throw new Error(`WalletRequestHandler: wallet provider is not configured for chainId ${chainId}`)
285
-
286
- if (provider.send === undefined) {
287
- throw new Error(`Account provider doesn't support send method`)
288
- }
285
+ const jsonRpcProvider = provider instanceof ethers.providers.JsonRpcProvider ? provider : undefined
289
286
 
290
287
  switch (request.method) {
291
288
  case 'net_version': {
292
- const result = await provider.send('net_version', [])
289
+ if (!jsonRpcProvider) {
290
+ throw new Error(`Account provider doesn't support send method`)
291
+ }
292
+
293
+ const result = await jsonRpcProvider.send('net_version', [])
293
294
  response.result = result
294
295
  break
295
296
  }
296
297
 
297
298
  case 'eth_chainId': {
298
- const result = await provider.send('eth_chainId', [])
299
+ if (!jsonRpcProvider) {
300
+ throw new Error(`Account provider doesn't support send method`)
301
+ }
302
+
303
+ const result = await jsonRpcProvider.send('eth_chainId', [])
299
304
  response.result = result
300
305
  break
301
306
  }
@@ -313,20 +318,27 @@ export class WalletRequestHandler implements ExternalProvider, JsonRpcHandler, P
313
318
  break
314
319
  }
315
320
 
321
+ case 'sequence_sign':
316
322
  case 'personal_sign':
317
323
  case 'eth_sign': {
318
324
  // note: message from json-rpc input is in hex format
319
325
  let message: any
320
326
 
321
327
  // there is a difference in the order of the params:
322
- // personal_sign: [data, address]
328
+ // sequence_sign, personal_sign: [data, address]
323
329
  // eth_sign: [address, data]
324
- if (request.method === 'personal_sign') {
325
- const [data, address] = request.params!
326
- message = data
327
- } else {
328
- const [address, data] = request.params!
329
- message = data
330
+ switch (request.method) {
331
+ case 'sequence_sign':
332
+ case 'personal_sign': {
333
+ const [data, _address] = request.params!
334
+ message = data
335
+ break
336
+ }
337
+ case 'eth_sign': {
338
+ const [_address, data] = request.params!
339
+ message = data
340
+ break
341
+ }
330
342
  }
331
343
 
332
344
  let sig = ''
@@ -341,7 +353,7 @@ export class WalletRequestHandler implements ExternalProvider, JsonRpcHandler, P
341
353
  // prompter is null, so we'll sign from here
342
354
  sig = await account.signMessage(prefixedMessage, chainId ?? this.defaultNetworkId)
343
355
  } else {
344
- const promptResultForDeployment = await this.handleConfirmWalletDeployPrompt(this.prompter, account, chainId)
356
+ const promptResultForDeployment = request.method === 'sequence_sign' || await this.handleConfirmWalletDeployPrompt(this.prompter, account, chainId)
345
357
  if (promptResultForDeployment) {
346
358
  sig = await this.prompter.promptSignMessage({ chainId: chainId, message: prefixedMessage }, this.connectOptions)
347
359
  }
@@ -356,6 +368,7 @@ export class WalletRequestHandler implements ExternalProvider, JsonRpcHandler, P
356
368
  break
357
369
  }
358
370
 
371
+ case 'sequence_signTypedData_v4':
359
372
  case 'eth_signTypedData':
360
373
  case 'eth_signTypedData_v4': {
361
374
  // note: signingAddress from json-rpc input is in hex format, and typedDataObject
@@ -381,7 +394,7 @@ export class WalletRequestHandler implements ExternalProvider, JsonRpcHandler, P
381
394
  // prompter is null, so we'll sign from here
382
395
  sig = await account.signTypedData(typedData.domain, typedData.types, typedData.message, chainId ?? this.defaultNetworkId)
383
396
  } else {
384
- const promptResultForDeployment = await this.handleConfirmWalletDeployPrompt(this.prompter, account, chainId)
397
+ const promptResultForDeployment = request.method === 'sequence_signTypedData_v4' || await this.handleConfirmWalletDeployPrompt(this.prompter, account, chainId)
385
398
  if (promptResultForDeployment) {
386
399
  sig = await this.prompter.promptSignMessage({ chainId: chainId, typedData: typedData }, this.connectOptions)
387
400
  }
@@ -619,8 +632,12 @@ export class WalletRequestHandler implements ExternalProvider, JsonRpcHandler, P
619
632
  }
620
633
 
621
634
  default: {
635
+ if (!jsonRpcProvider) {
636
+ throw new Error(`Account provider doesn't support send method`)
637
+ }
638
+
622
639
  // NOTE: provider here will be chain-bound if chainId is provided
623
- const providerResponse = await provider.send(request.method, request.params!)
640
+ const providerResponse = await jsonRpcProvider.send(request.method, request.params!)
624
641
  response.result = providerResponse
625
642
  }
626
643
  }
package/src/types.ts CHANGED
@@ -1,5 +1,6 @@
1
+ import { ETHAuthProof as AuthETHAuthProof } from '@0xsequence/auth'
1
2
  import { commons } from '@0xsequence/core'
2
- import { NetworkConfig, JsonRpcRequest, JsonRpcResponse, JsonRpcHandler } from '@0xsequence/network'
3
+ import { JsonRpcHandler, JsonRpcRequest, JsonRpcResponse, NetworkConfig, ProviderRpcError as NetworkProviderRpcError } from '@0xsequence/network'
3
4
  import { TypedData } from '@0xsequence/utils'
4
5
 
5
6
  export interface ProviderTransport extends JsonRpcHandler, ProviderMessageTransport, ProviderMessageRequestHandler {
@@ -50,11 +51,7 @@ export type ProviderMessageResponse = ProviderMessage<JsonRpcResponse>
50
51
  // which may contain the result or an error payload from the wallet.
51
52
  export type ProviderMessageResponseCallback = (error?: ProviderRpcError, response?: ProviderMessageResponse) => void
52
53
 
53
- export interface ProviderRpcError extends Error {
54
- message: string
55
- code?: number
56
- data?: { [key: string]: any }
57
- }
54
+ export type ProviderRpcError = NetworkProviderRpcError
58
55
 
59
56
  export interface ProviderMessageRequestHandler {
60
57
  // sendMessageRequest sends a ProviderMessageRequest over the wire to the wallet.
@@ -266,13 +263,7 @@ export interface MessageToSign {
266
263
  chainId?: number
267
264
  }
268
265
 
269
- export interface ETHAuthProof {
270
- // eip712 typed-data payload for ETHAuth domain as input
271
- typedData: TypedData
272
-
273
- // signature encoded in an ETHAuth proof string
274
- proofString: string
275
- }
266
+ export type ETHAuthProof = AuthETHAuthProof
276
267
 
277
268
  export interface WalletSession {
278
269
  // Wallet context