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

Function hsmd_check_client_capabilities

hsmd/libhsmd.c:84–217  ·  view source on GitHub ↗

~ This routine checks that a client is allowed to call the handler. */

Source from the content-addressed store, hash-verified

82
83/*~ This routine checks that a client is allowed to call the handler. */
84bool hsmd_check_client_capabilities(struct hsmd_client *client,
85 enum hsmd_wire t)
86{
87 /*~ Here's a useful trick: enums in C are not real types, they're
88 * semantic sugar sprinkled over an int, bascally (in fact, older
89 * versions of gcc used to convert the values ints in the parser!).
90 *
91 * But GCC will do one thing for us: if we have a switch statement
92 * with a controlling expression which is an enum, it will warn us
93 * if a declared enum value is *not* handled in the switch, eg:
94 * enumeration value ‘FOOBAR’ not handled in switch [-Werror=switch]
95 *
96 * This only works if there's no 'default' label, which is sometimes
97 * hard, as we *can* have non-enum values in our enum. But the tradeoff
98 * is worth it so the compiler tells us everywhere we have to fix when
99 * we add a new enum identifier!
100 */
101 switch (t) {
102 case WIRE_HSMD_ECDH_REQ:
103 return (client->capabilities & HSM_PERM_ECDH) != 0;
104
105 case WIRE_HSMD_CANNOUNCEMENT_SIG_REQ:
106 case WIRE_HSMD_CUPDATE_SIG_REQ:
107 case WIRE_HSMD_NODE_ANNOUNCEMENT_SIG_REQ:
108 return (client->capabilities & HSM_PERM_SIGN_GOSSIP) != 0;
109
110 case WIRE_HSMD_SIGN_DELAYED_PAYMENT_TO_US:
111 case WIRE_HSMD_SIGN_REMOTE_HTLC_TO_US:
112 case WIRE_HSMD_SIGN_PENALTY_TO_US:
113 return (client->capabilities & HSM_PERM_SIGN_ONCHAIN_TX) != 0;
114
115 case WIRE_HSMD_GET_PER_COMMITMENT_POINT:
116 case WIRE_HSMD_CHECK_FUTURE_SECRET:
117 case WIRE_HSMD_SETUP_CHANNEL:
118 return (client->capabilities & HSM_PERM_COMMITMENT_POINT) != 0;
119
120 case WIRE_HSMD_SIGN_REMOTE_COMMITMENT_TX:
121 case WIRE_HSMD_SIGN_REMOTE_HTLC_TX:
122 case WIRE_HSMD_VALIDATE_COMMITMENT_TX:
123 case WIRE_HSMD_REVOKE_COMMITMENT_TX:
124 case WIRE_HSMD_VALIDATE_REVOCATION:
125 return (client->capabilities & HSM_PERM_SIGN_REMOTE_TX) != 0;
126
127 case WIRE_HSMD_SIGN_MUTUAL_CLOSE_TX:
128 return (client->capabilities & HSM_PERM_SIGN_CLOSING_TX) != 0;
129
130 case WIRE_HSMD_SIGN_SPLICE_TX:
131 return (client->capabilities & HSM_PERM_SIGN_SPLICE_TX) != 0;
132
133 case WIRE_HSMD_SIGN_OPTION_WILL_FUND_OFFER:
134 return (client->capabilities & HSM_PERM_SIGN_WILL_FUND_OFFER) != 0;
135
136 case WIRE_HSMD_CHECK_OUTPOINT:
137 case WIRE_HSMD_LOCK_OUTPOINT:
138 return (client->capabilities & HSM_PERM_LOCK_OUTPOINT) != 0;
139
140 case WIRE_HSMD_CHECK_BIP86_PUBKEY:
141 case WIRE_HSMD_INIT:

Callers 2

handle_clientFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected