Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: replace models/keys with lumos hd #3152

Merged
merged 7 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/neuron-wallet/src/controllers/hardware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { DeviceInfo, ExtendedPublicKey, PublicKey } from '../services/hardware/c
import { ResponseCode } from '../utils/const'
import HardwareWalletService from '../services/hardware'
import { connectDeviceFailed } from '../exceptions'
import { AccountExtendedPublicKey } from '../models/keys/key'
import { AccountExtendedPublicKey } from '@ckb-lumos/hd'

export default class HardwareController {
public async connectDevice(deviceInfo: DeviceInfo): Promise<Controller.Response<void>> {
Expand Down
21 changes: 10 additions & 11 deletions packages/neuron-wallet/src/controllers/wallets.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import fs from 'fs'
import { t } from 'i18next'
import { Ox } from '../utils/scriptAndAddress'
import { dialog, SaveDialogReturnValue, BrowserWindow, OpenDialogReturnValue } from 'electron'
import WalletsService, { Wallet, WalletProperties, FileKeystoreWallet } from '../services/wallets'
import NetworksService from '../services/networks'
import Keystore from '../models/keys/keystore'
import Keychain from '../models/keys/keychain'
import { validateMnemonic, mnemonicToSeedSync } from '../models/keys/mnemonic'
import { AccountExtendedPublicKey, ExtendedPrivateKey, generateMnemonic } from '../models/keys/key'
import { Keychain, Keystore, ExtendedPrivateKey, AccountExtendedPublicKey } from '@ckb-lumos/hd'
import { generateMnemonic, validateMnemonic, mnemonicToSeedSync } from '@ckb-lumos/hd/lib/mnemonic'
import CommandSubject from '../models/subjects/command'
import { ResponseCode } from '../utils/const'
import {
Expand Down Expand Up @@ -106,15 +105,15 @@ export default class WalletsController {
throw new InvalidMnemonic()
}
const extendedKey = new ExtendedPrivateKey(
masterKeychain.privateKey.toString('hex'),
masterKeychain.chainCode.toString('hex')
Ox(masterKeychain.privateKey.toString('hex')),
Ox(masterKeychain.chainCode.toString('hex'))
)
const keystore = Keystore.create(extendedKey, password)

const accountKeychain = masterKeychain.derivePath(AccountExtendedPublicKey.ckbAccountPath)
const accountExtendedPublicKey = new AccountExtendedPublicKey(
accountKeychain.publicKey.toString('hex'),
accountKeychain.chainCode.toString('hex')
Ox(accountKeychain.publicKey.toString('hex')),
Ox(accountKeychain.chainCode.toString('hex'))
)

const walletsService = WalletsService.getInstance()
Expand Down Expand Up @@ -173,8 +172,8 @@ export default class WalletsController {
)
const accountKeychain = masterKeychain.derivePath(AccountExtendedPublicKey.ckbAccountPath)
const accountExtendedPublicKey = new AccountExtendedPublicKey(
accountKeychain.publicKey.toString('hex'),
accountKeychain.chainCode.toString('hex')
Ox(accountKeychain.publicKey.toString('hex')),
Ox(accountKeychain.chainCode.toString('hex'))
)

const walletsService = WalletsService.getInstance()
Expand Down Expand Up @@ -273,7 +272,7 @@ export default class WalletsController {
walletName,
}: ExtendedPublicKey & { walletName: string }): Promise<Controller.Response<Wallet>> {
const device = HardwareWalletService.getInstance().getCurrent()!
const accountExtendedPublicKey = new AccountExtendedPublicKey(publicKey, chainCode)
const accountExtendedPublicKey = new AccountExtendedPublicKey(Ox(publicKey), Ox(chainCode))
const walletsService = WalletsService.getInstance()
const wallet = walletsService.create({
device: device.deviceInfo,
Expand Down
2 changes: 1 addition & 1 deletion packages/neuron-wallet/src/database/address/meta.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { bytes } from '@ckb-lumos/codec'
import { Address, AddressVersion } from '../../models/address'
import { AddressType } from '../../models/keys/address'
import { AddressType } from '@ckb-lumos/hd'
import Script from '../../models/chain/script'
import SystemScriptInfo from '../../models/system-script-info'
import AssetAccountInfo from '../../models/asset-account-info'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Entity, Column, PrimaryGeneratedColumn, Index, CreateDateColumn } from 'typeorm'
import HdPublicKeyInfoModel from '../../../models/keys/hd-public-key-info'
import { AddressType } from '../../../models/keys/address'
import { AddressType } from '@ckb-lumos/hd'

@Entity()
export default class HdPublicKeyInfo {
Expand Down
2 changes: 1 addition & 1 deletion packages/neuron-wallet/src/models/address.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AddressType } from '../models/keys/address'
import { AddressType } from '@ckb-lumos/hd'

export enum AddressVersion {
Testnet = 'testnet',
Expand Down
51 changes: 0 additions & 51 deletions packages/neuron-wallet/src/models/keys/address.ts

This file was deleted.

4 changes: 2 additions & 2 deletions packages/neuron-wallet/src/models/keys/hd-public-key-info.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AddressType, AccountExtendedPublicKey } from '@ckb-lumos/hd'
import { scriptToAddress } from '../../utils/scriptAndAddress'
import SystemScriptInfo from '../../models/system-script-info'
import NetworksService from '../../services/networks'
import Address, { AddressType } from './address'

export default class HdPublicKeyInfoModel {
public walletId: string
Expand All @@ -22,7 +22,7 @@ export default class HdPublicKeyInfoModel {
}

public get path(): string {
return Address.pathFor(this.addressType, this.addressIndex)
return AccountExtendedPublicKey.pathFor(this.addressType, this.addressIndex)
}

constructor(
Expand Down
114 changes: 0 additions & 114 deletions packages/neuron-wallet/src/models/keys/key.ts

This file was deleted.

Loading
Loading