added chain ID check to avoid replay attacks
This commit is contained in:
parent
d220e615e9
commit
2e99f9c588
@ -15,7 +15,7 @@
|
||||
Chamado pelo vendedor antes de fazer `deposit` no smart contract.
|
||||
|
||||
#### Parametros requeridos:
|
||||
- `nomeParticipante`
|
||||
- `chainID`
|
||||
- `tipoDocumento`
|
||||
- `numeroDocumento`
|
||||
- `numeroConta`
|
||||
@ -26,12 +26,13 @@ curl --request POST \
|
||||
--url http://localhost:5000/register \
|
||||
--header 'content-type: application/json' \
|
||||
--data '{
|
||||
"nomeParticipante": "João Silva",
|
||||
"chainID": "1337",
|
||||
"tipoDocumento": 1,
|
||||
"numeroDocumento": 12345678900,
|
||||
"numeroConta": 1234567890123456,
|
||||
"numeroAgencia": 123,
|
||||
"tipoConta": 1
|
||||
"tipoConta": 1,
|
||||
"codigoIspb": 0
|
||||
}'
|
||||
```
|
||||
#### Retorna em formato JSON:
|
||||
@ -64,7 +65,7 @@ Chamado pelo comprador após pagar o Pix
|
||||
curl http://localhost:5000/release/123
|
||||
```
|
||||
#### Retorna em formato JSON:
|
||||
- `pixTarget`
|
||||
- `chainid`-`pixTarget`
|
||||
- `amount`: valor em wei
|
||||
- `pixTimestamp`
|
||||
- `signature`: assinatura ethereum compatível
|
||||
|
14
bbpay.py
14
bbpay.py
@ -59,7 +59,7 @@ class Register(BBPay):
|
||||
data = request.get_json()
|
||||
body = {
|
||||
'numeroConvenio': 701,
|
||||
'nomeParticipante': data['nomeParticipante'],
|
||||
'nomeParticipante': data['chainID'],
|
||||
'tipoDocumento': data['tipoDocumento'],
|
||||
'numeroDocumento': data['numeroDocumento'],
|
||||
'numeroConta': data['numeroConta'],
|
||||
@ -116,15 +116,19 @@ class Release(BBPay):
|
||||
pixTimestamp = b85decode(data['informacoesPix']['txId'])
|
||||
valorSolicitacao = to_wei(data['valorSolicitacao'], 'ether')
|
||||
codigoEstadoSolicitacao = data['codigoEstadoSolicitacao']
|
||||
if codigoEstadoSolicitacao != 0:
|
||||
if codigoEstadoSolicitacao != 1:
|
||||
return 'Pix not paid', 204
|
||||
response = self.oauth.get(
|
||||
self.baseUrl+f"/participantes/{numeroParticipante}",
|
||||
params=self.params,
|
||||
verify=self.verify_ssl)
|
||||
chainID = response.json()['nomeParticipante']
|
||||
packed = encode_packed(['bytes32','uint80','bytes32'],
|
||||
(str(numeroParticipante).encode(), int(valorSolicitacao), pixTimestamp) )
|
||||
|
||||
(f"{chainID}-{numeroParticipante}".encode(), int(valorSolicitacao), pixTimestamp) )
|
||||
signable = eth_account.messages.encode_defunct(keccak(packed))
|
||||
signature = eth_account.account.Account.sign_message(signable, private_key=getenv('PRIVATE_KEY')).signature.hex()
|
||||
return {
|
||||
'pixTarget': str(numeroParticipante),
|
||||
'pixTarget': f"{chainID}-{numeroParticipante}",
|
||||
'amount': str(valorSolicitacao),
|
||||
'pixTimestamp': pixTimestamp.hex(),
|
||||
'signature': signature }
|
||||
|
Loading…
x
Reference in New Issue
Block a user