add type for mnemonic.js and replace some calls with recoveryPhrase

This commit is contained in:
Audric Ackermann 2020-08-20 10:19:47 +10:00
parent 9f232c4844
commit ed9f4e713e
No known key found for this signature in database
GPG key ID: 999F434D76324AD4
12 changed files with 36 additions and 29 deletions

6
libloki/modules/mnemonic.d.ts vendored Normal file
View file

@ -0,0 +1,6 @@
export interface RecoveryPhraseUtil {
mn_encode(str: string, wordset_name: string): string;
mn_decode(str: string, wordset_name: string): string;
get_languages(): Array<string>;
pubkey_to_secret_words(pubKey?: string): string;
}

View file

@ -127,7 +127,7 @@
return this.queueTask(() =>
generateKeypair().then(async identityKeyPair =>
createAccount(identityKeyPair)
.then(() => this.saveMnemonic(mnemonic))
.then(() => this.saveRecoveryPhrase(mnemonic))
.then(clearSessionsAndPreKeys)
.then(generateKeys)
.then(confirmKeys)
@ -507,10 +507,10 @@
const hex = StringView.arrayBufferToHex(seed);
return mnemonic.mn_encode(hex, language);
},
getCurrentMnemonic() {
getCurrentRecoveryPhrase() {
return textsecure.storage.get('mnemonic');
},
saveMnemonic(mnemonic) {
saveRecoveryPhrase(mnemonic) {
return textsecure.storage.put('mnemonic', mnemonic);
},
async registrationDone(number, displayName) {

View file

@ -73,7 +73,7 @@ export class DevicePairingDialog extends React.Component<Props, State> {
public renderFilterRequestsView() {
const { currentPubKey, accepted, deviceAlias } = this.state;
let secretWords: undefined;
let secretWords: string | undefined;
if (currentPubKey) {
secretWords = window.mnemonic.pubkey_to_secret_words(currentPubKey);
}

View file

@ -197,7 +197,7 @@ export class SessionSeedModal extends React.Component<Props, State> {
}
const manager = await window.getAccountManager();
const recoveryPhrase = manager.getCurrentMnemonic();
const recoveryPhrase = manager.getCurrentRecoveryPhrase();
this.setState({
recoveryPhrase,

View file

@ -21,12 +21,12 @@ describe('Add contact', function() {
await Common.stopStubSnodeServer();
const app1Props = {
mnemonic: Common.TEST_MNEMONIC1,
recoveryPhrase: Common.TEST_RECOVERY_PHRASE_1,
displayName: Common.TEST_DISPLAY_NAME1,
};
const app2Props = {
mnemonic: Common.TEST_MNEMONIC2,
recoveryPhrase: Common.TEST_RECOVERY_PHRASE_2,
displayName: Common.TEST_DISPLAY_NAME2,
};

View file

@ -32,19 +32,19 @@ const ENABLE_LOG = false;
// tslint:disable-next-line: no-unnecessary-class
export class Common {
/* ************** USERS ****************** */
public static readonly TEST_MNEMONIC1 =
public static readonly TEST_RECOVERY_PHRASE_1 =
'faxed mechanic mocked agony unrest loincloth pencil eccentric boyfriend oasis speedy ribbon faxed';
public static readonly TEST_PUBKEY1 =
'0552b85a43fb992f6bdb122a5a379505a0b99a16f0628ab8840249e2a60e12a413';
public static readonly TEST_DISPLAY_NAME1 = 'tester_Alice';
public static readonly TEST_MNEMONIC2 =
public static readonly TEST_RECOVERY_PHRASE_2 =
'guide inbound jerseys bays nouns basin sulking awkward stockpile ostrich ascend pylons ascend';
public static readonly TEST_PUBKEY2 =
'054e1ca8681082dbd9aad1cf6fc89a32254e15cba50c75b5a73ac10a0b96bcbd2a';
public static readonly TEST_DISPLAY_NAME2 = 'tester_Bob';
public static readonly TEST_MNEMONIC3 =
public static readonly TEST_RECOVERY_PHRASE_3 =
'alpine lukewarm oncoming blender kiwi fuel lobster upkeep vogue simplest gasp fully simplest';
public static readonly TEST_PUBKEY3 =
'05f8662b6e83da5a31007cc3ded44c601f191e07999acb6db2314a896048d9036c';
@ -210,19 +210,19 @@ export class Common {
}
public static async startAndStub({
mnemonic,
recoveryPhrase,
displayName,
env = 'test-integration-session',
}: {
mnemonic: string;
recoveryPhrase: string;
displayName: string;
env?: string;
}) {
const app = await Common.startAndAssureCleanedApp(env);
await Common.startStubSnodeServer();
if (mnemonic && displayName) {
await Common.restoreFromMnemonic(app, mnemonic, displayName);
if (recoveryPhrase && displayName) {
await Common.restoreFromRecoveryPhrase(app, recoveryPhrase, displayName);
// not sure we need Common - rtharp.
await Common.timeout(2000);
}
@ -240,9 +240,9 @@ export class Common {
return appN;
}
public static async restoreFromMnemonic(
public static async restoreFromRecoveryPhrase(
app: Application,
mnemonic: string,
recoveryPhrase: string,
displayName: string
) {
await app.client.element(RegistrationPage.registrationTabSignIn).click();
@ -250,7 +250,7 @@ export class Common {
await Common.setValueWrapper(
app,
RegistrationPage.recoveryPhraseInput,
mnemonic
recoveryPhrase
);
await Common.setValueWrapper(
@ -305,13 +305,13 @@ export class Common {
public static async startAppsAsFriends() {
const app1Props = {
mnemonic: Common.TEST_MNEMONIC1,
recoveryPhrase: Common.TEST_RECOVERY_PHRASE_1,
displayName: Common.TEST_DISPLAY_NAME1,
stubSnode: true,
};
const app2Props = {
mnemonic: Common.TEST_MNEMONIC2,
recoveryPhrase: Common.TEST_RECOVERY_PHRASE_2,
displayName: Common.TEST_DISPLAY_NAME2,
stubSnode: true,
};

View file

@ -21,7 +21,7 @@ describe('Link Device', function() {
await Common.killallElectron();
const app1Props = {
mnemonic: Common.TEST_MNEMONIC1,
recoveryPhrase: Common.TEST_RECOVERY_PHRASE_1,
displayName: Common.TEST_DISPLAY_NAME1,
};

View file

@ -18,7 +18,7 @@ describe('Open groups', function() {
beforeEach(async () => {
await Common.killallElectron();
const login = {
mnemonic: Common.TEST_MNEMONIC1,
recoveryPhrase: Common.TEST_RECOVERY_PHRASE_1,
displayName: Common.TEST_DISPLAY_NAME1,
};
app = await Common.startAndStub(login);

View file

@ -47,7 +47,7 @@ describe('Window Test and Login', function() {
await app.client.element(RegistrationPage.restoreFromSeedMode).click();
await app.client
.element(RegistrationPage.recoveryPhraseInput)
.setValue(Common.TEST_MNEMONIC1);
.setValue(Common.TEST_RECOVERY_PHRASE_1);
await app.client
.element(RegistrationPage.displayNameInput)
.setValue(Common.TEST_DISPLAY_NAME1);
@ -56,7 +56,7 @@ describe('Window Test and Login', function() {
await app.client
.element(RegistrationPage.recoveryPhraseInput)
.getValue()
.should.eventually.equal(Common.TEST_MNEMONIC1);
.should.eventually.equal(Common.TEST_RECOVERY_PHRASE_1);
await app.client
.element(RegistrationPage.displayNameInput)
.getValue()
@ -107,7 +107,7 @@ describe('Window Test and Login', function() {
it('registration: can delete account when logged in', async () => {
// login as user1
const login = {
mnemonic: Common.TEST_MNEMONIC1,
recoveryPhrase: Common.TEST_RECOVERY_PHRASE_1,
displayName: Common.TEST_DISPLAY_NAME1,
};
app = await Common.startAndStub(login);

View file

@ -83,19 +83,19 @@ async function testThreeMembers() {
// 1. Make three clients A, B, C
const app1Props = {
mnemonic: Common.TEST_MNEMONIC1,
recoveryPhrase: Common.TEST_RECOVERY_PHRASE_1,
displayName: Common.TEST_DISPLAY_NAME1,
stubSnode: true,
};
const app2Props = {
mnemonic: Common.TEST_MNEMONIC2,
recoveryPhrase: Common.TEST_RECOVERY_PHRASE_2,
displayName: Common.TEST_DISPLAY_NAME2,
stubSnode: true,
};
const app3Props = {
mnemonic: Common.TEST_MNEMONIC3,
recoveryPhrase: Common.TEST_RECOVERY_PHRASE_3,
displayName: Common.TEST_DISPLAY_NAME3,
stubSnode: true,
};

View file

@ -27,7 +27,7 @@ describe('Settings', function() {
await Common.stopStubSnodeServer();
const appProps = {
mnemonic: Common.TEST_MNEMONIC1,
recoveryPhrase: Common.TEST_RECOVERY_PHRASE_1,
displayName: Common.TEST_DISPLAY_NAME1,
};

3
ts/window.d.ts vendored
View file

@ -10,6 +10,7 @@ import { SwarmPolling } from './session/snode_api/swarmPolling';
import { LibTextsecure } from '../libtextsecure';
import { ConversationType } from '../js/modules/data';
import { RecoveryPhraseUtil } from '../libloki/modules/mnemonic';
/*
We declare window stuff here instead of global.d.ts because we are importing other declarations.
@ -67,7 +68,7 @@ declare global {
lokiPublicChatAPI: LokiPublicChatFactoryInterface;
lokiSnodeAPI: LokiSnodeAPI;
lokiPublicChatAPI: LokiPublicChatFactoryAPI;
mnemonic: any;
mnemonic: RecoveryPhraseUtil;
onLogin: any;
passwordUtil: any;
pushToast: any;