2017-08-28 18:06:01 +02:00
|
|
|
#ifndef LIGHTNING_COMMON_DERIVE_BASEPOINTS_H
|
|
|
|
#define LIGHTNING_COMMON_DERIVE_BASEPOINTS_H
|
2017-03-07 02:07:06 +01:00
|
|
|
#include "config.h"
|
2017-08-23 03:52:17 +02:00
|
|
|
#include <assert.h>
|
2017-03-07 02:07:06 +01:00
|
|
|
#include <bitcoin/privkey.h>
|
|
|
|
#include <bitcoin/pubkey.h>
|
2017-08-23 02:54:54 +02:00
|
|
|
#include <ccan/build_assert/build_assert.h>
|
|
|
|
#include <ccan/crypto/shachain/shachain.h>
|
2017-03-07 02:07:06 +01:00
|
|
|
|
|
|
|
struct sha256;
|
|
|
|
|
|
|
|
struct basepoints {
|
|
|
|
struct pubkey revocation;
|
|
|
|
struct pubkey payment;
|
|
|
|
struct pubkey delayed_payment;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct secrets {
|
|
|
|
struct privkey funding_privkey;
|
2017-05-06 04:19:44 +02:00
|
|
|
struct secret revocation_basepoint_secret;
|
|
|
|
struct secret payment_basepoint_secret;
|
|
|
|
struct secret delayed_payment_basepoint_secret;
|
2017-03-07 02:07:06 +01:00
|
|
|
};
|
|
|
|
|
2017-05-23 13:07:17 +02:00
|
|
|
/**
|
|
|
|
* derive_basepoints - given a (per-peer) seed, get the basepoints
|
|
|
|
* @seed: (in) seed (derived by master daemon from counter and main seed)
|
|
|
|
* @funding_pubkey: (out) pubkey for funding tx output (if non-NULL)
|
|
|
|
* @basepoints: (out) basepoints for channel (if non-NULL)
|
|
|
|
* @secrets: (out) basepoints for channel (if non-NULL)
|
|
|
|
* @shaseed: (out) seed for shachain (if non-NULL)
|
|
|
|
*/
|
2017-03-07 02:07:06 +01:00
|
|
|
bool derive_basepoints(const struct privkey *seed,
|
|
|
|
struct pubkey *funding_pubkey,
|
|
|
|
struct basepoints *basepoints,
|
|
|
|
struct secrets *secrets,
|
2017-06-20 08:10:03 +02:00
|
|
|
struct sha256 *shaseed);
|
2017-03-07 02:07:06 +01:00
|
|
|
|
2017-06-20 08:09:03 +02:00
|
|
|
/**
|
|
|
|
* per_commit_secret - get a secret for this index.
|
|
|
|
* @shaseed: the sha256 seed
|
|
|
|
* @commit_secret: the returned per-commit secret.
|
|
|
|
* @per_commit_index: (in) which @commit_secret to return.
|
|
|
|
*/
|
|
|
|
void per_commit_secret(const struct sha256 *shaseed,
|
|
|
|
struct sha256 *commit_secret,
|
|
|
|
u64 per_commit_index);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* per_commit_point - get the per-commit-point for this index.
|
|
|
|
* @shaseed: the sha256 seed
|
|
|
|
* @commit_point: the returned per-commit point.
|
|
|
|
* @per_commit_index: (in) which @commit_point to return.
|
|
|
|
*/
|
|
|
|
bool per_commit_point(const struct sha256 *shaseed,
|
|
|
|
struct pubkey *commit_point,
|
|
|
|
u64 per_commit_index);
|
2017-04-01 12:58:30 +02:00
|
|
|
|
2017-04-01 15:05:32 +02:00
|
|
|
/* BOLT #3:
|
|
|
|
*
|
|
|
|
* the first secret used MUST be index 281474976710655, and then the index
|
|
|
|
* decremented.
|
|
|
|
*/
|
|
|
|
static inline u64 shachain_index(u64 per_commit_index)
|
|
|
|
{
|
2017-08-23 02:54:54 +02:00
|
|
|
BUILD_ASSERT((1ULL << SHACHAIN_BITS)-1 == 281474976710655);
|
|
|
|
assert(per_commit_index < (1ULL << SHACHAIN_BITS));
|
|
|
|
return (1ULL << SHACHAIN_BITS)-1 - per_commit_index;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline u64 revocations_received(const struct shachain *shachain)
|
|
|
|
{
|
|
|
|
return (1ULL << SHACHAIN_BITS) - (shachain_next_index(shachain) + 1);
|
2017-04-01 15:05:32 +02:00
|
|
|
}
|
2017-08-28 18:06:01 +02:00
|
|
|
#endif /* LIGHTNING_COMMON_DERIVE_BASEPOINTS_H */
|