Skip to content

Commit

Permalink
jellyfish-address refactor (#238)
Browse files Browse the repository at this point in the history
* updated order of jellyfish-address

* rename file to lower snakecase

* rename test class

* fix and rename

* reorder packages in introduction.md
  • Loading branch information
fuxingloh authored May 17, 2021
1 parent cdc85c6 commit 9e78608
Show file tree
Hide file tree
Showing 21 changed files with 36 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
/website/ @fuxingloh

/packages/jellyfish/ @fuxingloh
/packages/jellyfish-address/ @fuxingloh @ivan-zynesis
/packages/jellyfish-api-core/ @fuxingloh @canonbrother @jingyi2811
/packages/jellyfish-api-jsonrpc/ @fuxingloh
/packages/jellyfish-crypto/ @fuxingloh
Expand All @@ -18,7 +19,6 @@
/packages/jellyfish-transaction/ @fuxingloh
/packages/jellyfish-wallet/ @fuxingloh
/packages/jellyfish-wallet-mnemonic/ @fuxingloh
/packages/jellyfish-address/ @fuxingloh @ivan-zynesis
/packages/testcontainers/ @fuxingloh
/packages/testing/ @fuxingloh @canonbrother

Expand Down
2 changes: 1 addition & 1 deletion .github/governance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ issue:
- workflow
- website
- jellyfish
- jellyfish-address
- jellyfish-api-core
- jellyfish-api-jsonrpc
- jellyfish-crypto
Expand All @@ -42,7 +43,6 @@ issue:
- jellyfish-transaction
- jellyfish-wallet
- jellyfish-wallet-mnemonic
- jellyfish-address
- testcontainers
- testing
multiple: true
Expand Down
11 changes: 5 additions & 6 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ labels:
matcher:
files: "packages/jellyfish/**"

- label: area/jellyfish-address
sync: true
matcher:
files: "packages/jellyfish-address/**"

- label: area/jellyfish-api-core
sync: true
matcher:
Expand Down Expand Up @@ -51,12 +56,6 @@ labels:
matcher:
files: "packages/jellyfish-wallet-mnemonic/**"


- label: area/jellyfish-address
sync: true
matcher:
files: "packages/jellyfish-address/**"

- label: area/testcontainers
sync: true
matcher:
Expand Down
4 changes: 2 additions & 2 deletions .github/labels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
name: area/website
- color: fbca04
name: area/jellyfish
- color: fbca04
name: area/jellyfish-address
- color: fbca04
name: area/jellyfish-api-core
- color: fbca04
Expand All @@ -74,8 +76,6 @@
name: area/jellyfish-wallet
- color: fbca04
name: area/jellyfish-wallet-mnemonic
- color: fbca04
name: area/jellyfish-address
- color: fbca04
name: area/testcontainers
- color: fbca04
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ version tag.
Package | Description
---------------------------------------------------|-------------
`@defichain/jellyfish` | Library bundled usage entrypoint with conventional defaults for 4 bundles: umd, esm, cjs and d.ts
`@defichain/jellyfish-address` | Provide address builder, parser, validator utility library for DeFi Blockchain.
`@defichain/jellyfish-api-core` | A protocol agnostic DeFi Blockchain client interfaces, with a "foreign function interface" design.
`@defichain/jellyfish-api-jsonrpc` | Implements the [JSON-RPC 1.0](https://www.jsonrpc.org/specification_v1) specification for api-core.
`@defichain/jellyfish-crypto` | Cryptography operations for jellyfish, includes a simple 'secp256k1' EllipticPair.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,9 @@ describe('P2PKH', () => {
const pubKeyHash = '134b0749882c225e8647df3a3417507c6f5b27'
expect(pubKeyHash.length).toEqual(38)

try {
expect(() => {
P2PKH.to('regtest', pubKeyHash)
throw new Error('should had failed')
} catch (e) {
expect(e.message).toEqual('InvalidDataLength')
}
}).toThrow('InvalidDataLength')
})
})

