Skip to content

Commit b701e66

Browse files
author
Fabrice Bascoulergue
committed
Update lum prefix constants
1 parent 391d983 commit b701e66

File tree

5 files changed

+87
-14
lines changed

5 files changed

+87
-14
lines changed

docs/lib/modules/lumconstants.md

+51-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@
55
### Variables
66

77
- [HDPath](lumconstants.md#hdpath)
8-
- [LumAddressPrefix](lumconstants.md#lumaddressprefix)
8+
- [LumBech32PrefixAccAddr](lumconstants.md#lumbech32prefixaccaddr)
9+
- [LumBech32PrefixAccPub](lumconstants.md#lumbech32prefixaccpub)
10+
- [LumBech32PrefixConsAddr](lumconstants.md#lumbech32prefixconsaddr)
11+
- [LumBech32PrefixConsPub](lumconstants.md#lumbech32prefixconspub)
12+
- [LumBech32PrefixValAddr](lumconstants.md#lumbech32prefixvaladdr)
13+
- [LumBech32PrefixValPub](lumconstants.md#lumbech32prefixvalpub)
914
- [LumDenom](lumconstants.md#lumdenom)
1015
- [PrivateKeyLength](lumconstants.md#privatekeylength)
1116

@@ -23,13 +28,55 @@ Lum Network HDPath
2328

2429
**`see`** https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki
2530

31+
**`see`** https://github.com/satoshilabs/slips/blob/master/slip-0044.md
32+
33+
___
34+
35+
### LumBech32PrefixAccAddr
36+
37+
`Const` **LumBech32PrefixAccAddr**: *lum*= 'lum'
38+
39+
Lum Network Bech32 prefix of an account's address
40+
41+
___
42+
43+
### LumBech32PrefixAccPub
44+
45+
`Const` **LumBech32PrefixAccPub**: *lumpub*= 'lumpub'
46+
47+
Lum Network Bech32 prefix of an account's public key
48+
49+
___
50+
51+
### LumBech32PrefixConsAddr
52+
53+
`Const` **LumBech32PrefixConsAddr**: *lumvalcons*= 'lumvalcons'
54+
55+
Lum Network Bech32 prefix of a consensus node address
56+
57+
___
58+
59+
### LumBech32PrefixConsPub
60+
61+
`Const` **LumBech32PrefixConsPub**: *lumvalconspub*= 'lumvalconspub'
62+
63+
Lum Network Bech32 prefix of a consensus node public key
64+
65+
___
66+
67+
### LumBech32PrefixValAddr
68+
69+
`Const` **LumBech32PrefixValAddr**: *lumvaloper*= 'lumvaloper'
70+
71+
Lum Network Bech32 prefix of a validator's operator address
72+
2673
___
2774

28-
### LumAddressPrefix
75+
### LumBech32PrefixValPub
2976

30-
`Const` **LumAddressPrefix**: *lum*= 'lum'
77+
`Const` **LumBech32PrefixValPub**: *lumvaloperpub*= 'lumvaloperpub'
3178

32-
Lum Network address prefix
79+
Lum Network Bech32 prefix of a validator's operator public key
3380

3481
___
3582

src/constants/index.ts

+28-2
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,40 @@
44
export const LumDenom = 'lum';
55

66
/**
7-
* Lum Network address prefix
7+
* Lum Network Bech32 prefix of an account's address
88
*/
9-
export const LumAddressPrefix = 'lum';
9+
export const LumBech32PrefixAccAddr = 'lum';
10+
11+
/**
12+
* Lum Network Bech32 prefix of an account's public key
13+
*/
14+
export const LumBech32PrefixAccPub = 'lumpub';
15+
16+
/**
17+
* Lum Network Bech32 prefix of a validator's operator address
18+
*/
19+
export const LumBech32PrefixValAddr = 'lumvaloper';
20+
21+
/**
22+
* Lum Network Bech32 prefix of a validator's operator public key
23+
*/
24+
export const LumBech32PrefixValPub = 'lumvaloperpub';
25+
26+
/**
27+
* Lum Network Bech32 prefix of a consensus node address
28+
*/
29+
export const LumBech32PrefixConsAddr = 'lumvalcons';
30+
31+
/**
32+
* Lum Network Bech32 prefix of a consensus node public key
33+
*/
34+
export const LumBech32PrefixConsPub = 'lumvalconspub';
1035

1136
/**
1237
* Lum Network HDPath
1338
*
1439
* @see https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki
40+
* @see https://github.com/satoshilabs/slips/blob/master/slip-0044.md
1541
*/
1642
export const HDPath = "m/44'/837'/0'/0/";
1743

src/utils/keys.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ import { Any } from '..//codec/google/protobuf/any';
33
import { Secp256k1, sha256, ripemd160, EnglishMnemonic, Bip39, Slip10, Slip10Curve, stringToPath, Random } from '@cosmjs/crypto';
44

55
import { Bech32 } from './encoding';
6-
import { LumAddressPrefix, getLumHdPath, PrivateKeyLength } from '../constants';
6+
import { LumBech32PrefixAccAddr, getLumHdPath, PrivateKeyLength } from '../constants';
77

88
/**
99
* Derives a bech32 wallet address from a public key (secp256k1)
1010
*
1111
* @param publicKey public key to derive the address from
1212
* @param prefix address prefix to use (ex: lum)
1313
*/
14-
export const getAddressFromPublicKey = (publicKey: Uint8Array, prefix = LumAddressPrefix) => {
14+
export const getAddressFromPublicKey = (publicKey: Uint8Array, prefix = LumBech32PrefixAccAddr) => {
1515
if (publicKey.length !== 33) {
1616
throw new Error(`Invalid Secp256k1 pubkey length (compressed): ${publicKey.length}`);
1717
}
@@ -78,7 +78,7 @@ export const generatePrivateKey = (): Uint8Array => {
7878
* @param address address to check
7979
* @param prefix prefix to check (will not be checked if not provided)
8080
*/
81-
export const isAddressValid = (address: string, prefix: string | undefined = LumAddressPrefix): boolean => {
81+
export const isAddressValid = (address: string, prefix: string | undefined = LumBech32PrefixAccAddr): boolean => {
8282
try {
8383
const decoded = Bech32.decode(address);
8484
return (!prefix || prefix === decoded.prefix) && decoded.data.length === 20;

src/wallet/LumWallet.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export class LumWallet {
2525
* @param publicKey wallet public key (secp256k1)
2626
* @param addressPrefix prefix to use to derive the address from the public key (ex: lum)
2727
*/
28-
constructor(privateKey: Uint8Array, publicKey: Uint8Array, addressPrefix = constants.LumAddressPrefix) {
28+
constructor(privateKey: Uint8Array, publicKey: Uint8Array, addressPrefix = constants.LumBech32PrefixAccAddr) {
2929
this.publicKey = publicKey;
3030
this.privateKey = privateKey;
3131
this.address = utils.getAddressFromPublicKey(publicKey, addressPrefix);
@@ -37,7 +37,7 @@ export class LumWallet {
3737
* @param privateKey wallet private key (secp256k1)
3838
* @param addressPrefix prefix to use to derive the address from the public key (ex: lum)
3939
*/
40-
static fromPrivateKey = async (privateKey: Uint8Array, addressPrefix = constants.LumAddressPrefix) => {
40+
static fromPrivateKey = async (privateKey: Uint8Array, addressPrefix = constants.LumBech32PrefixAccAddr) => {
4141
const publicKey = await utils.getPublicKeyFromPrivateKey(privateKey);
4242
return new LumWallet(privateKey, publicKey, addressPrefix);
4343
};
@@ -49,7 +49,7 @@ export class LumWallet {
4949
* @param hdPath BIP44 derivation path
5050
* @param addressPrefix prefix to use to derive the address from the public key (ex: lum)
5151
*/
52-
static fromMnemonic = async (mnemonic: string, hdPath = constants.getLumHdPath(0), addressPrefix = constants.LumAddressPrefix) => {
52+
static fromMnemonic = async (mnemonic: string, hdPath = constants.getLumHdPath(0), addressPrefix = constants.LumBech32PrefixAccAddr) => {
5353
const privateKey = await utils.getPrivateKeyFromMnemonic(mnemonic, hdPath);
5454
return LumWallet.fromPrivateKey(privateKey, addressPrefix);
5555
};
@@ -61,7 +61,7 @@ export class LumWallet {
6161
* @param password keystore password
6262
* @param addressPrefix prefix to use to derive the address from the public key (ex: lum)
6363
*/
64-
static fromKeyStore = async (keystore: string | utils.KeyStore, password: string, addressPrefix = constants.LumAddressPrefix) => {
64+
static fromKeyStore = async (keystore: string | utils.KeyStore, password: string, addressPrefix = constants.LumBech32PrefixAccAddr) => {
6565
const privateKey = utils.getPrivateKeyFromKeystore(keystore, password);
6666
return LumWallet.fromPrivateKey(privateKey, addressPrefix);
6767
};

tests/wallet.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe('LumWallet', () => {
1212
const w3 = await LumWallet.fromKeyStore(keystore, 'lumiere');
1313

1414
expect(LumUtils.isAddressValid(w1.address)).toBe(true);
15-
expect(LumUtils.isAddressValid(w1.address, LumConstants.LumAddressPrefix)).toBe(true);
15+
expect(LumUtils.isAddressValid(w1.address, LumConstants.LumBech32PrefixAccAddr)).toBe(true);
1616
expect(LumUtils.isAddressValid(w1.address, undefined)).toBe(true);
1717
expect(LumUtils.isAddressValid(w1.address, 'cosmos')).toBe(false);
1818
expect(w1.address).toEqual(w2.address);

0 commit comments

Comments
 (0)