chore(walletconnect): adapting to improvements done on the statusgo side

This commit is contained in:
Sale Djenic 2023-12-01 17:58:58 +01:00 committed by saledjenic
parent ba60c711f7
commit c5d1d5b77d
7 changed files with 65 additions and 68 deletions

View File

@ -1,17 +1,19 @@
import NimQml, strutils, logging, json, options
import backend/wallet_connect as backend
import backend/wallet as backend_wallet
import backend/wallet_connect as backend_wallet_connect
import app/global/global_singleton
import app/core/eventemitter
import app/core/signals/types
import app_service/common/utils as common_utils
from app_service/service/transaction/dto import PendingTransactionTypeDto
import app/modules/shared_modules/keycard_popup/io_interface as keycard_shared_module
import constants
import session_response_dto, helper
import tx_response_dto, helper
const UNIQUE_WALLET_CONNECT_MODULE_SIGNING_IDENTIFIER* = "WalletConnect-Signing"
@ -20,6 +22,7 @@ QtObject:
Controller* = ref object of QObject
events: EventEmitter
sessionRequestJson: JsonNode
txResponseDto: TxResponseDto
hasActivePairings: Option[bool]
## Forward declarations
@ -61,7 +64,7 @@ QtObject:
proc pairSessionProposal(self: Controller, sessionProposalJson: string) {.slot.} =
var res: JsonNode
let err = backend.pair(res, sessionProposalJson)
let err = backend_wallet_connect.pair(res, sessionProposalJson)
if err.len > 0:
error "Failed to pair session"
return
@ -70,20 +73,20 @@ QtObject:
self.proposeUserPair(sessionProposalJson, supportedNamespacesJson)
proc recordSuccessfulPairing(self: Controller, sessionProposalJson: string) {.slot.} =
if backend.recordSuccessfulPairing(sessionProposalJson):
if backend_wallet_connect.recordSuccessfulPairing(sessionProposalJson):
if not self.hasActivePairings.get(false):
self.hasActivePairings = some(true)
proc deletePairing(self: Controller, topic: string) {.slot.} =
if backend.deletePairing(topic):
if backend_wallet_connect.deletePairing(topic):
if self.hasActivePairings.get(false):
self.hasActivePairings = some(backend.hasActivePairings())
self.hasActivePairings = some(backend_wallet_connect.hasActivePairings())
else:
error "Failed to delete pairing"
proc getHasActivePairings*(self: Controller): bool {.slot.} =
if self.hasActivePairings.isNone:
self.hasActivePairings = some(backend.hasActivePairings())
self.hasActivePairings = some(backend_wallet_connect.hasActivePairings())
return self.hasActivePairings.get(false)
QtProperty[bool] hasActivePairings:
@ -93,23 +96,25 @@ QtObject:
proc sendTransactionAndRespond(self: Controller, signature: string) =
let finalSignature = singletonInstance.utils.removeHexPrefix(signature)
var res: JsonNode
let err = backend.sendTransactionWithSignature(res, finalSignature)
if err.len > 0:
var txResponse: JsonNode
let err = backend_wallet.sendTransactionWithSignature(txResponse, self.txResponseDto.chainId,
$PendingTransactionTypeDto.WalletConnectTransfer, $self.txResponseDto.txArgsJson, finalSignature)
if err.len > 0 or txResponse.isNil:
error "Failed to send tx"
return
let txHash = res.getStr
let txHash = txResponse.getStr
self.respondSessionRequest($self.sessionRequestJson, txHash, false)
proc buildRawTransactionAndRespond(self: Controller, signature: string) =
let finalSignature = singletonInstance.utils.removeHexPrefix(signature)
var res: JsonNode
let err = backend.buildRawTransaction(res, finalSignature)
var txResponse: JsonNode
let err = backend_wallet.buildRawTransaction(txResponse, self.txResponseDto.chainId, $self.txResponseDto.txArgsJson,
finalSignature)
if err.len > 0:
error "Failed to send tx"
error "Failed to build raw tx"
return
let txHash = res.getStr
self.respondSessionRequest($self.sessionRequestJson, txHash, false)
let txResponseDto = txResponse.toTxResponseDto()
self.respondSessionRequest($self.sessionRequestJson, txResponseDto.rawTx, false)
proc finishSessionRequest(self: Controller, signature: string) =
let requestMethod = getRequestMethod(self.sessionRequestJson)
@ -130,25 +135,25 @@ QtObject:
try:
self.sessionRequestJson = parseJson(sessionRequestJson)
var sessionRes: JsonNode
let err = backend.sessionRequest(sessionRes, sessionRequestJson)
let err = backend_wallet_connect.sessionRequest(sessionRes, sessionRequestJson)
if err.len > 0:
error "Failed to request a session"
self.respondSessionRequest($sessionRequestJson, "", true)
self.respondSessionRequest(sessionRequestJson, "", true)
return
let sessionResponseDto = sessionRes.toSessionResponseDto()
if sessionResponseDto.signOnKeycard:
self.txResponseDto = sessionRes.toTxResponseDto()
if self.txResponseDto.signOnKeycard:
let data = SharedKeycarModuleSigningArgs(uniqueIdentifier: UNIQUE_WALLET_CONNECT_MODULE_SIGNING_IDENTIFIER,
keyUid: sessionResponseDto.keyUid,
path: sessionResponseDto.addressPath,
dataToSign: singletonInstance.utils.removeHexPrefix(sessionResponseDto.messageToSign))
keyUid: self.txResponseDto.keyUid,
path: self.txResponseDto.addressPath,
dataToSign: singletonInstance.utils.removeHexPrefix(self.txResponseDto.messageToSign))
self.events.emit(SIGNAL_SHARED_KEYCARD_MODULE_SIGN_DATA, data)
else:
let hashedPasssword = common_utils.hashPassword(password)
var signMsgRes: JsonNode
let err = backend.signMessage(signMsgRes,
sessionResponseDto.messageToSign,
sessionResponseDto.address,
let err = backend_wallet.signMessage(signMsgRes,
self.txResponseDto.messageToSign,
self.txResponseDto.address,
hashedPasssword)
if err.len > 0:
error "Failed to sign message on statusgo side"

View File

@ -3,19 +3,25 @@ import json
include app_service/common/json_utils
type
SessionResponseDto* = ref object
TxResponseDto* = ref object
keyUid*: string
address*: string
addressPath*: string
signOnKeycard*: bool
chainId*: int
messageToSign*: string
signedMessage*: string
txArgsJson*: JsonNode
rawTx*: string
txHash*: string
proc toSessionResponseDto*(jsonObj: JsonNode): SessionResponseDto =
result = SessionResponseDto()
proc toTxResponseDto*(jsonObj: JsonNode): TxResponseDto =
result = TxResponseDto()
discard jsonObj.getProp("keyUid", result.keyUid)
discard jsonObj.getProp("address", result.address)
discard jsonObj.getProp("addressPath", result.addressPath)
discard jsonObj.getProp("signOnKeycard", result.signOnKeycard)
discard jsonObj.getProp("chainId", result.chainId)
discard jsonObj.getProp("messageToSign", result.messageToSign)
discard jsonObj.getProp("signedMessage", result.signedMessage)
discard jsonObj.getProp("txArgs", result.txArgsJson)
discard jsonObj.getProp("rawTx", result.rawTx)
discard jsonObj.getProp("txHash", result.txHash)

View File

@ -338,7 +338,7 @@ QtObject:
if data.eventType == collectibles_backend.eventCommunityCollectiblesReceived:
self.processReceivedCollectiblesWalletEvent(data.message)
self.events.on(PendingTransactionTypeDto.SetSigner.event) do(e: Args):
self.events.on(PendingTransactionTypeDto.SetSignerPublicKey.event) do(e: Args):
let receivedData = TransactionMinedArgs(e)
self.processSetSignerTransactionEvent(receivedData)
@ -999,7 +999,7 @@ QtObject:
transactionHash,
addressFrom,
contractAddress,
$PendingTransactionTypeDto.SetSigner,
$PendingTransactionTypeDto.SetSignerPublicKey,
$(%contractDetails),
chainId,
)

