Skip to content

Commit

Permalink
adds classes for Sapphire and Jackpot, and the ability to check addre…
Browse files Browse the repository at this point in the history
…sses.
  • Loading branch information
pedro-at-decenomy committed Sep 24, 2021
1 parent f351db7 commit 08f9f01
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 29 deletions.
102 changes: 74 additions & 28 deletions index.js
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)
});
}
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"name": "dswjs-lib",
"version": "1.0.0",
"version": "0.0.1",
"description": "A javascript DSW library for node.js and browsers.",
"main": "index.js",
"type": "module",
"scripts": {
"test": "test"
},
Expand Down
44 changes: 44 additions & 0 deletions sandbox.js
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

0 comments on commit 08f9f01

Please sign in to comment.