@0xsequence/provider 0.30.0 → 0.33.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,42 @@
1
1
  # @0xsequence/provider
2
2
 
3
+ ## 0.33.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+ - @0xsequence/auth@0.33.0
9
+
10
+ ## 0.31.3
11
+
12
+ ### Patch Changes
13
+
14
+ - @0xsequence/auth@0.31.3
15
+
16
+ ## 0.31.1
17
+
18
+ ### Patch Changes
19
+
20
+ - @0xsequence/wallet@0.31.1
21
+ - @0xsequence/auth@0.31.1
22
+
23
+ ## 0.31.0
24
+
25
+ ### Minor Changes
26
+
27
+ - - upgrading to ethers v5.5
28
+
29
+ ### Patch Changes
30
+
31
+ - Updated dependencies
32
+ - @0xsequence/abi@0.31.0
33
+ - @0xsequence/auth@0.31.0
34
+ - @0xsequence/config@0.31.0
35
+ - @0xsequence/network@0.31.0
36
+ - @0xsequence/transactions@0.31.0
37
+ - @0xsequence/utils@0.31.0
38
+ - @0xsequence/wallet@0.31.0
39
+
3
40
  ## 0.30.0
4
41
 
5
42
  ### Minor Changes
@@ -1732,6 +1732,34 @@ class WalletRequestHandler {
1732
1732
  break;
1733
1733
  }
1734
1734
 
1735
+ case 'personal_sign':
1736
+ {
1737
+ // note: message from json-rpc input is in hex format
1738
+ const [message, signingAddress] = request.params;
1739
+ let sig = ''; // TODO:
1740
+ // if (process.env.TEST_MODE === 'true' && this.prompter === null) {
1741
+
1742
+ if (_this.prompter === null) {
1743
+ // prompter is null, so we'll sign from here
1744
+ sig = await signer.signMessage(ethers.ethers.utils.arrayify(message), chainId);
1745
+ } else {
1746
+ // prompt user to provide the response
1747
+ sig = await _this.prompter.promptSignMessage({
1748
+ chainId: chainId,
1749
+ message: message
1750
+ });
1751
+ }
1752
+
1753
+ if (sig && sig.length > 0) {
1754
+ response.result = sig;
1755
+ } else {
1756
+ // The user has declined the request when value is null
1757
+ throw new Error('declined by user');
1758
+ }
1759
+
1760
+ break;
1761
+ }
1762
+
1735
1763
  case 'eth_sign':
