-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds classes for Sapphire and Jackpot, and the ability to check addre…
…sses.
- Loading branch information
pedro-at-decenomy
committed
Sep 24, 2021
1 parent
f351db7
commit 08f9f01
Showing
3 changed files
with
120 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,75 @@ | ||
const bitcoin = require('bitcoinjs-lib'); | ||
|
||
let network = { | ||
messagePrefix: '\x18DarkNet Signed Message:\n', | ||
bech32: 'bc', // we don't have it, however leave it like in Bitcoin | ||
bip32: { | ||
public: 0x022d2563, // boost::assign::list_of(0x02)(0x2D)(0x25)(0x63) | ||
private: 0x0221312b, // boost::assign::list_of(0x02)(0x21)(0x31)(0x2B) | ||
}, | ||
pubKeyHash: 0x3F, // std::vector<unsigned char>(1, 63) | ||
scriptHash: 0x12, // std::vector<unsigned char>(1, 18) | ||
wif: 0x19, // std::vector<unsigned char>(1, 25) | ||
}; | ||
|
||
let master = bitcoin.bip32.fromBase58( | ||
'TDt9EWvD5T5T44hAZm3pGYyn3tEa9MtyDUJqTnRbSS4gGmK1RwjkJRNiAXDe29WNQTAYBBWKb6ZK6Wf186SsgNyJ4BgxkEzgLAZbGXo8UF3toxj', | ||
network); | ||
|
||
let child = master.derivePath("m/44'/119'/0'/0'/0'"); // 4pvrsoxZXjKaK93ikcR3qD58ixb7iX1XZQXUNoWyqyqtbbRMgW3y 2021-04-23T14:57:04Z label=Default # addr=SPEvfQMtAtdNFfJT79GfauzodjK5N5eH1r hdkeypath=m/44'/119'/0'/0'/0' | ||
|
||
const { address } = bitcoin.payments.p2pkh({ | ||
pubkey: child.publicKey, | ||
network, | ||
}); | ||
|
||
console.log(address); | ||
if(!child.isNeutered) { | ||
console.log(c.toWIF()); | ||
import bitcoinjs from 'bitcoinjs-lib'; | ||
|
||
/** | ||
* Abstract Class DSW. | ||
* | ||
* @class DSW | ||
*/ | ||
class DSW { | ||
|
||
constructor(network) { | ||
if (this.constructor == DSW) { | ||
throw new Error("Abstract classes can't be instantiated."); | ||
} | ||
this._network = network; | ||
} | ||
|
||
checkAddress(address) { | ||
try { | ||
// check the base58 encoding and the checksum value | ||
bitcoinjs.address.fromBase58Check(address); | ||
// check the validity of the network parameters | ||
bitcoinjs.address.toOutputScript(address, this._network); | ||
return true; | ||
} catch { | ||
return false; | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Sapphire. | ||
* | ||
* @class Sapphire | ||
* @extends {DSW} | ||
*/ | ||
export class Sapphire extends DSW { | ||
|
||
constructor() { | ||
super({ | ||
messagePrefix: '\x18DarkNet Signed Message:\n', | ||
bech32: 'bc', // we don't have it, however leave it like in Bitcoin | ||
bip32: { | ||
public: 0x022d2563, // boost::assign::list_of(0x02)(0x2D)(0x25)(0x63) | ||
private: 0x0221312B, // boost::assign::list_of(0x02)(0x21)(0x31)(0x2B) | ||
}, | ||
pubKeyHash: 0x3F, // std::vector<unsigned char>(1, 63) | ||
scriptHash: 0x12, // std::vector<unsigned char>(1, 18) | ||
wif: 0x19, // std::vector<unsigned char>(1, 25) | ||
}); | ||
} | ||
|
||
} | ||
|
||
/** | ||
* Jackpot. | ||
* | ||
* @class Jackpot | ||
* @extends {DSW} | ||
*/ | ||
export class Jackpot extends DSW { | ||
|
||
constructor() { | ||
super({ | ||
messagePrefix: '\x18DarkNet Signed Message:\n', | ||
bech32: 'bc', // we don't have it, however leave it like in Bitcoin | ||
bip32: { | ||
public: 0x022D2573, // boost::assign::list_of(0x02)(0x2D)(0x25)(0x73) | ||
private: 0x0221312B, // boost::assign::list_of(0x02)(0x21)(0x31)(0x2B) | ||
}, | ||
pubKeyHash: 0x0F, // std::vector<unsigned char>(1, 15) | ||
scriptHash: 0x10, // std::vector<unsigned char>(1, 16) | ||
wif: 0x2B, // std::vector<unsigned char>(1, 43) | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import bitcoinjs from 'bitcoinjs-lib'; | ||
import { Sapphire, Jackpot } from './index.js' | ||
|
||
let network = { | ||
messagePrefix: '\x18DarkNet Signed Message:\n', | ||
bech32: 'bc', // we don't have it, however leave it like in Bitcoin | ||
bip32: { | ||
public: 0x022d2563, // boost::assign::list_of(0x02)(0x2D)(0x25)(0x63) | ||
private: 0x0221312b, // boost::assign::list_of(0x02)(0x21)(0x31)(0x2B) | ||
}, | ||
pubKeyHash: 0x3F, // std::vector<unsigned char>(1, 63) | ||
scriptHash: 0x12, // std::vector<unsigned char>(1, 18) | ||
wif: 0x19, // std::vector<unsigned char>(1, 25) | ||
}; | ||
|
||
let master = bitcoinjs.bip32.fromBase58( | ||
'TDt9EWvD5T5T44hAZm3pGYyn3tEa9MtyDUJqTnRbSS4gGmK1RwjkJRNiAXDe29WNQTAYBBWKb6ZK6Wf186SsgNyJ4BgxkEzgLAZbGXo8UF3toxj', | ||
network); | ||
|
||
let child = master.derivePath("m/44'/119'/0'/0'/0'"); // 4pvrsoxZXjKaK93ikcR3qD58ixb7iX1XZQXUNoWyqyqtbbRMgW3y 2021-04-23T14:57:04Z label=Default # addr=SPEvfQMtAtdNFfJT79GfauzodjK5N5eH1r hdkeypath=m/44'/119'/0'/0'/0' | ||
|
||
const { address } = bitcoinjs.payments.p2pkh({ | ||
pubkey: child.publicKey, | ||
network, | ||
}); | ||
|
||
console.log(address); | ||
if(!child.isNeutered) { | ||
console.log(c.toWIF()); | ||
} | ||
|
||
console.log(bitcoinjs.address.fromBase58Check('SPEvfQMtAtdNFfJT79GfauzodjK5N5eH1r')); | ||
|
||
const sapphire = new Sapphire(); | ||
|
||
console.log(sapphire.checkAddress('SPEvfQMtAtdNFfJT79GfauzodjK5N5eH1r')); // good address | ||
console.log(sapphire.checkAddress('SPEvfQMtAtdNFdJT79GfauzodjK5N5eH1r')); // bad address | ||
console.log(sapphire.checkAddress('bMcbjoJRwrim4bmEByXkpMD1VWmQMKtHPe')); // address from other chain | ||
|
||
const jackpot = new Jackpot(); | ||
|
||
console.log(jackpot.checkAddress('75gbzE5cjtCcEHREeNJh2oFHq9X77Kbkee')); // good address | ||
console.log(jackpot.checkAddress('75gbzE5cjtCcEHrEeNJh2oFHq9X77Kbkee')); // bad address | ||
console.log(jackpot.checkAddress('bMcbjoJRwrim4bmEByXkpMD1VWmQMKtHPe')); // address from other chain |