Expand Down
1 change: 0 additions & 1 deletion packages/jellyfish-address/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module.exports = {
testEnvironment: 'node',
testMatch: [
'**/__testcontainers__/**/*.test.ts',
'**/__tests__/**/*.test.ts'
],
transform: {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Bs58 } from '@defichain/jellyfish-crypto'
import { Network } from '@defichain/jellyfish-network'
import { Address, AddressType, Validator } from './Address'
import { Address, AddressType, Validator } from './address'

export abstract class Base58Address extends Address {
static MIN_LENGTH = 26
Expand Down Expand Up @@ -48,7 +48,7 @@ export abstract class Base58Address extends Address {
return Buffer.from([this.getPrefix()]).toString('hex')
}

static fromAddress<T extends Base58Address>(network: Network, utf8String: string, AddressClass: new (...a: any[]) => T): T {
static fromAddress<T extends Base58Address> (network: Network, utf8String: string, AddressClass: new (...a: any[]) => T): T {
try {
const { buffer } = Bs58.toHash160(utf8String)
return new AddressClass(network, utf8String, buffer.toString('hex'))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Network } from '@defichain/jellyfish-network'
import { bech32 } from 'bech32'
import { Address, AddressType, Validator } from './Address'
import { Address, AddressType, Validator } from './address'

export abstract class Bech32Address extends Address {
static MAX_LENGTH = 90
Expand Down
28 changes: 14 additions & 14 deletions packages/jellyfish-address/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@

import { getNetwork, NetworkName } from '@defichain/jellyfish-network'
import { Address, AddressType, UnknownTypeAddress } from './Address'
import { Base58Address } from './Base58Address'
import { Bech32Address } from './Bech32Address'
import { P2PKH } from './P2PKH'
import { P2SH } from './P2SH'
import { P2WSH } from './P2WSH'
import { P2WPKH } from './P2WPKH'
import { Address, AddressType, UnknownTypeAddress } from './address'
import { Base58Address } from './base58_address'
import { Bech32Address } from './bech32_address'
import { P2PKH } from './p2pkh'
import { P2SH } from './p2sh'
import { P2WSH } from './p2wsh'
import { P2WPKH } from './p2wpkh'

export * from './Address'
export * from './Base58Address'
export * from './Bech32Address'
export * from './P2PKH'
export * from './P2SH'
export * from './P2WPKH'
export * from './P2WSH'
export * from './address'
export * from './base58_address'
export * from './bech32_address'
export * from './p2pkh'
export * from './p2sh'
export * from './p2wpkh'
export * from './p2wsh'

/**
* When insist to use the "network" decoded from raw address, instead of passing one based on running application environment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Bs58 } from '@defichain/jellyfish-crypto'
import { getNetwork, Network, NetworkName } from '@defichain/jellyfish-network'
import { Script } from '@defichain/jellyfish-transaction'
import { OP_CODES, OP_PUSHDATA } from '@defichain/jellyfish-transaction/src/script'
import { Base58Address } from './Base58Address'
import { Base58Address } from './base58_address'

export class P2PKH extends Base58Address {
constructor (network: Network, utf8String: string, hex: string, validated: boolean = false) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Bs58 } from '@defichain/jellyfish-crypto'
import { getNetwork, Network, NetworkName } from '@defichain/jellyfish-network'
import { Script } from '@defichain/jellyfish-transaction'
import { OP_CODES, OP_PUSHDATA } from '@defichain/jellyfish-transaction/src/script'
import { Base58Address } from './Base58Address'
import { Base58Address } from './base58_address'

export class P2SH extends Base58Address {
static SCRIPT_HASH_LENGTH = 50 // 25 bytes, 50 char
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { bech32 } from 'bech32'
import { getNetwork, Network, NetworkName } from '@defichain/jellyfish-network'
import { Script } from '@defichain/jellyfish-transaction'
import { OP_CODES, OP_PUSHDATA } from '@defichain/jellyfish-transaction/src/script'
import { Bech32Address } from './Bech32Address'
import { Validator } from './Address'
import { Bech32Address } from './bech32_address'
import { Validator } from './address'

export class P2WPKH extends Bech32Address {
static SAMPLE = 'bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { bech32 } from 'bech32'
import { getNetwork, Network, NetworkName } from '@defichain/jellyfish-network'
import { Script } from '@defichain/jellyfish-transaction'
import { OP_CODES, OP_PUSHDATA } from '@defichain/jellyfish-transaction/src/script'
import { Bech32Address } from './Bech32Address'
import { Validator } from './Address'
import { Bech32Address } from './bech32_address'
import { Validator } from './address'

export class P2WSH extends Bech32Address {
// the raw utf8, eg bc1...
Expand Down
2 changes: 1 addition & 1 deletion website/docs/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ maintained in this repo are published with the same version tag and follows the
Package | Description
---------------------------------------------------|-------------
`@defichain/jellyfish` | Library bundled usage entrypoint with conventional defaults for 4 bundles: umd, esm, cjs and d.ts
`@defichain/jellyfish-address` | Provide address builder, parser, validator utility library for DeFi Blockchain.
`@defichain/jellyfish-api-core` | A protocol agnostic DeFi Blockchain client interfaces, with a "foreign function interface" design.
`@defichain/jellyfish-api-jsonrpc` | Implements the [JSON-RPC 1.0](https://www.jsonrpc.org/specification_v1) specification for api-core.
`@defichain/jellyfish-crypto` | Cryptography operations for jellyfish, includes a simple 'secp256k1' EllipticPair.
Expand All @@ -36,6 +37,5 @@ Package | Description
`@defichain/jellyfish-transaction` | Dead simple modern stateless raw transaction builder for DeFi.
`@defichain/jellyfish-wallet` | Jellyfish wallet is a managed wallet, where account can get discovered from an HD seed.
`@defichain/jellyfish-wallet-mnemonic` | MnemonicHdNode implements the WalletHdNode from jellyfish-wallet; a CoinType-agnostic HD Wallet for noncustodial DeFi.
`@defichain/jellyfish-address` | Provide address builder, parser, validator utility library for DeFi blockchain use.
`@defichain/testcontainers` | Provides a lightweight, throw away instances for DeFiD node provisioned automatically in a Docker container.
`@defichain/testing` | Provides rich test fixture setup functions for effective and effortless testing.

0 comments on commit 9e78608

Please sign in to comment.