From d118ebaaa88bba38c64681e9781711f50949b0e4 Mon Sep 17 00:00:00 2001 From: lyambo Date: Mon, 9 Dec 2024 16:56:12 -0500 Subject: [PATCH] feedback from PR #3692 --- .../src/derivation/index.ts | 6 ++--- .../src/derivation/sol/index.ts | 23 +++++++++++-------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/packages/crypto-wallet-core/src/derivation/index.ts b/packages/crypto-wallet-core/src/derivation/index.ts index 461d891b8b1..5e0a7343da7 100644 --- a/packages/crypto-wallet-core/src/derivation/index.ts +++ b/packages/crypto-wallet-core/src/derivation/index.ts @@ -18,11 +18,11 @@ export interface Key { } export interface IDeriver { - deriveAddress(network: string, xPub: string, addressIndex: number, isChange: boolean, addressType?: string): string | void; + deriveAddress(network: string, xPub: string, addressIndex: number, isChange: boolean, addressType?: string): string; derivePrivateKey(network: string, xPriv: string, addressIndex: number, isChange: boolean, addressType?: string): Key; - deriveAddressWithPath(network: string, xpubKey: string, path: string, addressType: string): string | void; + deriveAddressWithPath(network: string, xpubKey: string, path: string, addressType: string): string; derivePrivateKeyWithPath(network, xprivKey: string, path: string, addressType: string): Key; @@ -39,7 +39,7 @@ const derivers: { [chain: string]: IDeriver } = { MATIC: new MaticDeriver(), ARB: new ArbDeriver(), BASE: new BaseDeriver(), - OP: new OpDeriver(),, + OP: new OpDeriver(), SOL: new SolDeriver() }; diff --git a/packages/crypto-wallet-core/src/derivation/sol/index.ts b/packages/crypto-wallet-core/src/derivation/sol/index.ts index c811cc1d62c..78053dcd2db 100644 --- a/packages/crypto-wallet-core/src/derivation/sol/index.ts +++ b/packages/crypto-wallet-core/src/derivation/sol/index.ts @@ -1,18 +1,23 @@ import * as web3 from '@solana/web3.js'; import { IDeriver } from '..'; -import { derivePath, getPublicKey } from 'ed25519-hd-key'; +import { derivePath } from 'ed25519-hd-key'; const BitcoreLib = require('bitcore-lib'); -const Base58 = BitcoreLib.encoding.Base58; export class SolDeriver implements IDeriver { - deriveAddress(network, xpubkey, addressIndex, isChange) { - throw new Error('Cannot derive solona addresses from just xpubkey, need to use derivePrivateKeyWithPath'); + deriveAddress(_network, _xpubkey, _addressIndex, _isChange) { + if (true) { + throw new Error('Cannot derive solona addresses from just xpubkey, need to use derivePrivateKeyWithPath'); + } + return ''; } - deriveAddressWithPath(network: string, xpubKey: string, path: string) { - throw new Error('Cannot derive solona addresses from just xpubkey, need to use derivePrivateKeyWithPath'); + deriveAddressWithPath(_network: string, _xpubKey: string, _path: string) { + if (true) { + throw new Error('Cannot derive solona addresses from just xpubkey, need to use derivePrivateKeyWithPath'); + } + return ''; } getAddress(network: string, pubKey) { @@ -21,16 +26,16 @@ export class SolDeriver implements IDeriver { } addressFromPublicKeyBuffer(pubKey: Buffer): string { - return Base58.fromBuffer(pubKey).toString(); + return new web3.PublicKey(pubKey).toString(); } derivePrivateKey(network, xPriv, addressIndex, isChange) { const changeNum = isChange ? 1 : 0; - const path = `m/${changeNum}'/${addressIndex}'`; + const path = `m/${addressIndex}'/${changeNum}'`; return this.derivePrivateKeyWithPath(network, xPriv, path); } - derivePrivateKeyWithPath(network: string, seed: string, path: string) { + derivePrivateKeyWithPath(_network: string, seed: string, path: string) { const keypair = web3.Keypair.fromSeed(derivePath(path, seed).key); const privKey = keypair.secretKey.toString(); const pubKey = keypair.publicKey.toBase58();