Skip to content

Commit

Permalink
rename package to jellyfish-network (#84)
Browse files Browse the repository at this point in the history
* rename package to jellyfish-network

* updated package-lock.json
  • Loading branch information
fuxingloh authored Mar 26, 2021
1 parent 18526c9 commit 56aa664
Show file tree
Hide file tree
Showing 11 changed files with 180 additions and 137 deletions.
9 changes: 2 additions & 7 deletions .idea/jellyfish.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 24 additions & 20 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions packages/jellyfish-network/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[![npm](https://img.shields.io/npm/v/@defichain/jellyfish-network)](https://www.npmjs.com/package/@defichain/jellyfish-network/v/latest)
[![npm@next](https://img.shields.io/npm/v/@defichain/jellyfish-network/next)](https://www.npmjs.com/package/@defichain/jellyfish-network/v/next)

# @defichain/jellyfish-network

DeFi blockchain various network configuration for main, net and regtest.
51 changes: 51 additions & 0 deletions packages/jellyfish-network/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { Network, MainNet, RegTest, TestNet, getNetwork } from '../src'

it('should be exported', () => {
const network: Network = MainNet
expect(network.bech32.hrp).toBe('df')
expect(network.wifPrefix).toBe(0x80)
})

describe('getNetwork', () => {
it('should get mainnet', () => {
expect(getNetwork('mainnet').bech32.hrp).toBe('df')
})

it('should get testnet', () => {
expect(getNetwork('testnet').bech32.hrp).toBe('tf')
})

it('should get regtest', () => {
expect(getNetwork('regtest').bech32.hrp).toBe('bcrt')
})
})

it('should match MainNet network', () => {
expect(MainNet.bech32.hrp).toBe('df')
expect(MainNet.bip32.publicPrefix).toBe(0x0488b21e)
expect(MainNet.bip32.privatePrefix).toBe(0x0488ade4)
expect(MainNet.wifPrefix).toBe(0x80)
expect(MainNet.pubKeyHashPrefix).toBe(0x12)
expect(MainNet.scriptHashPrefix).toBe(0x5a)
expect(MainNet.messagePrefix).toBe('\x15Defi Signed Message:\n')
})

it('should match TestNet network', () => {
expect(TestNet.bech32.hrp).toBe('tf')
expect(TestNet.bip32.publicPrefix).toBe(0x043587cf)
expect(TestNet.bip32.privatePrefix).toBe(0x04358394)
expect(TestNet.wifPrefix).toBe(0xef)
expect(TestNet.pubKeyHashPrefix).toBe(0xf)
expect(TestNet.scriptHashPrefix).toBe(0x80)
expect(TestNet.messagePrefix).toBe('\x15Defi Signed Message:\n')
})

it('should match RegTest network', () => {
expect(RegTest.bech32.hrp).toBe('bcrt')
expect(RegTest.bip32.publicPrefix).toBe(0x043587cf)
expect(RegTest.bip32.privatePrefix).toBe(0x04358394)
expect(RegTest.wifPrefix).toBe(0xef)
expect(RegTest.pubKeyHashPrefix).toBe(0x6f)
expect(RegTest.scriptHashPrefix).toBe(0xc4)
expect(RegTest.messagePrefix).toBe('\x15Defi Signed Message:\n')
})
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"private": false,
"name": "@defichain/network",
"name": "@defichain/jellyfish-network",
"version": "0.0.0",
"description": "A collection of TypeScript + JavaScript tools and libraries for DeFiChain developers to build decentralized finance on Bitcoin",
"keywords": [
Expand All @@ -22,7 +22,10 @@
"url": "https://defichain.com/"
},
{
"name": "DeFiChain Jellyfish Contributors"
"name": "DeFi Blockchain Contributors"
},
{
"name": "DeFi Jellyfish Contributors"
}
],
"main": "dist/index.js",
Expand Down
92 changes: 92 additions & 0 deletions packages/jellyfish-network/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/**
* Network specific DeFi Wallet configuration.
* They can be found in DeFiCh/ain project in file chainparams.cpp, under base58Prefixes
*/
export interface Network {
bech32: {
/** bech32 human readable part */
hrp: string
}
bip32: {
/** base58Prefixes.EXT_PUBLIC_KEY */
publicPrefix: number
/** base58Prefixes.EXT_SECRET_KEY */
privatePrefix: number
}
/** base58Prefixes.SECRET_KEY */
wifPrefix: number
/** base58Prefixes.PUBKEY_ADDRESS */
pubKeyHashPrefix: number
/** base58Prefixes.SCRIPT_ADDRESS */
scriptHashPrefix: number
/** For message signing. */
messagePrefix: string
}

/**
* @param network name
* @return Network specific DeFi Wallet configuration
*/
export function getNetwork (network: 'mainnet' | 'testnet' | 'regtest'): Network {
switch (network) {
case 'mainnet':
return MainNet
case 'testnet':
return TestNet
case 'regtest':
return RegTest
default:
throw new Error(`${network as string} network not found`)
}
}

/**
* MainNet specific DeFi Wallet configuration.
*/
export const MainNet: Network = {
bech32: {
hrp: 'df'
},
bip32: {
publicPrefix: 0x0488b21e,
privatePrefix: 0x0488ade4
},
wifPrefix: 0x80,
pubKeyHashPrefix: 0x12,
scriptHashPrefix: 0x5a,
messagePrefix: '\x15Defi Signed Message:\n'
}

/**
* TestNet specific DeFi Wallet configuration.
*/
export const TestNet: Network = {
bech32: {
hrp: 'tf'
},
bip32: {
publicPrefix: 0x043587cf,
privatePrefix: 0x04358394
},
wifPrefix: 0xef,
pubKeyHashPrefix: 0xf,
scriptHashPrefix: 0x80,
messagePrefix: '\x15Defi Signed Message:\n'
}

/**
* RegTest specific DeFi Wallet configuration.
*/
export const RegTest: Network = {
bech32: {
hrp: 'bcrt'
},
bip32: {
publicPrefix: 0x043587cf,
privatePrefix: 0x04358394
},
wifPrefix: 0xef,
pubKeyHashPrefix: 0x6f,
scriptHashPrefix: 0xc4,
messagePrefix: '\x15Defi Signed Message:\n'
}
File renamed without changes.
3 changes: 0 additions & 3 deletions packages/network/README.md

This file was deleted.

31 changes: 0 additions & 31 deletions packages/network/__tests__/index.test.ts

This file was deleted.

Loading

0 comments on commit 56aa664

Please sign in to comment.