From c824af11a16658777b4be27fd9b7cf4c833dc7d6 Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Mon, 26 Mar 2018 14:02:51 -0700 Subject: [PATCH] aezeed: expose BirthdayTime conversion from offset --- aezeed/cipherseed.go | 13 ++++++++++--- aezeed/cipherseed_test.go | 4 ++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/aezeed/cipherseed.go b/aezeed/cipherseed.go index 3c34754d..3459e4cd 100644 --- a/aezeed/cipherseed.go +++ b/aezeed/cipherseed.go @@ -126,12 +126,12 @@ var ( ) var ( - // bitcoinGenesisDate is the timestamp of Bitcoin's genesis block. + // BitcoinGenesisDate is the timestamp of Bitcoin's genesis block. // We'll use this value in order to create a compact birthday for the // seed. The birthday will be interested as the number of days since // the genesis date. We refer to this time period as ABE (after Bitcoin // era). - bitcoinGenesisDate = time.Unix(1231006505, 0) + BitcoinGenesisDate = time.Unix(1231006505, 0) ) // CipherSeed is a fully decoded instance of the aezeed scheme. At a high @@ -201,7 +201,7 @@ func New(internalVersion uint8, entropy *[EntropySize]byte, // To compute our "birthday", we'll first use the current time, then // subtract that from the Bitcoin Genesis Date. We'll then convert that // value to days. - birthday := uint16(now.Sub(bitcoinGenesisDate) / (time.Hour * 24)) + birthday := uint16(now.Sub(BitcoinGenesisDate) / (time.Hour * 24)) c := &CipherSeed{ InternalVersion: internalVersion, @@ -384,6 +384,13 @@ func (c *CipherSeed) Encipher(pass []byte) ([EncipheredCipherSeedSize]byte, erro return c.encipher(pass) } +// BirthdayTime returns the cipher seed's internal birthday format as a native +// golang Time struct. +func (c *CipherSeed) BirthdayTime() time.Time { + offset := time.Duration(c.Birthday) * 24 * time.Hour + return BitcoinGenesisDate.Add(offset) +} + // Mnemonic is a 24-word passphrase as of CipherSeedVersion zero. This // passphrase encodes an encrypted seed triple (version, birthday, entropy). // Additionally, we also encode the salt used with scrypt to derive the key diff --git a/aezeed/cipherseed_test.go b/aezeed/cipherseed_test.go index 7703bdc5..e17d8e64 100644 --- a/aezeed/cipherseed_test.go +++ b/aezeed/cipherseed_test.go @@ -33,7 +33,7 @@ var ( version0TestVectors = []TestVector{ { version: 0, - time: bitcoinGenesisDate, + time: BitcoinGenesisDate, entropy: testEntropy, salt: testSalt, password: []byte{}, @@ -466,7 +466,7 @@ func TestSeedEncodeDecode(t *testing.T) { now := time.Unix(nowInt, 0) seed := CipherSeed{ InternalVersion: version, - Birthday: uint16(now.Sub(bitcoinGenesisDate) / (time.Hour * 24)), + Birthday: uint16(now.Sub(BitcoinGenesisDate) / (time.Hour * 24)), Entropy: entropy, }