-
Notifications
You must be signed in to change notification settings - Fork 168
/
account.js
60 lines (54 loc) · 1.32 KB
/
account.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { NETWORK_ID, NETWORK_TYPE } from '../constants';
export function accountId ({
address,
networkType = 'ethereum',
chainId = '1'
}) {
if (typeof address !== 'string' || address.length === 0) {
throw new Error(`Couldn't create an accountId, missing address`);
}
return `${networkType}:0x${address.toLowerCase()}@${chainId}`;
}
export function empty (account = {}) {
return {
name: '',
networkType: NETWORK_TYPE.ethereum,
chainId: NETWORK_ID.frontier,
seed: '',
// address for an empty seed phrase
address: '00a329c0648769A73afAc7F9381E08FB43dBEA72',
createdAt: new Date().getTime(),
updatedAt: new Date().getTime(),
archived: false,
encryptedSeed: null,
validBip39Seed: false,
...account
};
}
export function validateSeed (seed, validBip39Seed) {
if (seed.length === 0) {
return {
valid: false,
reason: `You're trying to recover from an empty seed phrase`
};
}
const words = seed.split(' ');
for (let word of words) {
if (word === '') {
return {
valid: false,
reason: `Extra whitespace found`
};
}
}
if (!validBip39Seed) {
return {
valid: false,
reason: `This recovery phrase will be treated as a legacy Parity brain wallet`
};
}
return {
valid: true,
reason: null
};
}