Skip to content

Commit

Permalink
expose seedPhrase
Browse files Browse the repository at this point in the history
  • Loading branch information
javisantos committed Jan 25, 2021
1 parent eedd93c commit e834534
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 4 deletions.
Binary file modified dist/faythe.br
Binary file not shown.
2 changes: 1 addition & 1 deletion dist/faythe.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/faythe.js.map

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion src/v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const SEED = Symbol('SEED')
const ENTROPY = Symbol('ENTROPY')
const MNEMONIC = Symbol('MNEMONIC')
const PASSPHRASE = Symbol('PASSPHRASE')
const SEEDPHRASE = Symbol('SEEDPHRASE')

const encode = (buffer, encoder = ENCODER) => {
if (!Buffer.isBuffer(buffer)) buffer = ensureBuffer(buffer)
Expand Down Expand Up @@ -86,7 +87,7 @@ export class Identity extends EventEmitter {
this[MNEMONIC] = seed ? null : mnemonic || generateMnemonic(256, randomBytes)
this[ENTROPY] = seed ? null : Buffer.from(mnemonicToEntropy(this[MNEMONIC]), 'hex')
this[SEED] = seed || Buffer.from(mnemonicToSeedSync(this[MNEMONIC], this[PASSPHRASE]).slice(0, sodium.crypto_kdf_KEYBYTES))

this[SEEDPHRASE] = entropyToMnemonic(this[SEED])
this.idspace = idspace ? ensureBuffer(idspace) : Buffer.from(multicodec.addPrefix('path', hash(Buffer.from('idspace'))))

this[MASTERKEY] = deriveFromKey(this[SEED], this.rotation, '_faythe_')
Expand Down Expand Up @@ -243,6 +244,10 @@ export class Identity extends EventEmitter {
return this[SEED]
}

get seedPhrase () {
return this[SEEDPHRASE]
}

get rotationKey () {
return this[ROTATIONKEY]
}
Expand All @@ -254,6 +259,7 @@ export class Identity extends EventEmitter {
this.masterKeyPair = null
this[MNEMONIC] = null
this[PASSPHRASE] = null
this[SEEDPHRASE] = null
sodium.sodium_memzero(this[MASTERKEY])
sodium.sodium_memzero(this[SEED])
sodium.sodium_memzero(this[ENTROPY])
Expand Down
2 changes: 1 addition & 1 deletion test/v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ let alice, bob, charlie
})

test('fromSeedPhrase (' + env + ')', (t) => {
const seedPhrase = faythe.entropyToMnemonic(alice.seed)
const seedPhrase = alice.seedPhrase
const alice2 = faythe.Identity.fromSeedPhrase(seedPhrase, 'test', 'alice')
t.equal(alice2.publicKey.toString('hex'), alice.publicKey.toString('hex'), 'Should be the same')
t.end()
Expand Down

0 comments on commit e834534

Please sign in to comment.