View File

@ -32,6 +32,7 @@ type
BurnCommunityToken = "BurnCommunityToken"
DeployOwnerToken = "DeployOwnerToken"
SetSignerPublicKey = "SetSignerPublicKey"
WalletConnectTransfer = "WalletConnectTransfer"
proc event*(self:PendingTransactionTypeDto):string =
result = "transaction:" & $self

View File

@ -12,6 +12,11 @@ rpc(buildTransaction, "wallet"):
chainId: int
sendTxArgsJson: string
rpc(buildRawTransaction, "wallet"):
chainId: int
sendTxArgsJson: string
signature: string
rpc(sendTransactionWithSignature, "wallet"):
chainId: int
txType: string
@ -59,6 +64,20 @@ proc buildTransaction*(resultOut: var JsonNode, chainId: int, sendTxArgsJson: st
return e.msg
## Builds the raw tx with the provided tx args, chain id and signature
## `resultOut` represents a json object that corresponds to the status go `transfer.TxResponse` type, or `nil` if the call was unsuccessful
## `chainId` is the chain id of the network
## `txArgsJSON` is the json string of the tx, corresponds to the status go `transactions.SendTxArgs` type
## `signature` is the signature of the tx
## returns the error message if any, or an empty string
proc buildRawTransaction*(resultOut: var JsonNode, chainId: int, sendTxArgsJson: string, signature: string): string =
try:
let response = buildRawTransaction(chainId, sendTxArgsJson, signature)
return prepareResponse(resultOut, response)
except Exception as e:
warn e.msg
return e.msg
## Sends the tx with signature on provided chain, setting tx type
## `resultOut` represents a json object that contains the tx hash if the call was successful, or `nil`
## `chainId` is the chain id of the network

View File

@ -19,8 +19,6 @@ rpc(wCSignMessage, "wallet"):
rpc(wCBuildRawTransaction, "wallet"):
signature: string
rpc(wCSendRawTransaction, "wallet"):
rawTx: string
rpc(wCSendTransactionWithSignature, "wallet"):
signature: string
@ -52,38 +50,6 @@ proc prepareResponse(res: var JsonNode, rpcResponse: RpcResponse[JsonNode]): str
return "no result"
res = rpcResponse.result
proc signMessage*(res: var JsonNode, message: string, address: string, password: string): string =
try:
let response = wCSignMessage(message, address, password)
return prepareResponse(res, response)
except Exception as e:
warn e.msg
return e.msg
proc buildRawTransaction*(res: var JsonNode, signature: string): string =
try:
let response = wCBuildRawTransaction(signature)
return prepareResponse(res, response)
except Exception as e:
warn e.msg
return e.msg
proc sendRawTransaction*(res: var JsonNode, rawTx: string): string =
try:
let response = wCSendRawTransaction(rawTx)
return prepareResponse(res, response)
except Exception as e:
warn e.msg
return e.msg
proc sendTransactionWithSignature*(res: var JsonNode, signature: string): string =
try:
let response = wCSendTransactionWithSignature(signature)
return prepareResponse(res, response)
except Exception as e:
warn e.msg
return e.msg
# TODO #12434: async answer
proc pair*(res: var JsonNode, sessionProposalJson: string): string =
try:

2
vendor/status-go vendored

@ -1 +1 @@
Subproject commit 9acabc69955b6a1884154a133083e62f05406892
Subproject commit cfa542378d974c3628ba5f545e4a1610818bd24a