Skip to content

Commit

Permalink
Merge pull request #1 from Holo-Host/passphrase/10-30
Browse files Browse the repository at this point in the history
manage passphrase in-memory
  • Loading branch information
mrruby authored Oct 30, 2023
2 parents f6e8850 + 0f4ab4a commit e7948e7
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/lib/helpers/generate-keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,28 @@ import * as hcSeedBundle from 'hcSeedBundle';
export async function generateKeys(passphrase: string) {
await hcSeedBundle.seedBundleReady;

const pw = new TextEncoder().encode(passphrase);

const master = hcSeedBundle.UnlockedSeedBundle.newRandom({
bundle_type: 'master'
});
master.setAppData({
generate_by: 'keymanager-v1.0'
});
const encodedMasterBytes = master.lock([
new hcSeedBundle.SeedCipherPwHash(hcSeedBundle.parseSecret(pw), 'minimum')
new hcSeedBundle.SeedCipherPwHash(
hcSeedBundle.parseSecret(new TextEncoder().encode(passphrase)),
'minimum'
)
]);

const revocationDerivationPath = 0;
const encodedRevocationBytes = await derive(revocationDerivationPath, 'revocationRoot', pw);
const encodedRevocationBytes = await derive(
revocationDerivationPath,
'revocationRoot',
passphrase
);

const deviceNumber = 1;
const encodedDeviceBytes = await derive(deviceNumber, 'deviceRoot', pw);
const encodedDeviceBytes = await derive(deviceNumber, 'deviceRoot', passphrase);

master.zero();

Expand All @@ -39,7 +44,10 @@ export async function generateKeys(passphrase: string) {
generate_by: 'keymanager-v1.0'
});
const encodedBytes = root.lock([
new hcSeedBundle.SeedCipherPwHash(hcSeedBundle.parseSecret(passphrase), 'minimum')
new hcSeedBundle.SeedCipherPwHash(
hcSeedBundle.parseSecret(new TextEncoder().encode(passphrase)),
'minimum'
)
]);
return encodedBytes;
}
Expand Down

0 comments on commit e7948e7

Please sign in to comment.