From 56aa664ac9f14154afb89ab0a153df40eaa81bf8 Mon Sep 17 00:00:00 2001
From: Fuxing Loh <4266087+fuxingloh@users.noreply.github.com>
Date: Fri, 26 Mar 2021 14:46:17 +0800
Subject: [PATCH] rename package to jellyfish-network (#84)
* rename package to jellyfish-network
* updated package-lock.json
---
.idea/jellyfish.iml | 9 +-
package-lock.json | 44 +++++----
packages/jellyfish-network/README.md | 6 ++
.../jellyfish-network/__tests__/index.test.ts | 51 ++++++++++
.../jest.config.js | 0
.../package.json | 7 +-
packages/jellyfish-network/src/index.ts | 92 +++++++++++++++++++
.../tsconfig.json | 0
packages/network/README.md | 3 -
packages/network/__tests__/index.test.ts | 31 -------
packages/network/src/index.ts | 74 ---------------
11 files changed, 180 insertions(+), 137 deletions(-)
create mode 100644 packages/jellyfish-network/README.md
create mode 100644 packages/jellyfish-network/__tests__/index.test.ts
rename packages/{network => jellyfish-network}/jest.config.js (100%)
rename packages/{network => jellyfish-network}/package.json (86%)
create mode 100644 packages/jellyfish-network/src/index.ts
rename packages/{network => jellyfish-network}/tsconfig.json (100%)
delete mode 100644 packages/network/README.md
delete mode 100644 packages/network/__tests__/index.test.ts
delete mode 100644 packages/network/src/index.ts
diff --git a/.idea/jellyfish.iml b/.idea/jellyfish.iml
index 9f96e61a63..b19defd1d2 100644
--- a/.idea/jellyfish.iml
+++ b/.idea/jellyfish.iml
@@ -4,15 +4,10 @@
-
-
-
-
-
-
+
-
\ No newline at end of file
+
diff --git a/package-lock.json b/package-lock.json
index 61b422176a..44d2b955fe 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1488,12 +1488,12 @@
"resolved": "packages/jellyfish",
"link": true
},
- "node_modules/@defichain/json": {
- "resolved": "packages/json",
+ "node_modules/@defichain/jellyfish-network": {
+ "resolved": "packages/jellyfish-network",
"link": true
},
- "node_modules/@defichain/network": {
- "resolved": "packages/network",
+ "node_modules/@defichain/json": {
+ "resolved": "packages/json",
"link": true
},
"node_modules/@defichain/testcontainers": {
@@ -15468,7 +15468,8 @@
},
"node_modules/cross-fetch": {
"version": "3.0.6",
- "license": "MIT",
+ "resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.0.6.tgz",
+ "integrity": "sha512-KBPUbqgFjzWlVcURG+Svp9TlhA5uliYtiNx/0r8nv0pdypeQCRJ9IaSIc3q/x3q8t3F75cHuwxVql1HFGHCNJQ==",
"dependencies": {
"node-fetch": "2.6.1"
}
@@ -28986,7 +28987,7 @@
"dependencies": {
"@defichain/api-core": "0.0.0",
"abort-controller": "^3.0.0",
- "cross-fetch": "^3.0.6"
+ "cross-fetch": "3.0.6"
},
"devDependencies": {
"@defichain/testcontainers": "0.0.0",
@@ -29013,6 +29014,14 @@
"node": ">=12.x"
}
},
+ "packages/jellyfish-network": {
+ "name": "@defichain/jellyfish-network",
+ "version": "0.0.0",
+ "license": "MIT",
+ "devDependencies": {
+ "typescript": ">=4.2.0"
+ }
+ },
"packages/json": {
"name": "@defichain/json",
"version": "0.0.0",
@@ -29028,13 +29037,6 @@
"bignumber.js": "^9.0.1"
}
},
- "packages/network": {
- "version": "0.0.0",
- "license": "MIT",
- "devDependencies": {
- "typescript": ">=4.2.0"
- }
- },
"packages/testcontainers": {
"name": "@defichain/testcontainers",
"version": "0.0.0",
@@ -30208,7 +30210,7 @@
"@defichain/api-core": "0.0.0",
"@defichain/testcontainers": "0.0.0",
"abort-controller": "^3.0.0",
- "cross-fetch": "^3.0.6",
+ "cross-fetch": "3.0.6",
"nock": "^13.0.11",
"typescript": ">=4.2.0"
}
@@ -30224,17 +30226,17 @@
"parcel": "2.0.0-beta.1"
}
},
- "@defichain/json": {
- "version": "file:packages/json",
+ "@defichain/jellyfish-network": {
+ "version": "file:packages/jellyfish-network",
"requires": {
- "@types/lossless-json": "^1.0.0",
- "lossless-json": "^1.0.4",
"typescript": ">=4.2.0"
}
},
- "@defichain/network": {
- "version": "file:packages/network",
+ "@defichain/json": {
+ "version": "file:packages/json",
"requires": {
+ "@types/lossless-json": "^1.0.0",
+ "lossless-json": "^1.0.4",
"typescript": ">=4.2.0"
}
},
@@ -41164,6 +41166,8 @@
},
"cross-fetch": {
"version": "3.0.6",
+ "resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.0.6.tgz",
+ "integrity": "sha512-KBPUbqgFjzWlVcURG+Svp9TlhA5uliYtiNx/0r8nv0pdypeQCRJ9IaSIc3q/x3q8t3F75cHuwxVql1HFGHCNJQ==",
"requires": {
"node-fetch": "2.6.1"
}
diff --git a/packages/jellyfish-network/README.md b/packages/jellyfish-network/README.md
new file mode 100644
index 0000000000..8e93f6a028
--- /dev/null
+++ b/packages/jellyfish-network/README.md
@@ -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.
diff --git a/packages/jellyfish-network/__tests__/index.test.ts b/packages/jellyfish-network/__tests__/index.test.ts
new file mode 100644
index 0000000000..82e23f1b50
--- /dev/null
+++ b/packages/jellyfish-network/__tests__/index.test.ts
@@ -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')
+})
diff --git a/packages/network/jest.config.js b/packages/jellyfish-network/jest.config.js
similarity index 100%
rename from packages/network/jest.config.js
rename to packages/jellyfish-network/jest.config.js
diff --git a/packages/network/package.json b/packages/jellyfish-network/package.json
similarity index 86%
rename from packages/network/package.json
rename to packages/jellyfish-network/package.json
index 6a94efb66b..1705181c2e 100644
--- a/packages/network/package.json
+++ b/packages/jellyfish-network/package.json
@@ -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": [
@@ -22,7 +22,10 @@
"url": "https://defichain.com/"
},
{
- "name": "DeFiChain Jellyfish Contributors"
+ "name": "DeFi Blockchain Contributors"
+ },
+ {
+ "name": "DeFi Jellyfish Contributors"
}
],
"main": "dist/index.js",
diff --git a/packages/jellyfish-network/src/index.ts b/packages/jellyfish-network/src/index.ts
new file mode 100644
index 0000000000..b64b90ada1
--- /dev/null
+++ b/packages/jellyfish-network/src/index.ts
@@ -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'
+}
diff --git a/packages/network/tsconfig.json b/packages/jellyfish-network/tsconfig.json
similarity index 100%
rename from packages/network/tsconfig.json
rename to packages/jellyfish-network/tsconfig.json
diff --git a/packages/network/README.md b/packages/network/README.md
deleted file mode 100644
index b190ae834b..0000000000
--- a/packages/network/README.md
+++ /dev/null
@@ -1,3 +0,0 @@
-# @defichain/network
-
-DeFiChain various network configuration for main, net and regtest.
diff --git a/packages/network/__tests__/index.test.ts b/packages/network/__tests__/index.test.ts
deleted file mode 100644
index 47d35307fb..0000000000
--- a/packages/network/__tests__/index.test.ts
+++ /dev/null
@@ -1,31 +0,0 @@
-import { Main, RegTest, Test } from "../src";
-
-it('should match Main network', () => {
- expect(Main.messagePrefix).toBe('\x15Defi Signed Message:\n')
- expect(Main.bech32).toBe('df')
- expect(Main.bip32.public).toBe(0x0488b21e)
- expect(Main.bip32.private).toBe(0x0488ade4)
- expect(Main.pubKeyHash).toBe(0x12)
- expect(Main.scriptHash).toBe(0x5a)
- expect(Main.wif).toBe(0x80)
-})
-
-it('should match Test network', () => {
- expect(Test.messagePrefix).toBe('\x15Defi Signed Message:\n')
- expect(Test.bech32).toBe('tf')
- expect(Test.bip32.public).toBe(0x043587cf)
- expect(Test.bip32.private).toBe(0x04358394)
- expect(Test.pubKeyHash).toBe(0xf)
- expect(Test.scriptHash).toBe(0x80)
- expect(Test.wif).toBe(0xef)
-})
-
-it('should match RegTest network', () => {
- expect(RegTest.messagePrefix).toBe('\x15Defi Signed Message:\n')
- expect(RegTest.bech32).toBe('bcrt')
- expect(RegTest.bip32.public).toBe(0x043587cf)
- expect(RegTest.bip32.private).toBe(0x04358394)
- expect(RegTest.pubKeyHash).toBe(0x6f)
- expect(RegTest.scriptHash).toBe(0xc4)
- expect(RegTest.wif).toBe(0xef)
-})
diff --git a/packages/network/src/index.ts b/packages/network/src/index.ts
deleted file mode 100644
index bb6343e1ba..0000000000
--- a/packages/network/src/index.ts
+++ /dev/null
@@ -1,74 +0,0 @@
-interface Network {
- /**
- * For signing message with RPC
- * - 'signmessage'
- * - 'verifymessage'
- */
- messagePrefix: string;
- /**
- * Wallet import format
- * base58Prefixes.SECRET_KEY
- */
- wif: number;
- /**
- * Hierarchical Deterministic Wallet
- */
- bip32: {
- /**
- * base58Prefixes.EXT_PUBLIC_KEY
- */
- public: number;
- /**
- * base58Prefixes.EXT_SECRET_KEY
- */
- private: number;
- };
- /**
- * Version prefix used for bech32
- */
- bech32: string;
- /**
- * base58Prefixes.PUBKEY_ADDRESS
- */
- pubKeyHash: number;
- /**
- * base58Prefixes.SCRIPT_ADDRESS
- */
- scriptHash: number;
-}
-
-export const Main: Network = {
- messagePrefix: '\x15Defi Signed Message:\n',
- bech32: 'df',
- bip32: {
- public: 0x0488b21e,
- private: 0x0488ade4,
- },
- pubKeyHash: 0x12,
- scriptHash: 0x5a,
- wif: 0x80,
-};
-
-export const Test: Network = {
- messagePrefix: '\x15Defi Signed Message:\n',
- bech32: 'tf',
- bip32: {
- public: 0x043587cf,
- private: 0x04358394,
- },
- pubKeyHash: 0xf,
- scriptHash: 0x80,
- wif: 0xef,
-}
-
-export const RegTest: Network = {
- messagePrefix: '\x15Defi Signed Message:\n',
- bech32: 'bcrt',
- bip32: {
- public: 0x043587cf,
- private: 0x04358394,
- },
- pubKeyHash: 0x6f,
- scriptHash: 0xc4,
- wif: 0xef,
-}