-
Notifications
You must be signed in to change notification settings - Fork 302
Expand file tree
/
Copy pathutils.ts
More file actions
60 lines (53 loc) · 1.28 KB
/
utils.ts
File metadata and controls
60 lines (53 loc) · 1.28 KB
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
/**
* Tempo Utility Functions
*
* Since Tempo is EVM-compatible, we can reuse Ethereum utilities
*/
import { bip32 } from '@bitgo/secp256k1';
import { VALID_ADDRESS_REGEX } from './constants';
/**
* Check if address is valid Ethereum-style address
* TODO: Replace with ETH utils when implementing
*/
export function isValidAddress(address: string): boolean {
if (typeof address !== 'string') {
return false;
}
return VALID_ADDRESS_REGEX.test(address);
}
/**
* Check if public key is valid (BIP32 xpub format)
* TODO: Replace with ETH utils when implementing
*/
export function isValidPublicKey(publicKey: string): boolean {
if (typeof publicKey !== 'string') {
return false;
}
try {
const hdNode = bip32.fromBase58(publicKey);
return hdNode.isNeutered();
} catch (e) {
return false;
}
}
/**
* Check if private key is valid (BIP32 xprv format)
* TODO: Replace with ETH utils when implementing
*/
export function isValidPrivateKey(privateKey: string): boolean {
if (typeof privateKey !== 'string') {
return false;
}
try {
const hdNode = bip32.fromBase58(privateKey);
return !hdNode.isNeutered();
} catch (e) {
return false;
}
}
const utils = {
isValidAddress,
isValidPublicKey,
isValidPrivateKey,
};
export default utils;