Skip to content

Commit 01c7803

Browse files
author
iGroza
committed
feat: migrate mnemonic wallets
1 parent ab328dc commit 01c7803

File tree

3 files changed

+29
-16
lines changed

3 files changed

+29
-16
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@haqq/rn-wallet-providers",
3-
"version": "0.0.7",
3+
"version": "0.0.8",
44
"description": "React Native providers for Haqq wallet",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

src/providers/mnemonic/provider.ts

+3-11
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@ import EncryptedStorage from 'react-native-encrypted-storage';
77
import {ProviderMnemonicBaseOptions} from './types';
88

99
import {ITEM_KEYS, WalletType} from '../../constants';
10-
import {Multichain} from '../../services/multichain';
11-
import {compressPublicKey, convertHdPath} from '../../utils';
10+
import {compressPublicKey} from '../../utils';
1211
import {getMnemonic} from '../../utils/mnemonic/get-mnemonic';
1312
import {ProviderBase} from '../base-provider';
14-
import {NETWORK_TYPE, ProviderBaseOptions, ProviderInterface} from '../types';
13+
import {ProviderBaseOptions, ProviderInterface} from '../types';
1514

1615
export class ProviderMnemonicBase
1716
extends ProviderBase<ProviderMnemonicBaseOptions>
@@ -119,7 +118,7 @@ export class ProviderMnemonicBase
119118
}
120119

121120
async getAccountInfo(hdPath: string) {
122-
let resp = {publicKey: '', address: '', tronAddress: ''};
121+
let resp = {publicKey: '', address: ''};
123122
try {
124123
const share = await getMnemonic(
125124
this._options.account,
@@ -131,13 +130,7 @@ export class ProviderMnemonicBase
131130
}
132131

133132
const seed = await ProviderMnemonicBase.shareToSeed(share);
134-
135133
const ethPrivateKey = await derive(seed, hdPath);
136-
const tronAddress = await Multichain.generateAddress(
137-
NETWORK_TYPE.TRON,
138-
convertHdPath(hdPath, NETWORK_TYPE.TRON),
139-
await this.getMnemonicPhrase(),
140-
);
141134

142135
if (!ethPrivateKey) {
143136
throw new Error('private_key_not_found');
@@ -148,7 +141,6 @@ export class ProviderMnemonicBase
148141
resp = {
149142
publicKey: compressPublicKey(account.publicKey),
150143
address: account.address,
151-
tronAddress,
152144
};
153145
this.emit('getPublicKeyForHDPath', true);
154146
} catch (e) {

src/providers/mnemonic/tron-provider.ts

+25-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable no-console */
2-
import {derive} from '@haqq/provider-web3-utils';
2+
import {accountInfo, derive} from '@haqq/provider-web3-utils';
33
import tron from 'tronweb';
44

55
import {ProviderMnemonicBase} from './provider';
@@ -12,6 +12,7 @@ import {
1212
TransactionRequest,
1313
TypedData,
1414
} from '../types';
15+
import { compressPublicKey } from '../../utils';
1516

1617
export class ProviderMnemonicTron
1718
extends ProviderMnemonicBase
@@ -42,10 +43,30 @@ export class ProviderMnemonicTron
4243
}
4344

4445
async getAccountInfo(hdPath: string) {
45-
const info = await super.getAccountInfo(hdPath.replace("44'", "195'"));
46+
const share = await getMnemonic(
47+
this._options.account,
48+
this._options.getPassword,
49+
);
50+
51+
if (!share) {
52+
throw new Error('seed_not_found');
53+
}
54+
55+
const seed = await ProviderMnemonicBase.shareToSeed(share);
56+
const ethPrivateKey = await derive(seed, hdPath);
57+
58+
if (!ethPrivateKey) {
59+
throw new Error('private_key_not_found');
60+
}
61+
62+
const account = await accountInfo(ethPrivateKey);
63+
console.log('ethPrivateKey', ethPrivateKey);
64+
console.log('account', account);
65+
66+
4667
return {
47-
...info,
48-
address: tron.utils.address.fromHex(info.address),
68+
publicKey: compressPublicKey(account.publicKey),
69+
address: tron.utils.address.fromHex(account.address),
4970
};
5071
}
5172

0 commit comments

Comments
 (0)