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

Function after_makesecret

plugins/offers.c:1780–1828  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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