Skip to content

Commit 836996f

Browse files
authored
Merge pull request #1915 from tmckenzie51/tiffany/signTypedData-to-snakecase
deprecate signTypedData in favor of sign_typed_data
2 parents 5d6c278 + db5bfcf commit 836996f

File tree

9 files changed

+87
-34
lines changed

9 files changed

+87
-34
lines changed

docs/overview.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ API
178178
- :meth:`web3.eth.waitForTransactionReceipt() <web3.eth.Eth.waitForTransactionReceipt>`
179179
- :meth:`web3.eth.get_transaction_receipt() <web3.eth.Eth.get_transaction_receipt>`
180180
- :meth:`web3.eth.sign() <web3.eth.Eth.sign>`
181-
- :meth:`web3.eth.signTypedData() <web3.eth.Eth.signTypedData>`
181+
- :meth:`web3.eth.sign_typed_data() <web3.eth.Eth.sign_typed_data>`
182182
- :meth:`web3.eth.estimateGas() <web3.eth.Eth.estimateGas>`
183183
- :meth:`web3.eth.generateGasPrice() <web3.eth.Eth.generateGasPrice>`
184184
- :meth:`web3.eth.setGasPriceStrategy() <web3.eth.Eth.setGasPriceStrategy>`

docs/web3.eth.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,7 @@ The following methods are available on the ``web3.eth`` namespace.
902902
'0x1a8bbe6eab8c72a219385681efefe565afd3accee35f516f8edf5ae82208fbd45a58f9f9116d8d88ba40fcd29076d6eada7027a3b412a9db55a0164547810cc401'
903903
904904
905-
.. py:method:: Eth.signTypedData(account, jsonMessage)
905+
.. py:method:: Eth.sign_typed_data(account, jsonMessage)
906906
907907
* Delegates to ``eth_signTypedData`` RPC Method
908908

@@ -914,6 +914,10 @@ The following methods are available on the ``web3.eth`` namespace.
914914

915915
``account`` may be a checksum address or an ENS name
916916

917+
.. py:method:: Eth.signTypedData(account, jsonMessage)
918+
919+
.. warning:: Deprecated: This property is deprecated in favor of
920+
:meth:`~web3.eth.Eth.sign_typed_data()`
917921

918922
.. py:method:: Eth.call(transaction, block_identifier=web3.eth.default_block)
919923

newsfragments/1915.feature.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add ``w3.eth.sign_typed_data`` deprecate ``w3.eth.signTypedData``

