Skip to content

Commit

Permalink
Renamed and additional refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
monstrobishi committed Jul 9, 2021
1 parent 3f281c0 commit 512e53f
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

/packages/jellyfish-transaction-builder/ @fuxingloh @ivan-zynesis @monstrobishi
/packages/jellyfish-transaction-signature/ @fuxingloh @ivan-zynesis
/packages/jellyfish-wallet/ @fuxingloh @ivan-zynesis
/packages/jellyfish-wallet/ @fuxingloh @ivan-zynesis @monstrobishi
/packages/jellyfish-wallet-mnemonic/ @fuxingloh @ivan-zynesis
/packages/testcontainers/ @fuxingloh
/packages/testing/ @fuxingloh @canonbrother
Expand Down
6 changes: 3 additions & 3 deletions packages/jellyfish-wallet/__tests__/account.mock.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { WalletAccount, WalletAccountProvider, WalletNode } from '../src'
import { WalletAccount, WalletAccountProvider, WalletEllipticPair } from '../src'
import { Network, RegTest } from '@defichain/jellyfish-network'

/**
Expand All @@ -13,7 +13,7 @@ import { Network, RegTest } from '@defichain/jellyfish-network'
* 02acf1d65943ce391c5c7a6319050c71ece26f5815f1a69445edd35b8d8dac13be
*/
export class TestAccount extends WalletAccount {
constructor (hdNode: WalletNode, readonly provider: TestAccountProvider) {
constructor (hdNode: WalletEllipticPair, readonly provider: TestAccountProvider) {
super(hdNode, provider.network)
}

Expand All @@ -29,7 +29,7 @@ export class TestAccountProvider implements WalletAccountProvider<TestAccount> {
constructor (public readonly addresses: string[]) {
}

provide (hdNode: WalletNode): TestAccount {
provide (hdNode: WalletEllipticPair): TestAccount {
return new TestAccount(hdNode, this)
}
}
2 changes: 1 addition & 1 deletion packages/jellyfish-wallet/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from './wallet'
export * from './wallet_account'
export * from './wallet_hd_node'
export * from './wallet_node'
export * from './wallet_elliptic_pair'
24 changes: 12 additions & 12 deletions packages/jellyfish-wallet/src/wallet_account.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { OP_CODES, Script, Transaction, TransactionSegWit, Vout } from '@defichain/jellyfish-transaction'
import { WalletNode } from './wallet_node'
import { WalletEllipticPair } from './wallet_elliptic_pair'
import { Bech32, HASH160 } from '@defichain/jellyfish-crypto'
import { Network } from '@defichain/jellyfish-network'
import { DeFiAddress } from '@defichain/jellyfish-address'
Expand All @@ -11,9 +11,9 @@ import { DeFiAddress } from '@defichain/jellyfish-address'
*
* WalletAccount implementation uses NATIVE SEGWIT redeem script exclusively.
*/
export abstract class WalletAccount implements WalletNode {
export abstract class WalletAccount implements WalletEllipticPair {
protected constructor (
private readonly hdNode: WalletNode,
private readonly walletEllipticPair: WalletEllipticPair,
private readonly network: Network
) {
}
Expand All @@ -22,15 +22,15 @@ export abstract class WalletAccount implements WalletNode {
* @return {Promise<string>} Bech32 address of this account. (NATIVE SEGWIT)
*/
async getAddress (): Promise<string> {
const pubKey = await this.hdNode.publicKey()
const pubKey = await this.walletEllipticPair.publicKey()
return Bech32.fromPubKey(pubKey, this.network.bech32.hrp, 0x00)
}

/**
* @return {Promise<Script>} redeem script of this account. (NATIVE SEGWIT)
*/
async getScript (): Promise<Script> {
const pubKey = await this.hdNode.publicKey()
const pubKey = await this.walletEllipticPair.publicKey()
return {
stack: [
OP_CODES.OP_0,
Expand Down Expand Up @@ -58,23 +58,23 @@ export abstract class WalletAccount implements WalletNode {
abstract isActive (): Promise<boolean>

async publicKey (): Promise<Buffer> {
return await this.hdNode.publicKey()
return await this.walletEllipticPair.publicKey()
}

async privateKey (): Promise<Buffer> {
return await this.hdNode.privateKey()
return await this.walletEllipticPair.privateKey()
}

async sign (hash: Buffer): Promise<Buffer> {
return await this.hdNode.sign(hash)
return await this.walletEllipticPair.sign(hash)
}

async signTx (transaction: Transaction, prevouts: Vout[]): Promise<TransactionSegWit> {
return await this.hdNode.signTx(transaction, prevouts)
return await this.walletEllipticPair.signTx(transaction, prevouts)
}

async verify (hash: Buffer, derSignature: Buffer): Promise<boolean> {
return await this.hdNode.verify(hash, derSignature)
return await this.walletEllipticPair.verify(hash, derSignature)
}
}

Expand All @@ -85,8 +85,8 @@ export abstract class WalletAccount implements WalletNode {
export interface WalletAccountProvider<T extends WalletAccount> {

/**
* @param {WalletNode} hdNode of this wallet account
* @param {WalletEllipticPair} hdNode of this wallet account
* @return WalletAccount
*/
provide: (hdNode: WalletNode) => T
provide: (hdNode: WalletEllipticPair) => T
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import { Transaction, TransactionSegWit, Vout } from '@defichain/jellyfish-trans
import { EllipticPair } from '@defichain/jellyfish-crypto'

/**
* WalletNode extends EllipticPair with additional interface to sign transaction.
* WalletEllipticPair extends EllipticPair with additional interface to sign transaction.
*
* WalletNode uses a managed wallet design where defaults are decided by the implementation.
* Keeping the WalletNode to conventional defaults and options to none.
* WalletEllipticPair uses a managed wallet design where defaults are decided by the implementation.
* Keeping the WalletEllipticPair to conventional defaults and options to none.
*/
export interface WalletNode extends EllipticPair {
export interface WalletEllipticPair extends EllipticPair {

/**
* WalletNode transaction signing.
* WalletEllipticPair transaction signing.
*
* @param {Transaction} transaction to sign
* @param {Vout[]} prevouts of the transaction to fund this transaction
Expand Down
4 changes: 2 additions & 2 deletions packages/jellyfish-wallet/src/wallet_hd_node.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { WalletNode } from './wallet_node'
import { WalletEllipticPair } from './wallet_elliptic_pair'

/**
* WalletHdNode extends EllipticPair with additional interface to sign transaction.
Expand All @@ -10,7 +10,7 @@ import { WalletNode } from './wallet_node'
* @see BIP32 Hierarchical Deterministic Wallets
* @see BIP44 Multi-Account Hierarchy for Deterministic Wallets
*/
export interface WalletHdNode extends WalletNode {
export interface WalletHdNode extends WalletEllipticPair {

}

Expand Down

0 comments on commit 512e53f

Please sign in to comment.