MCPcopy Create free account
hub / github.com/ElementsProject/lightning / json_signmessagewithkey

Function json_signmessagewithkey

wallet/walletrpc.c:1253–1346  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1251AUTODATA(json_command, &sendpsbt_command);
1252
1253static struct command_result *
1254json_signmessagewithkey(struct command *cmd, const char *buffer,
1255 const jsmntok_t *obj UNNEEDED, const jsmntok_t *params)
1256{
1257 /* decoding the address */
1258 const u8 *scriptpubkey;
1259 const char *message;
1260
1261 /* from wallet BIP32 */
1262 struct pubkey pubkey;
1263
1264 if (!param(
1265 cmd, buffer, params,
1266 p_req("message", param_string, &message),
1267 p_req("address", param_bitcoin_address, &scriptpubkey),
1268 NULL))
1269 return command_param_failed();
1270
1271 const size_t script_len = tal_bytelen(scriptpubkey);
1272
1273 /* FIXME: we already had the address from the input */
1274 char *addr;
1275 addr = encode_scriptpubkey_to_addr(tmpctx, chainparams, scriptpubkey,
1276 script_len);
1277
1278 if (!is_p2wpkh(scriptpubkey, script_len, NULL)) {
1279 /* FIXME add support for BIP 322 */
1280 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
1281 "Address is not p2wpkh and "
1282 "it is not supported for signing");
1283 }
1284
1285 if (!hsm_capable(cmd->ld, WIRE_HSMD_BIP137_SIGN_MESSAGE)) {
1286 return command_fail(
1287 cmd, JSONRPC2_INVALID_PARAMS,
1288 "HSM does not support signing BIP137 signing.");
1289 }
1290
1291 u32 keyidx;
1292 enum addrtype addrtype;
1293
1294 /* Use wallet_can_spend which handles both BIP32 and BIP86 addresses */
1295 if (!wallet_can_spend(cmd->ld->wallet, scriptpubkey, script_len,
1296 &keyidx, &addrtype)) {
1297 return command_fail(
1298 cmd, JSONRPC2_INVALID_PARAMS,
1299 "Address is not found in the wallet's database");
1300 }
1301
1302 /* Derive the pubkey for the found key index */
1303 if (cmd->ld->bip86_base) {
1304 bip86_pubkey(cmd->ld, &pubkey, keyidx);
1305 } else {
1306 bip32_pubkey(cmd->ld, &pubkey, keyidx);
1307 }
1308
1309 /* wire to hsmd a sign request */
1310 u8 *msg = towire_hsmd_bip137_sign_message(

Callers

nothing calls this directly

Calls 15

tal_bytelenFunction · 0.85
is_p2wpkhFunction · 0.85
wallet_can_spendFunction · 0.85
tal_hexFunction · 0.85
json_add_pubkeyFunction · 0.85
json_add_hexFunction · 0.85
b64_encodeFunction · 0.85
paramFunction · 0.50
command_param_failedFunction · 0.50
command_failFunction · 0.50
hsm_capableFunction · 0.50

Tested by

no test coverage detected