tests/integration/go_ethereum/common.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,16 @@ def test_eth_replace_transaction_already_mined(self, web3, unlocked_account_dual
4040
web3.geth.miner.stop()
4141

4242
@pytest.mark.xfail(reason='eth_signTypedData has not been released in geth')
43-
def test_eth_signTypedData(self,
44-
web3,
45-
unlocked_account_dual_type):
46-
super().test_eth_signTypedData(
47-
web3, unlocked_account_dual_type
48-
)
43+
def test_eth_sign_typed_data(self, web3, unlocked_account_dual_type):
44+
super().test_eth_sign_typed_data(web3, unlocked_account_dual_type)
4945

5046
@pytest.mark.xfail(reason='eth_signTypedData has not been released in geth')
51-
def test_invalid_eth_signTypedData(self,
52-
web3,
53-
unlocked_account_dual_type):
54-
super().test_invalid_eth_signTypedData(
55-
web3, unlocked_account_dual_type
56-
)
47+
def test_eth_signTypedData_deprecated(self, web3, unlocked_account_dual_type):
48+
super().test_eth_signTypedData_deprecated(web3, unlocked_account_dual_type)
49+
50+
@pytest.mark.xfail(reason='eth_signTypedData has not been released in geth')
51+
def test_invalid_eth_sign_typed_data(self, web3, unlocked_account_dual_type):
52+
super().test_invalid_eth_sign_typed_data(web3, unlocked_account_dual_type)
5753

5854
@pytest.mark.xfail(reason='eth_protocolVersion was removed in Geth 1.10.0')
5955
def test_eth_protocol_version(self, web3):

tests/integration/parity/common.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -151,20 +151,12 @@ def test_eth_get_logs_without_logs(self, web3, block_with_txn_with_log):
151151
assert len(result) == 0
152152

153153
@pytest.mark.xfail(reason='eth_signTypedData has not been released in Parity')
154-
def test_eth_signTypedData(self,
155-
web3,
156-
unlocked_account_dual_type):
157-
super().test_eth_signTypedData(
158-
web3, unlocked_account_dual_type
159-
)
154+
def test_eth_sign_typed_data(self, web3, unlocked_account_dual_type):
155+
super().test_eth_sign_typed_data(web3, unlocked_account_dual_type)
160156

161157
@pytest.mark.xfail(reason='eth_signTypedData has not been released in Parity')
162-
def test_invalid_eth_signTypedData(self,
163-
web3,
164-
unlocked_account_dual_type):
165-
super().test_invalid_eth_signTypedData(
166-
web3, unlocked_account_dual_type
167-
)
158+
def test_invalid_eth_sign_typed_data(self, web3, unlocked_account_dual_type):
159+
super().test_invalid_eth_sign_typed_data(web3, unlocked_account_dual_type)
168160

169161

170162
class ParityTraceModuleTest(ParityTraceModuleTest):

tests/integration/test_ethereum_tester.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,14 @@ class TestEthereumTesterEthModule(EthModuleTest):
242242
test_eth_sign_ens_names = not_implemented(
243243
EthModuleTest.test_eth_sign_ens_names, ValueError
244244
)
245-
test_eth_signTypedData = not_implemented(EthModuleTest.test_eth_signTypedData, ValueError)
245+
test_eth_signTypedData_deprecated = not_implemented(
246+
EthModuleTest.test_eth_signTypedData_deprecated,
247+
ValueError
248+
)
249+
test_eth_sign_typed_data = not_implemented(
250+
EthModuleTest.test_eth_sign_typed_data,
251+
ValueError
252+
)
246253
test_eth_signTransaction_deprecated = not_implemented(
247254
EthModuleTest.test_eth_signTransaction_deprecated,
248255
ValueError

web3/_utils/module_testing/eth_module.py

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,59 @@ def test_eth_sign_ens_names(
412412
assert is_bytes(signature)
413413
assert len(signature) == 32 + 32 + 1
414414

415-
def test_eth_signTypedData(
415+
def test_eth_sign_typed_data(
416+
self,
417+
web3: "Web3",
418+
unlocked_account_dual_type: ChecksumAddress,
419+
skip_if_testrpc: Callable[["Web3"], None],
420+
) -> None:
421+
validJSONMessage = '''
422+
{
423+
"types": {
424+
"EIP712Domain": [
425+
{"name": "name", "type": "string"},
426+
{"name": "version", "type": "string"},
427+
{"name": "chainId", "type": "uint256"},
428+
{"name": "verifyingContract", "type": "address"}
429+
],
430+
"Person": [
431+
{"name": "name", "type": "string"},
432+
{"name": "wallet", "type": "address"}
433+
],
434+
"Mail": [
435+
{"name": "from", "type": "Person"},
436+
{"name": "to", "type": "Person"},
437+
{"name": "contents", "type": "string"}
438+
]
439+
},
440+
"primaryType": "Mail",
441+
"domain": {
442+
"name": "Ether Mail",
443+
"version": "1",
444+
"chainId": "0x01",
445+
"verifyingContract": "0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC"
446+
},
447+
"message": {
448+
"from": {
449+
"name": "Cow",
450+
"wallet": "0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826"
451+
},
452+
"to": {
453+
"name": "Bob",
454+
"wallet": "0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB"
455+
},
456+
"contents": "Hello, Bob!"
457+
}
458+
}
459+
'''
460+
skip_if_testrpc(web3)
461+
signature = HexBytes(web3.eth.sign_typed_data(
462+
unlocked_account_dual_type,
463+
json.loads(validJSONMessage)
464+
))
465+
assert len(signature) == 32 + 32 + 1
466+
467+
def test_eth_signTypedData_deprecated(
416468
self,
417469
web3: "Web3",
418470
unlocked_account_dual_type: ChecksumAddress,
@@ -464,7 +516,7 @@ def test_eth_signTypedData(
464516
))
465517
assert len(signature) == 32 + 32 + 1
466518

467-
def test_invalid_eth_signTypedData(
519+
def test_invalid_eth_sign_typed_data(
468520
self,
469521
web3: "Web3",
470522
unlocked_account_dual_type: ChecksumAddress,
@@ -512,7 +564,7 @@ def test_invalid_eth_signTypedData(
512564
'''
513565
with pytest.raises(ValueError,
514566
match=r".*Expected 2 items for array type Person\[2\], got 1 items.*"):
515-
web3.eth.signTypedData(
567+
web3.eth.sign_typed_data(
516568
unlocked_account_dual_type,
517569
json.loads(invalid_typed_message)
518570
)

web3/_utils/module_testing/personal_module.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ def test_personal_sign_typed_data_deprecated(
327327
}
328328
}
329329
'''
330-
signature = HexBytes(web3.geth.personal.signTypedData(
330+
signature = HexBytes(web3.geth.personal.sign_typed_data(
331331
json.loads(typed_message),
332332
unlockable_account_dual_type,
333333
unlockable_account_pw
@@ -639,7 +639,7 @@ def test_personal_sign_typed_data_deprecated(
639639
}
640640
}
641641
'''
642-
signature = HexBytes(web3.parity.personal.signTypedData(
642+
signature = HexBytes(web3.parity.personal.sign_typed_data(
643643
json.loads(typed_message),
644644
unlockable_account_dual_type,
645645
unlockable_account_pw
@@ -755,7 +755,7 @@ def test_invalid_personal_sign_typed_data_deprecated(
755755
with pytest.raises(ValueError,
756756
match=r".*Expected 2 items for array type Person\[2\], got 1 items.*"
757757
):
758-
web3.parity.personal.signTypedData(
758+
web3.parity.personal.sign_typed_data(
759759
json.loads(invalid_typed_message),
760760
unlockable_account_dual_type,
761761
unlockable_account_pw

web3/eth.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ def sign_munger(
513513
mungers=[default_root_munger],
514514
)
515515

516-
signTypedData: Method[Callable[..., HexStr]] = Method(
516+
sign_typed_data: Method[Callable[..., HexStr]] = Method(
517517
RPC.eth_signTypedData,
518518
mungers=[default_root_munger],
519519
)
@@ -689,6 +689,7 @@ def setGasPriceStrategy(self, gas_price_strategy: GasPriceStrategy) -> None:
689689
getUncleCount = DeprecatedMethod(get_uncle_count, 'getUncleCount', 'get_uncle_count')
690690
sendTransaction = DeprecatedMethod(send_transaction, 'sendTransaction', 'send_transaction')
691691
signTransaction = DeprecatedMethod(sign_transaction, 'signTransaction', 'sign_transaction')
692+
signTypedData = DeprecatedMethod(sign_typed_data, 'signTypedData', 'sign_typed_data')
692693
submitHashrate = DeprecatedMethod(submit_hashrate, 'submitHashrate', 'submit_hashrate')
693694
submitWork = DeprecatedMethod(submit_work, 'submitWork', 'submit_work')
694695
getLogs = DeprecatedMethod(get_logs, 'getLogs', 'get_logs')

0 commit comments

Comments
 (0)