Skip to content

Commit

Permalink
feat: quality of life updates
Browse files Browse the repository at this point in the history
* add confirmations, algorithm, and consensus to common type
* change isProofOfStake to consensus
* add utility functions to make it easier to find specific chains and
  networks dynamically
* change testing to vitest

v1.6.0
  • Loading branch information
michaelmcshinsky committed Mar 1, 2024
1 parent c2f882b commit b727df0
Show file tree
Hide file tree
Showing 35 changed files with 3,572 additions and 209 deletions.
3,546 changes: 3,349 additions & 197 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hyperbitjs/chains",
"version": "1.5.1",
"version": "1.6.0",
"license": "MIT",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
Expand All @@ -14,7 +14,7 @@
"scripts": {
"start": "tsdx watch",
"build": "tsdx build",
"test": "tsdx test",
"test": "vitest",
"lint": "tsdx lint",
"lint:fix": "tsdx lint --fix",
"prepare": "tsdx build",
Expand Down Expand Up @@ -57,7 +57,8 @@
"size-limit": "^8.1.0",
"tsdx": "^0.14.1",
"tslib": "^2.4.1",
"typescript": "^4.8.4"
"typescript": "^4.8.4",
"vitest": "^1.3.1"
},
"publishConfig": {
"access": "public"
Expand Down
2 changes: 2 additions & 0 deletions src/chains/bitcoin/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ export const common: Common = {
'\x18Bitcoin Signed Message:\n',
'\x19Bitcoin Signed Message:\n',
],
// https://github.com/bitcoin/bitcoin/blob/01e1627e25bc5477c40f51da03c3c31b609a85c9/src/qt/transactionrecord.h#L76
confirmations: 6

Check failure on line 17 in src/chains/bitcoin/base.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 20.x and ubuntu-latest

Insert `,`

Check failure on line 17 in src/chains/bitcoin/base.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 20.x and ubuntu-latest

Insert `,`
};
3 changes: 3 additions & 0 deletions src/chains/bitcoincash/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ export const common: Common = {
unit: 'BCH',
symbol: 'bch',
messagePrefix: 'eCash Signed Message:\n',
// https://github.com/Bitcoin-ABC/bitcoin-abc/blob/master/src/qt/transactionrecord.h#L100
algorithm: 'zhash',
confirmations: 6

Check failure on line 12 in src/chains/bitcoincash/base.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 20.x and ubuntu-latest

Insert `,`

Check failure on line 12 in src/chains/bitcoincash/base.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 20.x and ubuntu-latest

Insert `,`
};
2 changes: 2 additions & 0 deletions src/chains/bitcoingold/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ export const common: Common = {
decimalPlaces: 1e8,
/** https://github.com/BTCGPU/BTCGPU/blob/71894be9e4eb573643d85a33d28247b95db1d998/src/validation.cpp#L251 */
messagePrefix: 'Bitcoin Gold Signed Message:\n',
algorithm: 'zhash',
confirmations: 6

Check failure on line 11 in src/chains/bitcoingold/base.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 20.x and ubuntu-latest

Insert `,`

Check failure on line 11 in src/chains/bitcoingold/base.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 20.x and ubuntu-latest

Insert `,`
};
2 changes: 2 additions & 0 deletions src/chains/blackcoin/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ export const common: Common = {
unit: 'BLK',
symbol: 'blk',
messagePrefix: 'BlackCoin Signed Message:\n',
// https://github.com/blacknet-ninja/blackcoin-old/blob/1f0dc61f894aaf5fbb0d79d609f3502f7c7f2771/src/qt/transactionrecord.h#L78
confirmations: 10

Check failure on line 12 in src/chains/blackcoin/base.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 20.x and ubuntu-latest

Insert `,`

Check failure on line 12 in src/chains/blackcoin/base.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 20.x and ubuntu-latest

Insert `,`
};
2 changes: 2 additions & 0 deletions src/chains/c0ban/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ export const common: Common = {
decimalPlaces: 1e8,
/** https://github.com/c0ban/c0ban/blob/master/src/util/message.cpp#L23 */
messagePrefix: 'c0ban Signed Message:\n',
// https://github.com/c0ban/c0ban/blob/master/src/qt/transactionrecord.h#L89
confirmations: 16,
};
3 changes: 2 additions & 1 deletion src/chains/citycoin/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ export const common: Common = {
unit: 'CITY',
symbol: 'city',
decimalPlaces: 1e8,
isProofOfStake: true,
consensus: 'PoS',
confirmations: 6,
};
2 changes: 2 additions & 0 deletions src/chains/dash/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ export const common: Common = {
decimalPlaces: 1e8,
unit: 'DASH',
symbol: 'dash',
// https://github.com/dashpay/dash/blob/master/src/qt/transactionrecord.h#L103
confirmations: 6,
};
2 changes: 2 additions & 0 deletions src/chains/denarius/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ export const common: Common = {
unit: 'DNR',
symbol: 'd',
decimalPlaces: 1e8,
// https://github.com/metaspartan/denarius/blob/master/src/qt/transactionrecord.h#L75
confirmations: 10,
};
2 changes: 2 additions & 0 deletions src/chains/digibyte/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ export const common: Common = {
decimalPlaces: 1e8,
unit: 'DGB',
symbol: 'dgb',
// https://github.com/DigiByte-Core/digibyte/blob/develop/src/qt/transactionrecord.h#L88
confirmations: 6

Check failure on line 9 in src/chains/digibyte/base.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 20.x and ubuntu-latest

Insert `,`

Check failure on line 9 in src/chains/digibyte/base.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 20.x and ubuntu-latest

Insert `,`
};
2 changes: 2 additions & 0 deletions src/chains/digitalnote/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ export const common: Common = {
symbol: 'xdn',
decimalPlaces: 1e8,
messagePrefix: '\x16Digital Note Signed Message:\n',
// https://github.com/DigitalNoteXDN/DigitalNote-2/blob/master/src/qt/transactionrecord.h#L86
confirmations: 10,
};
3 changes: 3 additions & 0 deletions src/chains/dogecoin/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@ export const common: Common = {
unit: 'DOGE',
symbol: 'doge',
decimalPlaces: 1e8,
// https://github.com/dogecoin/dogecoin/blob/master/src/validation.cpp#L102
messagePrefix: 'Dogecoin Signed Message:\n',
// https://github.com/dogecoin/dogecoin/blob/master/src/qt/transactionrecord.h#L83
confirmations: 6

Check failure on line 11 in src/chains/dogecoin/base.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 20.x and ubuntu-latest

Insert `,`

Check failure on line 11 in src/chains/dogecoin/base.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 20.x and ubuntu-latest

Insert `,`
};
2 changes: 2 additions & 0 deletions src/chains/evrmore/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ export const common: Common = {
decimalPlaces: 1e8,
// https://github.com/EvrmoreOrg/Evrmore/blob/develop/src/validation.cpp#L131
messagePrefix: 'Evrmore Signed Message:\n',
// https://github.com/EvrmoreOrg/Evrmore/blob/0bbfe1813cda36190458dd69b1a0418357d30598/src/qt/transactionrecord.h#L88
confirmations: 6

Check failure on line 11 in src/chains/evrmore/base.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 20.x and ubuntu-latest

Insert `,`

Check failure on line 11 in src/chains/evrmore/base.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 20.x and ubuntu-latest

Insert `,`
};
2 changes: 2 additions & 0 deletions src/chains/feathercoin/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ export const common: Common = {
decimalPlaces: 1e8,
// https://github.com/FeatherCoin/Feathercoin/blob/master/src/util/validation.cpp#L20
messagePrefix: 'Feathercoin Signed Message:\n',
// https://github.com/FeatherCoin/Feathercoin/blob/master/src/qt/transactionrecord.h#L88
confirmations: 6

Check failure on line 11 in src/chains/feathercoin/base.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 20.x and ubuntu-latest

Insert `,`

Check failure on line 11 in src/chains/feathercoin/base.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 20.x and ubuntu-latest

Insert `,`
};
10 changes: 8 additions & 2 deletions src/chains/groestlcoin/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ export const common: Common = {
decimalPlaces: 1e8,
unit: 'GRS',
symbol: 'grs',
messagePrefix: '\x1CGroestlCoin Signed Message:\n',
messagePrefixAlts: ['\u001CGroestlCoin Signed Message:\n'],
// https://github.com/Groestlcoin/groestlcoin/blob/9588fb9abd581778cfe92ffbeb14fc23c33daa50/src/util/message.cpp#L24
messagePrefix: 'GroestlCoin Signed Message:\n',
messagePrefixAlts: [
'\x1CGroestlCoin Signed Message:\n',
'\u001CGroestlCoin Signed Message:\n',
],
// https://github.com/Groestlcoin/groestlcoin/blob/9588fb9abd581778cfe92ffbeb14fc23c33daa50/src/qt/transactionrecord.h#L75
confirmations: 6,
};
2 changes: 2 additions & 0 deletions src/chains/litecoin/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ export const common: Common = {
decimalPlaces: 1e8,
/** https://github.com/litecoin-project/litecoin/blob/master/src/util/message.cpp#L22 */
messagePrefix: 'Litecoin Signed Message:\n',
// https://github.com/litecoin-project/litecoin/blob/8925697f15f716da94c510c63b2fe7dac852cb0b/src/wallet/txrecord.h#L81
confirmations: 6,
};
4 changes: 4 additions & 0 deletions src/chains/meowcoin/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@ export const common: Common = {
decimalPlaces: 1e8,
// https://github.com/JustAResearcher/Meowcoin/blob/master/src/validation.cpp
messagePrefix: 'Meowcoin Signed Message:\n',
// TODO: update to meowpow
algorithm: 'kawpow',
// https://github.com/Meowcoin-Foundation/Meowcoin/blob/master/src/qt/transactionrecord.h#L88
confirmations: 6,
};
2 changes: 2 additions & 0 deletions src/chains/monacoin/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ export const common: Common = {
decimalPlaces: 1e8,
/** https://github.com/monacoinproject/monacoin/blob/master-0.20.3/src/util/message.cpp#L22 */
messagePrefix: 'Monacoin Signed Message:\n',
// https://github.com/monacoinproject/monacoin/blob/master-0.20.3/src/qt/transactionrecord.h#L88
confirmations: 6,
};
2 changes: 2 additions & 0 deletions src/chains/namecoin/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ export const common: Common = {
decimalPlaces: 1e8,
/** https://github.com/namecoin/namecoin-core/blob/master/src/util/message.cpp#L25 */
messagePrefix: 'Namecoin Signed Message:\n',
// https://github.com/namecoin/namecoin-core/blob/master/src/qt/transactionrecord.h#L88
confirmations: 6,
};
3 changes: 3 additions & 0 deletions src/chains/neoxa/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ export const common: Common = {
decimalPlaces: 1e8,
// https://github.com/NeoxaChain/Neoxa/blob/main/src/validation.cpp#L119
messagePrefix: 'Neoxa Signed Message:\n',
algorithm: 'kawpow',
// https://github.com/NeoxaChain/Neoxa/blob/main/src/qt/transactionrecord.h#L107
confirmations: 6,
};
2 changes: 2 additions & 0 deletions src/chains/neurai/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ export const common: Common = {
decimalPlaces: 1e8,
// https://github.com/NeuraiProject/Neurai/blob/main/src/validation.cpp#L129
messagePrefix: 'Neurai Signed Message:\n',
// https://github.com/NeuraiProject/Neurai/blob/main/src/qt/transactionrecord.h#L89
confirmations: 6,
};
2 changes: 2 additions & 0 deletions src/chains/nubits/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ export const common: Common = {
decimalPlaces: 1e6,
unit: 'NBT',
symbol: 'nbt',
// https://bitbucket.org/NuNetwork/nubits/src/919a76e59e3c88dc8c0b7c72f2032db159eba678/src/qt/transactionrecord.h#lines-78
confirmations: 6,
};
2 changes: 2 additions & 0 deletions src/chains/peercoin/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ export const common: Common = {
/** https://github.com/peercoin/peercoin/blob/master/src/util/message.cpp#L22 */
messagePrefix: 'Peercoin Signed Message:\n',
messagePrefixAlts: ['\x18Peercoin Signed Message:\n'],
// https://github.com/peercoin/peercoin/blob/master/src/qt/transactionrecord.h#L86
confirmations: 6,
};
2 changes: 2 additions & 0 deletions src/chains/pigeoncoin/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ export const common: Common = {
// https://github.com/Pigeoncoin/pigeoncoin/blob/master/src/validation.cpp#L119
messagePrefix: 'DarkCoin Signed Message:\n',
messageName: 'DarkCoin',
// https://github.com/Pigeoncoin/pigeoncoin/blob/master/src/qt/transactionrecord.h#L103
confirmations: 6,
};
2 changes: 2 additions & 0 deletions src/chains/qtum/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ export const common: Common = {
decimalPlaces: 1e8,
/** https://github.com/qtumproject/qtum/blob/631efb900d5372d957f66baa58cc800a460839ae/src/util/signstr.h#L14 */
messagePrefix: 'Qtum Signed Message:\n',
// https://github.com/qtumproject/qtum/blob/631efb900d5372d957f66baa58cc800a460839ae/src/qt/transactionrecord.h#L90
confirmations: 10,
};
3 changes: 3 additions & 0 deletions src/chains/ravencoin/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@ export const common: Common = {
decimalPlaces: 1e8,
// https://github.com/RavenProject/Ravencoin/blob/c8197cd15d8886dc5c6121e3ba3f39c92445fc1b/src/validation.cpp#L129
messagePrefix: '\x16Raven Signed Message:\n',
algorithm: 'kawpow',
// https://github.com/RavenProject/Ravencoin/blob/e48d932ec70267a62ec3541bdaf4fe022c149f0e/src/qt/transactionrecord.h#L88
confirmations: 6,
};
2 changes: 2 additions & 0 deletions src/chains/reddcoin/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ export const common: Common = {
unit: 'RDD',
symbol: 'rdd',
decimalPlaces: 1e8,
// https://github.com/reddcoin-project/reddcoin/blob/develop/src/qt/transactionrecord.h#L89
confirmations: 6,
};
3 changes: 3 additions & 0 deletions src/chains/ritocoin/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ export const common: Common = {
decimalPlaces: 1e8,
// https://github.com/RitoProject/Ritocoin/blob/master/src/validation.cpp#L113
messagePrefix: 'Rito Signed Message:\n',
algorithm: 'x21s',
// https://github.com/RitoProject/Ritocoin/blob/master/src/qt/transactionrecord.h#L92
confirmations: 6,
};
2 changes: 2 additions & 0 deletions src/chains/vertcoin/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ export const common: Common = {
/** https://github.com/vertcoin-project/vertcoin-core/blob/master/src/util/message.cpp#L22 */
messagePrefix: 'Bitcoin Signed Message:\n',
messageName: 'Bitcoin Signed Message:\n',
// https://github.com/vertcoin-project/vertcoin-core/blob/master/src/qt/transactionrecord.h#L85
confirmations: 6,
};
2 changes: 2 additions & 0 deletions src/chains/viacoin/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ export const common: Common = {
unit: 'VIA',
symbol: 'via',
decimalPlaces: 1e8,
// https://github.com/viacoin/viacoin/blob/master/src/qt/transactionrecord.h#L84
confirmations: 6,
};
2 changes: 1 addition & 1 deletion src/chains/x42/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ export const common: Common = {
unit: 'X42',
symbol: 'symbol',
decimalPlaces: 1e8,
isProofOfStake: true,
consensus: 'PoS',
};
68 changes: 66 additions & 2 deletions src/types/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ export type Common = {
messagePrefix?: string;
messagePrefixAlts?: string[];
seedsDns?: string[];
isProofOfStake?: boolean;
consensus?: Consensus;
bech32?: string;
algorithm?: Algorithm;
confirmations?: number;
};

