| 1734 | AUTODATA(json_command, &delpay_command); |
| 1735 | |
| 1736 | static struct command_result *json_createonion(struct command *cmd, |
| 1737 | const char *buffer, |
| 1738 | const jsmntok_t *obj UNNEEDED, |
| 1739 | const jsmntok_t *params) |
| 1740 | { |
| 1741 | struct json_stream *response; |
| 1742 | struct secret *session_key, *shared_secrets; |
| 1743 | struct sphinx_path *sp; |
| 1744 | u8 *assocdata, *serialized; |
| 1745 | u32 *packet_size; |
| 1746 | struct onionpacket *packet; |
| 1747 | struct sphinx_hop *hops; |
| 1748 | |
| 1749 | if (!param(cmd, buffer, params, |
| 1750 | p_req("hops", param_hops_array, &hops), |
| 1751 | p_req("assocdata", param_bin_from_hex, &assocdata), |
| 1752 | p_opt("session_key", param_secret, &session_key), |
| 1753 | p_opt_def("onion_size", param_number, &packet_size, ROUTING_INFO_SIZE), |
| 1754 | NULL)) { |
| 1755 | return command_param_failed(); |
| 1756 | } |
| 1757 | |
| 1758 | if (session_key == NULL) |
| 1759 | sp = sphinx_path_new(cmd, assocdata); |
| 1760 | else |
| 1761 | sp = sphinx_path_new_with_key(cmd, assocdata, session_key); |
| 1762 | |
| 1763 | for (size_t i=0; i<tal_count(hops); i++) { |
| 1764 | if (!sphinx_add_hop_has_length(sp, &hops[i].pubkey, hops[i].raw_payload)) |
| 1765 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 1766 | "hops[%zi] payload is not prefixed with length!", |
| 1767 | i); |
| 1768 | } |
| 1769 | |
| 1770 | if (sphinx_path_payloads_size(sp) > *packet_size) |
| 1771 | return command_fail( |
| 1772 | cmd, JSONRPC2_INVALID_PARAMS, |
| 1773 | "Payloads exceed maximum onion packet size."); |
| 1774 | |
| 1775 | packet = create_onionpacket(cmd, sp, *packet_size, &shared_secrets); |
| 1776 | if (!packet) |
| 1777 | return command_fail(cmd, LIGHTNINGD, |
| 1778 | "Could not create onion packet"); |
| 1779 | |
| 1780 | serialized = serialize_onionpacket(cmd, packet); |
| 1781 | |
| 1782 | response = json_stream_success(cmd); |
| 1783 | json_add_hex(response, "onion", serialized, tal_bytelen(serialized)); |
| 1784 | json_array_start(response, "shared_secrets"); |
| 1785 | for (size_t i=0; i<tal_count(hops); i++) { |
| 1786 | json_add_secret(response, NULL, &shared_secrets[i]); |
| 1787 | } |
| 1788 | json_array_end(response); |
| 1789 | return command_success(cmd, response); |
| 1790 | } |
| 1791 | |
| 1792 | static const struct json_command createonion_command = { |
| 1793 | "createonion", |
nothing calls this directly
no test coverage detected