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

Function after_makesecret

plugins/offers.c:1778–1826  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1776}
1777
1778static struct command_result *after_makesecret(struct command *cmd,
1779 const char *method,
1780 const char *buf,
1781 const jsmntok_t *result,
1782 struct decodable *decodable)
1783{
1784 struct secret secret;
1785 struct json_stream *response;
1786 const jsmntok_t *secrettok;
1787
1788 secrettok = json_get_member(buf, result, "secret");
1789 json_to_secret(buf, secrettok, &secret);
1790
1791 crypto_secretstream_xchacha20poly1305_state crypto_state;
1792
1793 if (tal_bytelen(decodable->emergency_recover) < ABYTES +
1794 HEADER_LEN)
1795 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
1796 "Can't decrypt, hex is too short!");
1797
1798 u8 *decrypt_blob = tal_arr(tmpctx, u8,
1799 tal_bytelen(decodable->emergency_recover) -
1800 ABYTES -
1801 HEADER_LEN);
1802 /* The header part */
1803 if (crypto_secretstream_xchacha20poly1305_init_pull(&crypto_state,
1804 decodable->emergency_recover,
1805 secret.data) != 0) {
1806 return command_fail(cmd, JSONRPC2_INVALID_PARAMS, "Can't decrypt!");
1807 }
1808
1809 if (crypto_secretstream_xchacha20poly1305_pull(&crypto_state, decrypt_blob,
1810 NULL, 0,
1811 decodable->emergency_recover +
1812 HEADER_LEN,
1813 tal_bytelen(decodable->emergency_recover) -
1814 HEADER_LEN,
1815 NULL, 0) != 0) {
1816 return command_fail(cmd, JSONRPC2_INVALID_PARAMS, "Can't decrypt!");
1817 }
1818
1819 response = jsonrpc_stream_success(cmd);
1820 json_add_bool(response, "valid", true);
1821 json_add_string(response, "type", decodable->type);
1822 json_add_hex(response, "decrypted", decrypt_blob,
1823 tal_bytelen(decrypt_blob));
1824
1825 return command_finished(cmd, response);
1826}
1827
1828static struct command_result *json_decode(struct command *cmd,
1829 const char *buffer,

Callers

nothing calls this directly

Calls 9

json_get_memberFunction · 0.85
json_to_secretFunction · 0.85
tal_bytelenFunction · 0.85
json_add_boolFunction · 0.85
json_add_hexFunction · 0.85
command_failFunction · 0.70
jsonrpc_stream_successFunction · 0.70
command_finishedFunction · 0.70
json_add_stringFunction · 0.50

Tested by

no test coverage detected