@@ -5,10 +5,17 @@ const sha256f = require("sha256-file");
55const config = require ( "./config" ) ;
66
77class BitFact {
8- constructor ( options , chain = config . DEFAULT_CHAIN ) {
9- this . options = options ; // ie: { provider: 'https://...' privateKey: '4109c982fa'}
10- this . chain = chain ; // ie: { chain: "ropsten" }
11- this . web3 = new Web3 ( options . provider ) ;
8+ constructor ( setup ) {
9+ /* setup example
10+ {
11+ "provider": "https://eth-ropsten.alchemyapi.io/v2/01GesjZxWhg-KMfDuLH_-aUOmV-bRBaf",
12+ "privateKey": "67ccc16df9e7581ec11e7483c7eba5f2ae937b7ab37db413bad46470165629cf",
13+ "options": { "chain": "ropsten" }
14+ }
15+ */
16+ this . privateKey = setup . privateKey ; // ie: 67ccc16df9e7581ec11e7483c7eba5f2ae937b7ab37db413bad46470165629cf
17+ this . options = setup . options ? setup . options : config . DEFAULT_OPTIONS ; // ie: { chain: "ropsten" }
18+ this . web3 = new Web3 ( setup . provider ) ;
1219 }
1320
1421 async stampText ( text , memo ) {
@@ -62,7 +69,7 @@ class BitFact {
6269 txid,
6370 hash : fact . hash ,
6471 meta : {
65- info : this . chain ,
72+ info : this . options ,
6673 fact,
6774 tx,
6875 } ,
@@ -94,8 +101,8 @@ class BitFact {
94101
95102 async signTx ( txObj ) {
96103 // Signs a TX object.
97- const tx = new Tx . Transaction ( txObj , this . chain ) ;
98- const pk = Buffer . from ( this . options . privateKey , "hex" ) ;
104+ const tx = new Tx . Transaction ( txObj , this . options ) ;
105+ const pk = Buffer . from ( this . privateKey , "hex" ) ;
99106
100107 tx . sign ( pk ) ;
101108 return tx . serialize ( ) ;
@@ -116,7 +123,7 @@ class BitFact {
116123
117124 async getPublicKey ( ) {
118125 return await this . web3 . eth . accounts . privateKeyToAccount (
119- this . options . privateKey . toString ( )
126+ this . privateKey . toString ( )
120127 ) . address ;
121128 }
122129
0 commit comments