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

Function main

common/test/run-key_derive.c:112–169  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

110}
111
112int main(int argc, char *argv[])
113{
114 struct privkey privkey;
115 struct secret base_secret, per_commitment_secret;
116 struct pubkey base_point, per_commitment_point, pubkey, pubkey2;
117
118 common_setup(argv[0]);
119
120 base_secret = secret_from_hex("0x000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f");
121 per_commitment_secret = secret_from_hex("0x1f1e1d1c1b1a191817161514131211100f0e0d0c0b0a09080706050403020100");
122
123 printf("base_secret: 0x%s\n",
124 tal_hexstr(tmpctx, &base_secret, sizeof(base_secret)));
125 printf("per_commitment_secret: 0x%s\n",
126 tal_hexstr(tmpctx, &per_commitment_secret,
127 sizeof(per_commitment_secret)));
128 if (!secp256k1_ec_pubkey_create(secp256k1_ctx,
129 &per_commitment_point.pubkey,
130 per_commitment_secret.data))
131 abort();
132 if (!secp256k1_ec_pubkey_create(secp256k1_ctx,
133 &base_point.pubkey,
134 base_secret.data))
135 abort();
136 printf("base_point: 0x%s\n",
137 type_to_string(tmpctx, struct pubkey, &base_point));
138 printf("per_commitment_point: 0x%s\n",
139 type_to_string(tmpctx, struct pubkey, &per_commitment_point));
140
141 /* FIXME: Annotate internal steps. */
142 if (!derive_simple_key(&base_point, &per_commitment_point, &pubkey))
143 abort();
144 printf("localkey: 0x%s\n",
145 type_to_string(tmpctx, struct pubkey, &pubkey));
146 if (!derive_simple_privkey(&base_secret, &base_point,
147 &per_commitment_point, &privkey))
148 abort();
149 printf("localprivkey: 0x%s\n",
150 tal_hexstr(tmpctx, &privkey, sizeof(privkey)));
151 pubkey_from_privkey(&privkey, &pubkey2);
152 assert(pubkey_eq(&pubkey, &pubkey2));
153
154 /* FIXME: Annotate internal steps. */
155 if (!derive_revocation_key(&base_point, &per_commitment_point, &pubkey))
156 abort();
157 printf("revocationkey: 0x%s\n",
158 type_to_string(tmpctx, struct pubkey, &pubkey));
159 if (!derive_revocation_privkey(&base_secret, &per_commitment_secret,
160 &base_point, &per_commitment_point,
161 &privkey))
162 abort();
163 printf("revocationprivkey: 0x%s\n",
164 tal_hexstr(tmpctx, &privkey, sizeof(privkey)));
165 pubkey_from_privkey(&privkey, &pubkey2);
166 assert(pubkey_eq(&pubkey, &pubkey2));
167
168 common_shutdown();
169}

Callers

nothing calls this directly

Calls 9

common_setupFunction · 0.85
tal_hexstrFunction · 0.85
abortFunction · 0.85
derive_simple_keyFunction · 0.85
derive_simple_privkeyFunction · 0.85
pubkey_from_privkeyFunction · 0.85
common_shutdownFunction · 0.85
secret_from_hexFunction · 0.70
type_to_stringClass · 0.50

Tested by

no test coverage detected