Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(wallet) integrate Wallet Connect sign APIs #12716

Merged
merged 1 commit into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
632 changes: 626 additions & 6 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@
"engines": {
"node": ">=10",
"npm": ">=7"
},
"dependencies": {
"nodemon": "3.0.1"
}
}
16 changes: 16 additions & 0 deletions src/app/modules/main/wallet_section/wallet_connect/controller.nim
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import backend/wallet_connect as backend
import app/core/eventemitter
import app/core/signals/types

import app_service/common/utils as common_utils

import constants

QtObject:
Expand Down Expand Up @@ -45,6 +47,20 @@ QtObject:
if not ok:
error "Failed to pair session"

proc respondSessionRequest*(self: Controller, sessionRequestJson: string, signedJson: string, error: bool) {.signal.}

proc sessionRequest*(self: Controller, sessionRequestJson: string, password: string) {.slot.} =
let hashedPasssword = common_utils.hashPassword(password)
let ok = backend.sessionRequest(sessionRequestJson, hashedPasssword, proc (res: JsonNode) =
let sessionRequestJson = if res.hasKey("sessionRequest"): $res["sessionRequest"] else: ""
let signedJson = if res.hasKey("signed"): $res["signed"] else: ""

self.respondSessionRequest(sessionRequestJson, signedJson, false)
)

if not ok:
self.respondSessionRequest(sessionRequestJson, "", true)

proc getProjectId*(self: Controller): string {.slot.} =
return constants.WALLET_CONNECT_PROJECT_ID

Expand Down
18 changes: 16 additions & 2 deletions src/backend/wallet_connect.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import options
import options, logging
import json
import core, response_type

Expand All @@ -14,6 +14,10 @@ const ErrorChainsNotSupported*: string = "chains not supported"
rpc(wCPairSessionProposal, "wallet"):
sessionProposalJson: string

rpc(wCSessionRequest, "wallet"):
sessionRequestJson: string
hashedPassword: string

