Skip to content

Commit

Permalink
restructure the lib
Browse files Browse the repository at this point in the history
  • Loading branch information
pedro-at-decenomy committed Sep 29, 2021
1 parent 08f9f01 commit 0c31c42
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 105 deletions.
28 changes: 28 additions & 0 deletions dsw.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import bitcoinjs from 'bitcoinjs-lib';

/**
* Abstract Class DSW.
*
* @class DSW
*/
export 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;
}
}
}
77 changes: 2 additions & 75 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,75 +1,2 @@
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)
});
}
}
export { Sapphire } from './sapphire.js';
export { Jackpot } from './jackpot.js';
24 changes: 24 additions & 0 deletions jackpot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { DSW } from './dsw.js'

/**
* 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)
});
}
}
60 changes: 30 additions & 30 deletions sandbox.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
import bitcoinjs from 'bitcoinjs-lib';
// 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'));
// 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();

Expand Down
25 changes: 25 additions & 0 deletions sapphire.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { DSW } from './dsw.js'

/**
* 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)
});
}

}

0 comments on commit 0c31c42

Please sign in to comment.