2024-07-18 15:30:10 +00:00
|
|
|
package signal
|
|
|
|
|
2024-10-30 14:51:01 +00:00
|
|
|
import (
|
|
|
|
"github.com/status-im/status-go/eth-node/types"
|
|
|
|
)
|
|
|
|
|
2024-07-18 15:30:10 +00:00
|
|
|
const (
|
2024-08-06 19:28:55 +00:00
|
|
|
EventConnectorSendRequestAccounts = "connector.sendRequestAccounts"
|
|
|
|
EventConnectorSendTransaction = "connector.sendTransaction"
|
2024-08-13 09:11:24 +00:00
|
|
|
EventConnectorPersonalSign = "connector.personalSign"
|
2024-08-06 19:28:55 +00:00
|
|
|
EventConnectorDAppPermissionGranted = "connector.dAppPermissionGranted"
|
|
|
|
EventConnectorDAppPermissionRevoked = "connector.dAppPermissionRevoked"
|
2024-08-15 11:49:29 +00:00
|
|
|
EventConnectorDAppChainIdSwitched = "connector.dAppChainIdSwitched"
|
2024-07-18 15:30:10 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type ConnectorDApp struct {
|
|
|
|
URL string `json:"url"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
IconURL string `json:"iconUrl"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// ConnectorSendRequestAccountsSignal is triggered when a request for accounts is sent.
|
|
|
|
type ConnectorSendRequestAccountsSignal struct {
|
|
|
|
ConnectorDApp
|
|
|
|
RequestID string `json:"requestId"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// ConnectorSendTransactionSignal is triggered when a transaction is requested to be sent.
|
|
|
|
type ConnectorSendTransactionSignal struct {
|
|
|
|
ConnectorDApp
|
|
|
|
RequestID string `json:"requestId"`
|
|
|
|
ChainID uint64 `json:"chainId"`
|
|
|
|
TxArgs string `json:"txArgs"`
|
|
|
|
}
|
|
|
|
|
2024-10-30 14:51:01 +00:00
|
|
|
type ConnectorSendDappPermissionGrantedSignal struct {
|
|
|
|
ConnectorDApp
|
|
|
|
Chains []uint64 `json:"chains"`
|
|
|
|
SharedAccount types.Address `json:"sharedAccount"`
|
|
|
|
}
|
|
|
|
|
2024-08-13 09:11:24 +00:00
|
|
|
type ConnectorPersonalSignSignal struct {
|
|
|
|
ConnectorDApp
|
|
|
|
RequestID string `json:"requestId"`
|
|
|
|
Challenge string `json:"challenge"`
|
|
|
|
Address string `json:"address"`
|
|
|
|
}
|
|
|
|
|
2024-08-15 11:49:29 +00:00
|
|
|
type ConnectorDAppChainIdSwitchedSignal struct {
|
|
|
|
URL string `json:"url"`
|
|
|
|
ChainId string `json:"chainId"`
|
|
|
|
}
|
|
|
|
|
2024-07-18 15:30:10 +00:00
|
|
|
func SendConnectorSendRequestAccounts(dApp ConnectorDApp, requestID string) {
|
|
|
|
send(EventConnectorSendRequestAccounts, ConnectorSendRequestAccountsSignal{
|
|
|
|
ConnectorDApp: dApp,
|
|
|
|
RequestID: requestID,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func SendConnectorSendTransaction(dApp ConnectorDApp, chainID uint64, txArgs string, requestID string) {
|
|
|
|
send(EventConnectorSendTransaction, ConnectorSendTransactionSignal{
|
|
|
|
ConnectorDApp: dApp,
|
|
|
|
RequestID: requestID,
|
|
|
|
ChainID: chainID,
|
|
|
|
TxArgs: txArgs,
|
|
|
|
})
|
|
|
|
}
|
2024-08-06 19:28:55 +00:00
|
|
|
|
2024-08-13 09:11:24 +00:00
|
|
|
func SendConnectorPersonalSign(dApp ConnectorDApp, requestID, challenge, address string) {
|
|
|
|
send(EventConnectorPersonalSign, ConnectorPersonalSignSignal{
|
|
|
|
ConnectorDApp: dApp,
|
|
|
|
RequestID: requestID,
|
|
|
|
Challenge: challenge,
|
|
|
|
Address: address,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-10-30 14:51:01 +00:00
|
|
|
func SendConnectorDAppPermissionGranted(dApp ConnectorDApp, account types.Address, chains []uint64) {
|
|
|
|
send(EventConnectorDAppPermissionGranted, ConnectorSendDappPermissionGrantedSignal{
|
|
|
|
ConnectorDApp: dApp,
|
|
|
|
Chains: chains,
|
|
|
|
SharedAccount: account,
|
|
|
|
})
|
2024-08-06 19:28:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func SendConnectorDAppPermissionRevoked(dApp ConnectorDApp) {
|
|
|
|
send(EventConnectorDAppPermissionRevoked, dApp)
|
|
|
|
}
|
2024-08-15 11:49:29 +00:00
|
|
|
|
|
|
|
func SendConnectorDAppChainIdSwitched(payload ConnectorDAppChainIdSwitchedSignal) {
|
|
|
|
send(EventConnectorDAppChainIdSwitched, payload)
|
|
|
|
}
|