1736
1764
  {
1737
1765
  // note: message from json-rpc input is in hex format
@@ -2650,9 +2678,11 @@ class Web3Signer extends wallet.Signer {
2650
2678
  async signMessage(message, chainId, allSigners) {
2651
2679
  const provider = await this.getSender(network.maybeChainId(chainId) || this.defaultChainId);
2652
2680
  const data = typeof message === 'string' ? ethers.ethers.utils.toUtf8Bytes(message) : message;
2653
- const address = await this.getAddress(); // https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sign
2681
+ const address = await this.getAddress(); // NOTE: as of ethers v5.5, it switched to using personal_sign, see
2682
+ // https://github.com/ethers-io/ethers.js/pull/1542 and see
2683
+ // https://github.com/WalletConnect/walletconnect-docs/issues/32 for additional info.
2654
2684
 
2655
- return await provider.send('eth_sign', [address, ethers.ethers.utils.hexlify(data)]);
2685
+ return await provider.send('personal_sign', [ethers.ethers.utils.hexlify(data), address]);
2656
2686
  } // signTypedData matches implementation from ethers JsonRpcSigner for compatibility, but with
2657
2687
  // multi-chain support.
2658
2688
 
@@ -2760,6 +2790,15 @@ class Web3Signer extends wallet.Signer {
2760
2790
  //
2761
2791
 
2762
2792
 
2793
+ async _legacySignMessage(message, chainId, allSigners) {
2794
+ const provider = await this.getSender(network.maybeChainId(chainId) || this.defaultChainId);
2795
+ const data = typeof message === 'string' ? ethers.ethers.utils.toUtf8Bytes(message) : message;
2796
+ const address = await this.getAddress(); // https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sign
2797
+ // NOTE: ethers since 5.5 has switched to using personal_sign, we should review, etc.
2798
+
2799
+ return await provider.send('eth_sign', [address, ethers.ethers.utils.hexlify(data)]);
2800
+ }
2801
+
2763
2802
  async _signTypedData(domain, types, message, chainId, allSigners) {
2764
2803
  return this.signTypedData(domain, types, message, chainId, allSigners);
2765
2804
  }
@@ -1732,6 +1732,34 @@ class WalletRequestHandler {
1732
1732
  break;
1733
1733
  }
1734
1734
 
1735
+ case 'personal_sign':
1736
+ {
1737
+ // note: message from json-rpc input is in hex format
1738
+ const [message, signingAddress] = request.params;
1739
+ let sig = ''; // TODO:
1740
+ // if (process.env.TEST_MODE === 'true' && this.prompter === null) {
1741
+
1742
+ if (_this.prompter === null) {
1743
+ // prompter is null, so we'll sign from here
1744
+ sig = await signer.signMessage(ethers.ethers.utils.arrayify(message), chainId);
1745
+ } else {
1746
+ // prompt user to provide the response
1747
+ sig = await _this.prompter.promptSignMessage({
1748
+ chainId: chainId,
1749
+ message: message
1750
+ });
1751
+ }
1752
+
1753
+ if (sig && sig.length > 0) {
1754
+ response.result = sig;
1755
+ } else {
1756
+ // The user has declined the request when value is null
1757
+ throw new Error('declined by user');
1758
+ }
1759
+
1760
+ break;
1761
+ }
1762
+
1735
1763
  case 'eth_sign':
1736
1764
  {
1737
1765
  // note: message from json-rpc input is in hex format
@@ -2650,9 +2678,11 @@ class Web3Signer extends wallet.Signer {
2650
2678
  async signMessage(message, chainId, allSigners) {
2651
2679
  const provider = await this.getSender(network.maybeChainId(chainId) || this.defaultChainId);
2652
2680
  const data = typeof message === 'string' ? ethers.ethers.utils.toUtf8Bytes(message) : message;
2653
- const address = await this.getAddress(); // https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sign
2681
+ const address = await this.getAddress(); // NOTE: as of ethers v5.5, it switched to using personal_sign, see
2682
+ // https://github.com/ethers-io/ethers.js/pull/1542 and see
2683
+ // https://github.com/WalletConnect/walletconnect-docs/issues/32 for additional info.
2654
2684
 
2655
- return await provider.send('eth_sign', [address, ethers.ethers.utils.hexlify(data)]);
2685
+ return await provider.send('personal_sign', [ethers.ethers.utils.hexlify(data), address]);
2656
2686
  } // signTypedData matches implementation from ethers JsonRpcSigner for compatibility, but with
2657
2687
  // multi-chain support.
2658
2688
 
@@ -2760,6 +2790,15 @@ class Web3Signer extends wallet.Signer {
2760
2790
  //
2761
2791
 
2762
2792
 
2793
+ async _legacySignMessage(message, chainId, allSigners) {
2794
+ const provider = await this.getSender(network.maybeChainId(chainId) || this.defaultChainId);
2795
+ const data = typeof message === 'string' ? ethers.ethers.utils.toUtf8Bytes(message) : message;
2796
+ const address = await this.getAddress(); // https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sign
2797
+ // NOTE: ethers since 5.5 has switched to using personal_sign, we should review, etc.
2798
+
2799
+ return await provider.send('eth_sign', [address, ethers.ethers.utils.hexlify(data)]);
2800
+ }
2801
+
2763
2802
  async _signTypedData(domain, types, message, chainId, allSigners) {
2764
2803
  return this.signTypedData(domain, types, message, chainId, allSigners);
2765
2804
  }
@@ -1728,6 +1728,34 @@ class WalletRequestHandler {
1728
1728
  break;
1729
1729
  }
1730
1730
 
1731
+ case 'personal_sign':
1732
+ {
1733
+ // note: message from json-rpc input is in hex format
1734
+ const [message, signingAddress] = request.params;
1735
+ let sig = ''; // TODO:
1736
+ // if (process.env.TEST_MODE === 'true' && this.prompter === null) {
1737
+
1738
+ if (_this.prompter === null) {
1739
+ // prompter is null, so we'll sign from here
1740
+ sig = await signer.signMessage(ethers.utils.arrayify(message), chainId);
1741
+ } else {
1742
+ // prompt user to provide the response
1743
+ sig = await _this.prompter.promptSignMessage({
1744
+ chainId: chainId,
1745
+ message: message
1746
+ });
1747
+ }
1748
+
1749
+ if (sig && sig.length > 0) {
1750
+ response.result = sig;
1751
+ } else {
1752
+ // The user has declined the request when value is null
1753
+ throw new Error('declined by user');
1754
+ }
1755
+
1756
+ break;
1757
+ }
1758
+
1731
1759
  case 'eth_sign':
1732
1760
  {
1733
1761
  // note: message from json-rpc input is in hex format
@@ -2646,9 +2674,11 @@ class Web3Signer extends Signer {
2646
2674
  async signMessage(message, chainId, allSigners) {
2647
2675
  const provider = await this.getSender(maybeChainId(chainId) || this.defaultChainId);
2648
2676
  const data = typeof message === 'string' ? ethers.utils.toUtf8Bytes(message) : message;
2649
- const address = await this.getAddress(); // https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sign
2677
+ const address = await this.getAddress(); // NOTE: as of ethers v5.5, it switched to using personal_sign, see
2678
+ // https://github.com/ethers-io/ethers.js/pull/1542 and see
2679
+ // https://github.com/WalletConnect/walletconnect-docs/issues/32 for additional info.
2650
2680
 
2651
- return await provider.send('eth_sign', [address, ethers.utils.hexlify(data)]);
2681
+ return await provider.send('personal_sign', [ethers.utils.hexlify(data), address]);
2652
2682
  } // signTypedData matches implementation from ethers JsonRpcSigner for compatibility, but with
2653
2683
  // multi-chain support.
2654
2684
 
@@ -2756,6 +2786,15 @@ class Web3Signer extends Signer {
2756
2786
  //
2757
2787
 
2758
2788
 
2789
+ async _legacySignMessage(message, chainId, allSigners) {
2790
+ const provider = await this.getSender(maybeChainId(chainId) || this.defaultChainId);
2791
+ const data = typeof message === 'string' ? ethers.utils.toUtf8Bytes(message) : message;
2792
+ const address = await this.getAddress(); // https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sign
2793
+ // NOTE: ethers since 5.5 has switched to using personal_sign, we should review, etc.
2794
+
2795
+ return await provider.send('eth_sign', [address, ethers.utils.hexlify(data)]);
2796
+ }
2797
+
2759
2798
  async _signTypedData(domain, types, message, chainId, allSigners) {
2760
2799
  return this.signTypedData(domain, types, message, chainId, allSigners);
2761
2800
  }
@@ -1,5 +1,5 @@
1
1
  import { ethers } from 'ethers';
2
- import { BytesLike } from '@ethersproject/bytes';
2
+ import { BytesLike, Bytes } from '@ethersproject/bytes';
3
3
  import { Web3Provider as EthersWeb3Provider, JsonRpcProvider } from '@ethersproject/providers';
4
4
  import { TypedDataDomain, TypedDataField, TypedDataSigner } from '@ethersproject/abstract-signer';
5
5
  import { NetworkConfig, Networks, WalletContext, ChainIdLike, JsonRpcHandler, JsonRpcFetchFunc, JsonRpcRequest, JsonRpcResponseCallback, JsonRpcSender } from '@0xsequence/network';
@@ -52,6 +52,7 @@ export declare class Web3Signer extends Signer implements TypedDataSigner {
52
52
  updateConfig(newConfig?: WalletConfig): Promise<[WalletConfig, TransactionResponse | undefined]>;
53
53
  publishConfig(): Promise<TransactionResponse | undefined>;
54
54
  isDeployed(chainId?: ChainIdLike): Promise<boolean>;
55
+ _legacySignMessage(message: Bytes | string, chainId?: ChainIdLike, allSigners?: boolean): Promise<string>;
55
56
  _signTypedData(domain: TypedDataDomain, types: Record<string, Array<TypedDataField>>, message: Record<string, any>, chainId?: ChainIdLike, allSigners?: boolean): Promise<string>;
56
57
  sendUncheckedTransaction(transaction: Deferrable<TransactionRequest>, chainId?: ChainIdLike): Promise<string>;
57
58
  connectUnchecked(): ethers.providers.JsonRpcSigner;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0xsequence/provider",
3
- "version": "0.30.0",
3
+ "version": "0.33.0",
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",
@@ -13,18 +13,18 @@
13
13
  "typecheck": "tsc --noEmit"
14
14
  },
15
15
  "dependencies": {
16
- "@0xsequence/abi": "^0.30.0",
17
- "@0xsequence/auth": "^0.30.0",
18
- "@0xsequence/config": "^0.30.0",
19
- "@0xsequence/network": "^0.30.0",
20
- "@0xsequence/transactions": "^0.30.0",
21
- "@0xsequence/utils": "^0.30.0",
22
- "@0xsequence/wallet": "^0.30.0",
23
- "@ethersproject/abstract-signer": "5.0.14",
24
- "@ethersproject/hash": "^5.0.12",
25
- "@ethersproject/providers": "^5.0.24",
26
- "@ethersproject/web": "^5.0.14",
27
- "ethers": "^5.0.32",
16
+ "@0xsequence/abi": "^0.31.0",
17
+ "@0xsequence/auth": "^0.33.0",
18
+ "@0xsequence/config": "^0.31.0",
19
+ "@0xsequence/network": "^0.31.0",
20
+ "@0xsequence/transactions": "^0.31.0",
21
+ "@0xsequence/utils": "^0.31.0",
22
+ "@0xsequence/wallet": "^0.31.1",
23
+ "@ethersproject/abstract-signer": "^5.5.0",
24
+ "@ethersproject/hash": "^5.5.0",
25
+ "@ethersproject/providers": "^5.5.0",
26
+ "@ethersproject/web": "^5.5.0",
27
+ "ethers": "^5.5.1",
28
28
  "eventemitter2": "^6.4.5",
29
29
  "webextension-polyfill-ts": "^0.26.0"
30
30
  },
package/src/provider.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ethers } from 'ethers'
2
- import { BytesLike } from '@ethersproject/bytes'
2
+ import { BytesLike, Bytes } from '@ethersproject/bytes'
3
3
  import { Web3Provider as EthersWeb3Provider, ExternalProvider, JsonRpcProvider, Networkish } from '@ethersproject/providers'
4
4
  import { TypedDataDomain, TypedDataField, TypedDataSigner } from '@ethersproject/abstract-signer'
5
5
  import {
@@ -230,8 +230,10 @@ export class Web3Signer extends Signer implements TypedDataSigner {
230
230
  const data = typeof message === 'string' ? ethers.utils.toUtf8Bytes(message) : message
231
231
  const address = await this.getAddress()
232
232
 
233
- // https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sign
234
- return await provider!.send('eth_sign', [address, ethers.utils.hexlify(data)])
233
+ // NOTE: as of ethers v5.5, it switched to using personal_sign, see
234
+ // https://github.com/ethers-io/ethers.js/pull/1542 and see
235
+ // https://github.com/WalletConnect/walletconnect-docs/issues/32 for additional info.
236
+ return await provider!.send('personal_sign', [ethers.utils.hexlify(data), address])
235
237
  }
236
238
 
237
239
  // signTypedData matches implementation from ethers JsonRpcSigner for compatibility, but with
@@ -363,6 +365,17 @@ export class Web3Signer extends Signer implements TypedDataSigner {
363
365
  // ethers JsonRpcSigner methods
364
366
  //
365
367
 
368
+ async _legacySignMessage(message: Bytes | string, chainId?: ChainIdLike, allSigners?: boolean): Promise<string> {
369
+ const provider = await this.getSender(maybeChainId(chainId) || this.defaultChainId)
370
+
371
+ const data = typeof message === 'string' ? ethers.utils.toUtf8Bytes(message) : message
372
+ const address = await this.getAddress()
373
+
374
+ // https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sign
375
+ // NOTE: ethers since 5.5 has switched to using personal_sign, we should review, etc.
376
+ return await provider!.send('eth_sign', [address, ethers.utils.hexlify(data)])
377
+ }
378
+
366
379
  async _signTypedData(
367
380
  domain: TypedDataDomain,
368
381
  types: Record<string, Array<TypedDataField>>,
@@ -244,7 +244,7 @@ export abstract class BaseWalletTransport implements WalletTransport {
244
244
  return false
245
245
  }
246
246
 
247
- const { sessionId, nonce } = (message.data as any) as { sessionId: string; nonce: string }
247
+ const { sessionId, nonce } = message.data as any as { sessionId: string; nonce: string }
248
248
  if (!sessionId || sessionId.length === 0 || !nonce || nonce.length === 0) {
249
249
  logger.error('invalid init ack')
250
250
  return false
@@ -252,6 +252,30 @@ export class WalletRequestHandler implements ExternalProvider, JsonRpcHandler, P
252
252
  break
253
253
  }
254
254
 
255
+ case 'personal_sign': {
256
+ // note: message from json-rpc input is in hex format
257
+ const [message, signingAddress] = request.params!
258
+
259
+ let sig = ''
260
+ // TODO:
261
+ // if (process.env.TEST_MODE === 'true' && this.prompter === null) {
262
+ if (this.prompter === null) {
263
+ // prompter is null, so we'll sign from here
264
+ sig = await signer.signMessage(ethers.utils.arrayify(message), chainId)
265
+ } else {
266
+ // prompt user to provide the response
267
+ sig = await this.prompter.promptSignMessage({ chainId: chainId, message: message })
268
+ }
269
+
270
+ if (sig && sig.length > 0) {
271
+ response.result = sig
272
+ } else {
273
+ // The user has declined the request when value is null
274
+ throw new Error('declined by user')
275
+ }
276
+ break
277
+ }
278
+
255
279
  case 'eth_sign': {
256
280
  // note: message from json-rpc input is in hex format
257
281
  const [signingAddress, message] = request.params!