Skip to content

Commit

Permalink
feat: getPublicKeyAndAddressForHDPath
Browse files Browse the repository at this point in the history
  • Loading branch information
vivalaakam committed Jan 10, 2023
1 parent 7794551 commit 05d4755
Showing 1 changed file with 30 additions and 11 deletions.
41 changes: 30 additions & 11 deletions src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,43 @@ export class ProviderLedgerReactNative extends Provider<ProviderLedgerReactNativ
private _transport: TransportBLE | null = null
private _bleManager: BleManager | null = null

async getBase64PublicKey() {
let resp = ''
async getPublicKeyAndAddressForHDPath(hdPath: string) {
let resp = {publicKey: '', address: ''}
try {
if (!this._wallet.publicKey) {
this.stop = false;
this.stop = false;

const transport = await this.awaitForTransport(this._options.deviceId);
if (!transport) {
throw new Error('can_not_connected');
}
const eth = new AppEth(transport);
const transport = await this.awaitForTransport(this._options.deviceId);
if (!transport) {
throw new Error('can_not_connected');
}
const eth = new AppEth(transport);

const response = await eth.getAddress(this._options.hdPath);
const response = await eth.getAddress(hdPath);

this._wallet.publicKey = compressPublicKey(response.publicKey);
resp = {
publicKey: compressPublicKey(response.publicKey),
address: response.address
}
this.emit('getPublicKeyForHDPath', true);
} catch (e) {
if (e instanceof Error) {
this.emit('getPublicKeyForHDPath', false, e.message);
throw new Error(e.message);
}
}
return resp
}

async getBase64PublicKey() {
let resp = ''
try {
if (!this._wallet.publicKey) {
const {publicKey} = await this.getPublicKeyAndAddressForHDPath(this._options.hdPath)
this._wallet.publicKey = publicKey;
}

resp = Buffer.from(this._wallet.publicKey, 'hex').toString('base64');
this.emit('getBase64PublicKey', true);
} catch (e) {
if (e instanceof Error) {
this.emit('getBase64PublicKey', false, e.message);
Expand Down

0 comments on commit 05d4755

Please sign in to comment.