From 9e786082f7438f37137682c38e7cab26cc5c93aa Mon Sep 17 00:00:00 2001 From: Fuxing Loh <4266087+fuxingloh@users.noreply.github.com> Date: Mon, 17 May 2021 22:53:29 +0800 Subject: [PATCH] jellyfish-address refactor (#238) * updated order of jellyfish-address * rename file to lower snakecase * rename test class * fix and rename * reorder packages in introduction.md --- .github/CODEOWNERS | 2 +- .github/governance.yml | 2 +- .github/labeler.yml | 11 ++++---- .github/labels.yml | 4 +-- README.md | 1 + ...Address.test.ts => base58_address.test.ts} | 0 ...Address.test.ts => bech32_address.test.ts} | 0 .../{P2PKH.test.ts => p2pkh.test.ts} | 7 ++--- .../__tests__/{P2SH.test.ts => p2sh.test.ts} | 0 .../{P2WPKH.test.ts => p2wpkh.test.ts} | 0 .../{P2WSH.test.ts => p2wsh.test.ts} | 0 packages/jellyfish-address/jest.config.js | 1 - .../src/{Address.ts => address.ts} | 0 .../{Base58Address.ts => base58_address.ts} | 4 +-- .../{Bech32Address.ts => bech32_address.ts} | 2 +- packages/jellyfish-address/src/index.ts | 28 +++++++++---------- .../src/{P2PKH.ts => p2pkh.ts} | 2 +- .../src/{P2SH.ts => p2sh.ts} | 2 +- .../src/{P2WPKH.ts => p2wpkh.ts} | 4 +-- .../src/{P2WSH.ts => p2wsh.ts} | 4 +-- website/docs/introduction.md | 2 +- 21 files changed, 36 insertions(+), 40 deletions(-) rename packages/jellyfish-address/__tests__/{Base58Address.test.ts => base58_address.test.ts} (100%) rename packages/jellyfish-address/__tests__/{Bech32Address.test.ts => bech32_address.test.ts} (100%) rename packages/jellyfish-address/__tests__/{P2PKH.test.ts => p2pkh.test.ts} (97%) rename packages/jellyfish-address/__tests__/{P2SH.test.ts => p2sh.test.ts} (100%) rename packages/jellyfish-address/__tests__/{P2WPKH.test.ts => p2wpkh.test.ts} (100%) rename packages/jellyfish-address/__tests__/{P2WSH.test.ts => p2wsh.test.ts} (100%) rename packages/jellyfish-address/src/{Address.ts => address.ts} (100%) rename packages/jellyfish-address/src/{Base58Address.ts => base58_address.ts} (89%) rename packages/jellyfish-address/src/{Bech32Address.ts => bech32_address.ts} (96%) rename packages/jellyfish-address/src/{P2PKH.ts => p2pkh.ts} (96%) rename packages/jellyfish-address/src/{P2SH.ts => p2sh.ts} (96%) rename packages/jellyfish-address/src/{P2WPKH.ts => p2wpkh.ts} (96%) rename packages/jellyfish-address/src/{P2WSH.ts => p2wsh.ts} (95%) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 9db4ffa454..df3c26a412 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -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 @@ -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 diff --git a/.github/governance.yml b/.github/governance.yml index 7d7a3a36e1..57435564ba 100644 --- a/.github/governance.yml +++ b/.github/governance.yml @@ -34,6 +34,7 @@ issue: - workflow - website - jellyfish + - jellyfish-address - jellyfish-api-core - jellyfish-api-jsonrpc - jellyfish-crypto @@ -42,7 +43,6 @@ issue: - jellyfish-transaction - jellyfish-wallet - jellyfish-wallet-mnemonic - - jellyfish-address - testcontainers - testing multiple: true diff --git a/.github/labeler.yml b/.github/labeler.yml index b475add4ff..728e8be8e1 100644 --- a/.github/labeler.yml +++ b/.github/labeler.yml @@ -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: @@ -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: diff --git a/.github/labels.yml b/.github/labels.yml index 05d46ec2cf..29c66cdddf 100644 --- a/.github/labels.yml +++ b/.github/labels.yml @@ -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 @@ -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 diff --git a/README.md b/README.md index 6e885dd71c..6b7d149c1b 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/packages/jellyfish-address/__tests__/Base58Address.test.ts b/packages/jellyfish-address/__tests__/base58_address.test.ts similarity index 100% rename from packages/jellyfish-address/__tests__/Base58Address.test.ts rename to packages/jellyfish-address/__tests__/base58_address.test.ts diff --git a/packages/jellyfish-address/__tests__/Bech32Address.test.ts b/packages/jellyfish-address/__tests__/bech32_address.test.ts similarity index 100% rename from packages/jellyfish-address/__tests__/Bech32Address.test.ts rename to packages/jellyfish-address/__tests__/bech32_address.test.ts diff --git a/packages/jellyfish-address/__tests__/P2PKH.test.ts b/packages/jellyfish-address/__tests__/p2pkh.test.ts similarity index 97% rename from packages/jellyfish-address/__tests__/P2PKH.test.ts rename to packages/jellyfish-address/__tests__/p2pkh.test.ts index 152bf50276..8389060b50 100644 --- a/packages/jellyfish-address/__tests__/P2PKH.test.ts +++ b/packages/jellyfish-address/__tests__/p2pkh.test.ts @@ -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') }) }) diff --git a/packages/jellyfish-address/__tests__/P2SH.test.ts b/packages/jellyfish-address/__tests__/p2sh.test.ts similarity index 100% rename from packages/jellyfish-address/__tests__/P2SH.test.ts rename to packages/jellyfish-address/__tests__/p2sh.test.ts diff --git a/packages/jellyfish-address/__tests__/P2WPKH.test.ts b/packages/jellyfish-address/__tests__/p2wpkh.test.ts similarity index 100% rename from packages/jellyfish-address/__tests__/P2WPKH.test.ts rename to packages/jellyfish-address/__tests__/p2wpkh.test.ts diff --git a/packages/jellyfish-address/__tests__/P2WSH.test.ts b/packages/jellyfish-address/__tests__/p2wsh.test.ts similarity index 100% rename from packages/jellyfish-address/__tests__/P2WSH.test.ts rename to packages/jellyfish-address/__tests__/p2wsh.test.ts diff --git a/packages/jellyfish-address/jest.config.js b/packages/jellyfish-address/jest.config.js index e340d01f42..11d9802ff4 100644 --- a/packages/jellyfish-address/jest.config.js +++ b/packages/jellyfish-address/jest.config.js @@ -1,7 +1,6 @@ module.exports = { testEnvironment: 'node', testMatch: [ - '**/__testcontainers__/**/*.test.ts', '**/__tests__/**/*.test.ts' ], transform: { diff --git a/packages/jellyfish-address/src/Address.ts b/packages/jellyfish-address/src/address.ts similarity index 100% rename from packages/jellyfish-address/src/Address.ts rename to packages/jellyfish-address/src/address.ts diff --git a/packages/jellyfish-address/src/Base58Address.ts b/packages/jellyfish-address/src/base58_address.ts similarity index 89% rename from packages/jellyfish-address/src/Base58Address.ts rename to packages/jellyfish-address/src/base58_address.ts index eaab27825a..55a47c4c81 100644 --- a/packages/jellyfish-address/src/Base58Address.ts +++ b/packages/jellyfish-address/src/base58_address.ts @@ -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 @@ -48,7 +48,7 @@ export abstract class Base58Address extends Address { return Buffer.from([this.getPrefix()]).toString('hex') } - static fromAddress(network: Network, utf8String: string, AddressClass: new (...a: any[]) => T): T { + static fromAddress (network: Network, utf8String: string, AddressClass: new (...a: any[]) => T): T { try { const { buffer } = Bs58.toHash160(utf8String) return new AddressClass(network, utf8String, buffer.toString('hex')) diff --git a/packages/jellyfish-address/src/Bech32Address.ts b/packages/jellyfish-address/src/bech32_address.ts similarity index 96% rename from packages/jellyfish-address/src/Bech32Address.ts rename to packages/jellyfish-address/src/bech32_address.ts index f1645165b0..6366f546af 100644 --- a/packages/jellyfish-address/src/Bech32Address.ts +++ b/packages/jellyfish-address/src/bech32_address.ts @@ -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 diff --git a/packages/jellyfish-address/src/index.ts b/packages/jellyfish-address/src/index.ts index 8cc0c94dd5..6da29629c3 100644 --- a/packages/jellyfish-address/src/index.ts +++ b/packages/jellyfish-address/src/index.ts @@ -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 diff --git a/packages/jellyfish-address/src/P2PKH.ts b/packages/jellyfish-address/src/p2pkh.ts similarity index 96% rename from packages/jellyfish-address/src/P2PKH.ts rename to packages/jellyfish-address/src/p2pkh.ts index 8d06cc98e5..5143ed9d5a 100644 --- a/packages/jellyfish-address/src/P2PKH.ts +++ b/packages/jellyfish-address/src/p2pkh.ts @@ -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) { diff --git a/packages/jellyfish-address/src/P2SH.ts b/packages/jellyfish-address/src/p2sh.ts similarity index 96% rename from packages/jellyfish-address/src/P2SH.ts rename to packages/jellyfish-address/src/p2sh.ts index fbb0e52aa7..29472d25e5 100644 --- a/packages/jellyfish-address/src/P2SH.ts +++ b/packages/jellyfish-address/src/p2sh.ts @@ -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 diff --git a/packages/jellyfish-address/src/P2WPKH.ts b/packages/jellyfish-address/src/p2wpkh.ts similarity index 96% rename from packages/jellyfish-address/src/P2WPKH.ts rename to packages/jellyfish-address/src/p2wpkh.ts index 2abd429d8e..5a8bd0fd65 100644 --- a/packages/jellyfish-address/src/P2WPKH.ts +++ b/packages/jellyfish-address/src/p2wpkh.ts @@ -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' diff --git a/packages/jellyfish-address/src/P2WSH.ts b/packages/jellyfish-address/src/p2wsh.ts similarity index 95% rename from packages/jellyfish-address/src/P2WSH.ts rename to packages/jellyfish-address/src/p2wsh.ts index 162466a79e..ac5a061145 100644 --- a/packages/jellyfish-address/src/P2WSH.ts +++ b/packages/jellyfish-address/src/p2wsh.ts @@ -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... diff --git a/website/docs/introduction.md b/website/docs/introduction.md index d0e34bf0cd..5038c7b51e 100644 --- a/website/docs/introduction.md +++ b/website/docs/introduction.md @@ -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. @@ -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.