export type MainNet = Common & {
Expand Down Expand Up @@ -54,7 +56,9 @@ export type SimNet = Omit<TestNet, 'network'> & {
network: 'simnet';
};

export type Networks = Record<string, MainNet | TestNet | RegTest | SimNet>;
export type Network = MainNet | TestNet | RegTest | SimNet;

export type Networks = Record<string, Network>;

export type BitcoinJS = (MainNet | TestNet | RegTest | SimNet) & {
bip32: Bip32;
Expand All @@ -74,3 +78,63 @@ export type BitCore = (MainNet | TestNet | RegTest | SimNet) & {
xprivkey: number;
dnsSeeds: string[];
};

export type Consensus =
| 'PoW' // Proof of Work
| 'PoS' // Proof of Stake
| 'PoB' // Proof of Burn
| 'DPoS' // Delegated Proof of Stake
| 'PBFT' // Practical Byzantine Fault Tolerance
| 'PoET' // Proof of Elapsed Time
| 'PoC' // Proof of Capacity
| 'PoA'; // Proof of Authority

export type Algorithm =
| 'allium'
| 'bcrypt'
| 'bitcore'
| 'blake'
| 'blake2s'
| 'boolberry'
| 'c11'
| 'cryptonight'
| 'cryptonight_fast'
| 'equihash'
| 'firopow'
| 'fresh'
| 'fugue'
| 'ghostrider'
| 'groestl'
| 'hefty1'
| 'kawpow'
| 'keccak'
| 'lbry'
| 'lyra2re'
| 'lyra2z'
| 'minotaur'
| 'minotaurx'
| 'neoscrypt'
| 'nist5'
| 'polytimos'
| 'quark'
| 'qubit'
| 'scrypt'
| 'scrypt-jane'
| 'scrypt-n'
| 'scryptjane'
| 'scryptn'
| 'sha1'
| 'sha256d'
| 'shavite3'
| 'skein'
| 'timetravel'
| 'verthash'
| 'x11'
| 'x13'
| 'x15'
| 'x16r'
| 'x16rt'
| 'x16rv2'
| 'x21s'
| 'xevan'
| 'zhash';
Loading

0 comments on commit b727df0

Please sign in to comment.