@@ -15,26 +15,18 @@ use bdk::{
15
15
} ;
16
16
use jsonrpsee:: { core:: async_trait, proc_macros:: rpc, server:: Server , types:: ErrorObjectOwned } ;
17
17
use log:: info;
18
- use protocol:: {
19
- bitcoin,
20
- bitcoin:: {
21
- bip32:: Xpriv ,
22
- Network :: { Regtest , Testnet } ,
23
- OutPoint ,
24
- } ,
25
- constants:: ChainAnchor ,
26
- hasher:: { BaseHash , KeyHasher , SpaceKey } ,
27
- prepare:: DataSource ,
28
- slabel:: SLabel ,
29
- validate:: TxChangeSet ,
30
- FullSpaceOut , SpaceOut ,
31
- } ;
18
+ use protocol:: { bitcoin, bitcoin:: {
19
+ bip32:: Xpriv ,
20
+ Network :: { Regtest , Testnet } ,
21
+ OutPoint ,
22
+ } , constants:: ChainAnchor , hasher:: { BaseHash , KeyHasher , SpaceKey } , prepare:: DataSource , slabel:: SLabel , validate:: TxChangeSet , Bytes , FullSpaceOut , SpaceOut } ;
32
23
use serde:: { Deserialize , Serialize } ;
33
24
use tokio:: {
34
25
select,
35
26
sync:: { broadcast, mpsc, oneshot, RwLock } ,
36
27
task:: JoinSet ,
37
28
} ;
29
+ use protocol:: bitcoin:: secp256k1;
38
30
use wallet:: { bdk_wallet as bdk, bdk_wallet:: template:: Bip86 , bitcoin:: hashes:: Hash , export:: WalletExport , Balance , DoubleUtxo , Listing , SpacesWallet , WalletConfig , WalletDescriptors , WalletInfo , WalletOutput } ;
39
31
40
32
use crate :: {
@@ -58,6 +50,13 @@ pub struct ServerInfo {
58
50
pub tip : ChainAnchor ,
59
51
}
60
52
53
+ #[ derive( Debug , Clone , Serialize , Deserialize ) ]
54
+ pub struct SignedMessage {
55
+ pub space : String ,
56
+ pub message : protocol:: Bytes ,
57
+ pub signature : secp256k1:: schnorr:: Signature ,
58
+ }
59
+
61
60
pub enum ChainStateCommand {
62
61
CheckPackage {
63
62
txs : Vec < String > ,
@@ -99,6 +98,10 @@ pub enum ChainStateCommand {
99
98
listing : Listing ,
100
99
resp : Responder < anyhow:: Result < ( ) > > ,
101
100
} ,
101
+ VerifyMessage {
102
+ msg : SignedMessage ,
103
+ resp : Responder < anyhow:: Result < ( ) > > ,
104
+ } ,
102
105
}
103
106
104
107
#[ derive( Clone ) ]
@@ -153,6 +156,12 @@ pub trait Rpc {
153
156
#[ method( name = "walletimport" ) ]
154
157
async fn wallet_import ( & self , wallet : WalletExport ) -> Result < ( ) , ErrorObjectOwned > ;
155
158
159
+ #[ method( name = "verifymessage" ) ]
160
+ async fn verify_message ( & self , msg : SignedMessage ) -> Result < ( ) , ErrorObjectOwned > ;
161
+
162
+ #[ method( name = "walletsignmessage" ) ]
163
+ async fn wallet_sign_message ( & self , wallet : & str , space : & str , msg : protocol:: Bytes ) -> Result < SignedMessage , ErrorObjectOwned > ;
164
+
156
165
#[ method( name = "walletgetinfo" ) ]
157
166
async fn wallet_get_info ( & self , name : & str ) -> Result < WalletInfo , ErrorObjectOwned > ;
158
167
@@ -797,13 +806,28 @@ impl RpcServer for RpcServerImpl {
797
806
. map_err ( |error| ErrorObjectOwned :: owned ( -1 , error. to_string ( ) , None :: < String > ) )
798
807
}
799
808
809
+ async fn wallet_sign_message ( & self , wallet : & str , space : & str , msg : Bytes ) -> Result < SignedMessage , ErrorObjectOwned > {
810
+ self . wallet ( & wallet)
811
+ . await ?
812
+ . send_sign_message ( space, msg)
813
+ . await
814
+ . map_err ( |error| ErrorObjectOwned :: owned ( -1 , error. to_string ( ) , None :: < String > ) )
815
+ }
816
+
800
817
async fn verify_listing ( & self , listing : Listing ) -> Result < ( ) , ErrorObjectOwned > {
801
818
self . store
802
819
. verify_listing ( listing)
803
820
. await
804
821
. map_err ( |error| ErrorObjectOwned :: owned ( -1 , error. to_string ( ) , None :: < String > ) )
805
822
}
806
823
824
+ async fn verify_message ( & self , msg : SignedMessage ) -> Result < ( ) , ErrorObjectOwned > {
825
+ self . store
826
+ . verify_message ( msg)
827
+ . await
828
+ . map_err ( |error| ErrorObjectOwned :: owned ( -1 , error. to_string ( ) , None :: < String > ) )
829
+ }
830
+
807
831
async fn wallet_list_transactions (
808
832
& self ,
809
833
wallet : & str ,
@@ -1006,6 +1030,11 @@ impl AsyncChainState {
1006
1030
ChainStateCommand :: VerifyListing { listing, resp } => {
1007
1031
_ = resp. send ( SpacesWallet :: verify_listing :: < Sha256 > ( chain_state, & listing) . map ( |_| ( ) ) ) ;
1008
1032
}
1033
+ ChainStateCommand :: VerifyMessage { msg, resp } => {
1034
+ _ = resp. send ( SpacesWallet :: verify_message :: < Sha256 > (
1035
+ chain_state, & msg. space , msg. message . as_slice ( ) , & msg. signature
1036
+ ) . map ( |_| ( ) ) ) ;
1037
+ }
1009
1038
}
1010
1039
}
1011
1040
@@ -1047,6 +1076,14 @@ impl AsyncChainState {
1047
1076
resp_rx. await ?
1048
1077
}
1049
1078
1079
+ pub async fn verify_message ( & self , msg : SignedMessage ) -> anyhow:: Result < ( ) > {
1080
+ let ( resp, resp_rx) = oneshot:: channel ( ) ;
1081
+ self . sender
1082
+ . send ( ChainStateCommand :: VerifyMessage { msg, resp } )
1083
+ . await ?;
1084
+ resp_rx. await ?
1085
+ }
1086
+
1050
1087
pub async fn get_rollout ( & self , target : usize ) -> anyhow:: Result < Vec < RolloutEntry > > {
1051
1088
let ( resp, resp_rx) = oneshot:: channel ( ) ;
1052
1089
self . sender
0 commit comments