@@ -1105,3 +1105,76 @@ func (m *Manager) publishPendingWithdrawals(ctx context.Context) error {
11051105
11061106 return nil
11071107}
1108+
1109+ // RevealDepositKeys reveals the internal keys for the given deposit IDs to
1110+ // the swap server.
1111+ func (m * Manager ) RevealDepositKeys (ctx context.Context ,
1112+ depositIDs []string ) error {
1113+
1114+ done , err := m .scheduleNextCall ()
1115+ if err != nil {
1116+ return err
1117+ }
1118+ defer done ()
1119+
1120+ // First check that all requested deposits are in the required state and
1121+ // collect the keys.
1122+ keys := make (map [string ][]byte , len (depositIDs ))
1123+ for _ , depositID := range depositIDs {
1124+ d , ok := m .deposits [depositID ]
1125+ if ! ok {
1126+ log .Warnf ("Can't reveal key for deposit %v as it is " +
1127+ "not active" , depositID )
1128+ }
1129+
1130+ if d .State != StateConfirmed && d .State != StateKeyRevealed {
1131+ return fmt .Errorf ("deposit %v key cannot be revealed" ,
1132+ depositID )
1133+ }
1134+
1135+ internalPubKey , internalPrivKey , err := DeriveSharedDepositKey (
1136+ ctx , m .signer , d .FunderScriptKey ,
1137+ )
1138+ if err != nil {
1139+ return err
1140+ }
1141+
1142+ if ! d .FunderInternalKey .IsEqual (internalPubKey ) {
1143+ log .Errorf ("Funder internal key %x does not match " +
1144+ "expected %x for deposit %v" ,
1145+ d .FunderInternalKey .SerializeCompressed (),
1146+ internalPubKey .SerializeCompressed (), depositID )
1147+
1148+ return fmt .Errorf ("funder internal key mismatch" )
1149+ }
1150+
1151+ keys [depositID ] = internalPrivKey .Serialize ()
1152+ }
1153+
1154+ // Update the deposit state before we actually push the keys to the
1155+ // server. Otherwise we may fail to update the state in our database,
1156+ // despite the server accepting the keys.
1157+ for depositID := range keys {
1158+ d := m .deposits [depositID ]
1159+ d .State = StateKeyRevealed
1160+ err = m .handleDepositStateUpdate (ctx , d )
1161+ if err != nil {
1162+ return err
1163+ }
1164+
1165+ log .Infof ("Revealing deposit key for %v: pub=%x" , depositID ,
1166+ d .FunderInternalKey .SerializeCompressed ())
1167+ }
1168+
1169+ // Now push the keys to the server.
1170+ _ , err = m .depositServiceClient .PushAssetDepositKeys (
1171+ ctx , & swapserverrpc.PushAssetDepositKeysReq {
1172+ DepositKeys : keys ,
1173+ },
1174+ )
1175+ if err != nil {
1176+ return err
1177+ }
1178+
1179+ return err
1180+ }
0 commit comments