# TODO #12434: async answer
proc pair*(sessionProposalJson: string, callback: proc(response: JsonNode): void): bool =
try:
Expand All @@ -22,5 +26,15 @@ proc pair*(sessionProposalJson: string, callback: proc(response: JsonNode): void
callback(response.result)
return response.error == nil
except Exception as e:
echo "@dd wCPairSessionProposal response: ", e.msg
warn e.msg
return false

proc sessionRequest*(sessionRequestJson: string, hashedPassword: string, callback: proc(response: JsonNode): void): bool =
try:
let response = wCSessionRequest(sessionRequestJson, hashedPassword)
if response.error == nil and response.result != nil:
callback(response.result)
return response.error == nil
except Exception as e:
warn e.msg
return false
13 changes: 12 additions & 1 deletion storybook/pages/WalletConnectPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@ Item {
pairSessionProposal: function(sessionProposalJson) {
proposeUserPair(sessionProposalJson, `{"eip155":{"methods":["eth_sendTransaction","personal_sign"],"chains":["eip155:5"],"events":["accountsChanged","chainChanged"],"accounts":["eip155:5:0x53780d79E83876dAA21beB8AFa87fd64CC29990b","eip155:5:0xBd54A96c0Ae19a220C8E1234f54c940DFAB34639","eip155:5:0x5D7905390b77A937Ae8c444aA8BF7Fa9a6A7DBA0"]}}`)
}
projectId: SystemUtils.getEnvVar("STATUS_BUILD_WALLET_CONNECT_PROJECT_ID")

sessionRequest: function(sessionRequestJson, password) {
const signedJson = "0x1234567890"
this.respondSessionRequest(sessionRequestJson, signedJson, respondError.checked)
}

projectId: "87815d72a81d739d2a7ce15c2cfdefb3"
}

clip: true
Expand All @@ -58,6 +64,11 @@ Item {
font.bold: true
}
}
CheckBox {
id: respondError
text: "Respond Error"
checked: false
}
// spacer
ColumnLayout {}
}
Expand Down
6 changes: 6 additions & 0 deletions storybook/stubs/nim/WalletConnectController.qml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,11 @@ Item {
// function pairSessionProposal(/*string*/ sessionProposalJson)
required property var pairSessionProposal

signal respondSessionRequest(string sessionRequestJson, string signedJson, bool error)

// function sessionRequest(/*string*/ sessionRequestJson, /*string*/ password)
required property var sessionRequest


required property string projectId
}
8 changes: 4 additions & 4 deletions test/go/test-wallet_connect/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1977,8 +1977,8 @@ github.com/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/y
github.com/spf13/viper v1.7.0/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg=
github.com/status-im/doubleratchet v3.0.0+incompatible h1:aJ1ejcSERpSzmWZBgtfYtiU2nF0Q8ZkGyuEPYETXkCY=
github.com/status-im/doubleratchet v3.0.0+incompatible/go.mod h1:1sqR0+yhiM/bd+wrdX79AOt2csZuJOni0nUDzKNuqOU=
github.com/status-im/go-ethereum v1.10.25-status.9 h1:NDuRs5TC4JjqPcYE8/sUtspdA+OwV1JRy3bbRLdIcL0=
github.com/status-im/go-ethereum v1.10.25-status.9/go.mod h1:Dt4K5JYMhJRdtXJwBEyGZLZn9iz/chSOZyjVmt5ZhwQ=
github.com/status-im/go-ethereum v1.10.25-status.11 h1:casDsgnrkXzyO9SQVyFsT+63XuInyFXzfEHRW/9eEVY=
github.com/status-im/go-ethereum v1.10.25-status.11/go.mod h1:Dt4K5JYMhJRdtXJwBEyGZLZn9iz/chSOZyjVmt5ZhwQ=
github.com/status-im/go-multiaddr-ethv4 v1.2.5 h1:pN+ey6wYKbvNNu5/xq9+VL0N8Yq0pZUTbZp0URg+Yn4=
github.com/status-im/go-multiaddr-ethv4 v1.2.5/go.mod h1:Fhe/18yWU5QwlAYiOO3Bb1BLe0bn5YobcNBHsjRr4kk=
github.com/status-im/go-sqlcipher/v4 v4.5.4-status.2 h1:Oi9JTAI2DZEe5UKlpUcvKBCCSn3ULsLIrix7jPnEoPE=
Expand Down Expand Up @@ -2088,8 +2088,8 @@ github.com/waku-org/go-discover v0.0.0-20221209174356-61c833f34d98 h1:xwY0kW5XZF
github.com/waku-org/go-discover v0.0.0-20221209174356-61c833f34d98/go.mod h1:eBHgM6T4EG0RZzxpxKy+rGz/6Dw2Nd8DWxS0lm9ESDw=
github.com/waku-org/go-libp2p-rendezvous v0.0.0-20230628220917-7b4e5ae4c0e7 h1:0e1h+p84yBp0IN7AqgbZlV7lgFBjm214lgSOE7CeJmE=
github.com/waku-org/go-libp2p-rendezvous v0.0.0-20230628220917-7b4e5ae4c0e7/go.mod h1:pFvOZ9YTFsW0o5zJW7a0B5tr1owAijRWJctXJ2toL04=
github.com/waku-org/go-waku v0.8.1-0.20230930175749-dcc828749f67 h1:EL0KljfCIFPXbY1IfT0JjVIjJekuF951ys1WL2WnWyM=
github.com/waku-org/go-waku v0.8.1-0.20230930175749-dcc828749f67/go.mod h1:MnMLFtym7XUt+GNN4zTkjm5NJCsm7TERLWVPOV/Ct6w=
github.com/waku-org/go-waku v0.8.1-0.20231103161423-351dd55a1498 h1:2Y06Ni3tBj2LQA0ys1o1PspZxZPM9GOKwNEGolbueQ4=
github.com/waku-org/go-waku v0.8.1-0.20231103161423-351dd55a1498/go.mod h1:hem2hnXK5BdabxwJULszM0Rh1Yj+gD9IxjwLCGPPaxs=
github.com/waku-org/go-zerokit-rln v0.1.14-0.20230916173259-d284a3d8f2fd h1:cu7CsUo7BK6ac/v193RIaqAzUcmpa6MNY4xYW9AenQI=
github.com/waku-org/go-zerokit-rln v0.1.14-0.20230916173259-d284a3d8f2fd/go.mod h1:1PdBdPzyTaKt3VnpAHk3zj+r9dXPFOr3IHZP9nFle6E=
github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230916172309-ee0ee61dde2b h1:KgZVhsLkxsj5gb/FfndSCQu6VYwALrCOgYI3poR95yE=
Expand Down
Loading