@shakesco/silent 1.0.5 → 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -19,10 +19,10 @@ const {
19
19
  SilentPaymentDestination,
20
20
  SilentPaymentBuilder,
21
21
  ECPrivateInfo,
22
- Network,
22
+ Network: SilentNetwork,
23
23
  BitcoinScriptOutput,
24
24
  bip32,
25
- bip39
25
+ bip39,
26
26
  } = shakesco;
27
27
  ```
28
28
 
@@ -35,19 +35,19 @@ You can generate a silent payment address in three ways:
35
35
 
36
36
  If you are not a wallet provider, use this method. More specifically, you can make the user sign a message and then derive `b_scan` and `b_spend` from the resulting [signature](https://cryptobook.nakov.com/digital-signatures/ecdsa-sign-verify-messages#ecdsa-sign) (Use `r` as `b_scan` and `s` as `b_spend` or vice versa).
37
37
 
38
- >⚠️ If you are not using this method, ensure that a cryptographically secure random number generator is being used.
38
+ > ⚠️ If you are not using this method, ensure that a cryptographically secure random number generator is being used.
39
39
 
40
40
  ```js {filename="index.js"}
41
41
  function main() {
42
- const b_scan = "";
43
- const b_spend = "";
44
- const keys = KeyGeneration.fromPrivateKeys({
42
+ const b_scan = "";
43
+ const b_spend = "";
44
+ const keys = KeyGeneration.fromPrivateKeys({
45
45
  b_scan: b_scan,
46
46
  b_spend: b_spend,
47
- network: "testnet",
48
- });
49
- const silentPaymentAddress = keys.toAddress();
50
- console.log(silentPaymentAddress); // Silent payment address
47
+ network: SilentNetwork.Testnet,
48
+ });
49
+ const silentPaymentAddress = keys.toAddress();
50
+ console.log(silentPaymentAddress); // Silent payment address
51
51
  }
52
52
  ```
53
53
 
@@ -62,11 +62,11 @@ function main() {
62
62
  const silentPaymentAddress = keys.toAddress();
63
63
  console.log(silentPaymentAddress);
64
64
 
65
- // const seed = bip39.mnemonicToSeedSync(mnemonic);
66
- // const node = bip32.fromSeed(seed);
67
- // const keys = KeyGeneration.fromHd(node);
68
- // const silentPaymentAddress = keys.toAddress();
69
- // console.log(silentPaymentAddress);
65
+ // const seed = bip39.mnemonicToSeedSync(mnemonic);
66
+ // const node = bip32.fromSeed(seed);
67
+ // const keys = KeyGeneration.fromHd(node);
68
+ // const silentPaymentAddress = keys.toAddress();
69
+ // console.log(silentPaymentAddress);
70
70
  }
71
71
  ```
72
72
 
@@ -76,15 +76,15 @@ Create a change silent payment address that won't break privacy. Consider a scen
76
76
 
77
77
  ```js {filename="index.js"}
78
78
  function main() {
79
- const b_scan = "";
80
- const b_spend = "";
81
- const keys = KeyGeneration.fromPrivateKeys({
79
+ const b_scan = "";
80
+ const b_spend = "";
81
+ const keys = KeyGeneration.fromPrivateKeys({
82
82
  b_scan: b_scan,
83
83
  b_spend: b_spend,
84
- network: "testnet",
85
- });
86
- const changeSilentPaymentAddress = keys.toLabeledSilentPaymentAddress(0); //should always be zero!(https://github.com/bitcoin/bips/blob/master/bip-0352.mediawiki#labels_for_change)
87
- console.log(changeSilentPaymentAddress.toAddress()); // change silent payment address
84
+ network: SilentNetwork.Testnet,
85
+ });
86
+ const changeSilentPaymentAddress = keys.toLabeledSilentPaymentAddress(0); //should always be zero!(https://github.com/bitcoin/bips/blob/master/bip-0352.mediawiki#labels_for_change)
87
+ console.log(changeSilentPaymentAddress.toAddress()); // change silent payment address
88
88
  }
89
89
  ```
90
90
 
@@ -100,39 +100,39 @@ You will need:
100
100
 
101
101
  ```js {filename="index.js"}
102
102
  function main() {
103
- const addressPubKeys = KeyGeneration.fromAddress(silentPaymentAddress);
104
- const vinOutpoints = [
103
+ const addressPubKeys = KeyGeneration.fromAddress(silentPaymentAddress);
104
+ const vinOutpoints = [
105
105
  {
106
- txid: "367e24cac43a7d77621ceb1cbc1cf4a7719fc81b05b07b38f99b043f4e8b95dc",
107
- index: 1,
106
+ txid: "367e24cac43a7d77621ceb1cbc1cf4a7719fc81b05b07b38f99b043f4e8b95dc",
107
+ index: 1,
108
108
  },
109
- ];
109
+ ];
110
110
 
111
- const pubkeys = [
111
+ const pubkeys = [
112
112
  "025c471f0e7d30d6f9095058bbaedaf13e1de67dbfcbe8328e6378d2a3bfb5cfd0",
113
- ];
114
- const UTXOPrivatekey = "";
115
- const builder = new SilentPaymentBuilder({
113
+ ];
114
+ const UTXOPrivatekey = "";
115
+ const builder = new SilentPaymentBuilder({
116
116
  vinOutpoints: vinOutpoints,
117
117
  pubkeys: pubkeys,
118
- }).createOutputs(
118
+ }).createOutputs(
119
119
  [
120
- new ECPrivateInfo(
120
+ new ECPrivateInfo(
121
121
  UTXOPrivatekey,
122
122
  false // If the output is from a taproot address
123
- ),
123
+ ),
124
124
  ],
125
125
  [
126
- new SilentPaymentDestination({
126
+ new SilentPaymentDestination({
127
127
  amount: 1000,
128
- network: Network.Testnet,
128
+ network: SilentNetwork.Testnet,
129
129
  version: 0,
130
130
  scanPubkey: addressPubKeys.B_scan,
131
131
  spendPubkey: addressPubKeys.B_spend,
132
- }),
132
+ }),
133
133
  ]
134
- );
135
- console.log(builder[silentPaymentAddress][0]); // Access the taproot address and send 1000 satoshis
134
+ );
135
+ console.log(builder[silentPaymentAddress][0]); // Access the taproot address and send 1000 satoshis
136
136
  }
137
137
  ```
138
138
 
@@ -148,30 +148,30 @@ For more info, go [here](https://github.com/bitcoin/bips/blob/master/bip-0352.me
148
148
 
149
149
  ```js {filename="index.js"}
150
150
  function main() {
151
- const vinOutpoints = [
151
+ const vinOutpoints = [
152
152
  {
153
- txid: "367e24cac43a7d77621ceb1cbc1cf4a7719fc81b05b07b38f99b043f4e8b95dc",
154
- index: 1,
153
+ txid: "367e24cac43a7d77621ceb1cbc1cf4a7719fc81b05b07b38f99b043f4e8b95dc",
154
+ index: 1,
155
155
  },
156
- ];
156
+ ];
157
157
 
158
- const pubkeys = [
158
+ const pubkeys = [
159
159
  "025c471f0e7d30d6f9095058bbaedaf13e1de67dbfcbe8328e6378d2a3bfb5cfd0",
160
- ];
161
- const search = new SilentPaymentBuilder({
160
+ ];
161
+ const search = new SilentPaymentBuilder({
162
162
  vinOutpoints: vinOutpoints,
163
163
  pubkeys: pubkeys,
164
- network: Network.Testnet,
165
- }).scanOutputs(keys.b_scan, keys.B_spend, [
164
+ network: SilentNetwork.Testnet,
165
+ }).scanOutputs(keys.b_scan, keys.B_spend, [
166
166
  new BitcoinScriptOutput(
167
- "5120fdcb28bcea339a5d36d0c00a3e110b837bf1151be9e7ac9a8544e18b2f63307d",
168
- BigInt(1000)
167
+ "5120fdcb28bcea339a5d36d0c00a3e110b837bf1151be9e7ac9a8544e18b2f63307d",
168
+ BigInt(1000)
169
169
  ),
170
- ]);
170
+ ]);
171
171
 
172
- console.log(
172
+ console.log(
173
173
  search[builder[keys.toAddress()][0].address.pubkey.toString("hex")].output
174
- );
174
+ );
175
175
  }
176
176
  ```
177
177
 
@@ -189,22 +189,22 @@ First, you will need:
189
189
 
190
190
  ```js {filename="index.js"}
191
191
  function main() {
192
- const vinOutpoints = [
193
- {
194
- txid: "367e24cac43a7d77621ceb1cbc1cf4a7719fc81b05b07b38f99b043f4e8b95dc",
195
- index: 1,
196
- },
197
- ];
198
-
199
- const pubkeys = [
192
+ const vinOutpoints = [
193
+ {
194
+ txid: "367e24cac43a7d77621ceb1cbc1cf4a7719fc81b05b07b38f99b043f4e8b95dc",
195
+ index: 1,
196
+ },
197
+ ];
198
+
199
+ const pubkeys = [
200
200
  "025c471f0e7d30d6f9095058bbaedaf13e1de67dbfcbe8328e6378d2a3bfb5cfd0",
201
- ];
202
- const private_key = new SilentPaymentBuilder({
201
+ ];
202
+ const private_key = new SilentPaymentBuilder({
203
203
  vinOutpoints: vinOutpoints,
204
204
  pubkeys: pubkeys,
205
- }).spendOutputs(keys.b_scan, keys.b_spend);
205
+ }).spendOutputs(keys.b_scan, keys.b_spend);
206
206
 
207
- console.log(private_key); // use this to build a taproot transaction with bitcoinjs: https://github.com/bitcoinjs/bitcoinjs-lib
207
+ console.log(private_key); // use this to build a taproot transaction with bitcoinjs: https://github.com/bitcoinjs/bitcoinjs-lib
208
208
  }
209
209
  ```
210
210
 
@@ -214,7 +214,4 @@ Thats it! 🎊🎊🎊
214
214
 
215
215
  ### Contribute
216
216
 
217
- If you love what we do to progress privacy, [contribute](https://me-qr.com/text/vPod5qN0 "btc_addr") to further development
218
-
219
- <img src="./images/bitcoin.png" alt="btc_addr" style="display: inline-block; margin-right: 100px; margin-left: 70px;" width="200">
220
- <img src="./images/silent.png" alt="silent_addr" width="200" style="display: inline-block; margin-right: 10px;">
217
+ If you love what we do to progress privacy, [contribute](https://donate.shakesco.com/@shakesco.sns "shakesco_donate") to further development
@@ -13,9 +13,11 @@ const Network = require("../utils/network");
13
13
  const { generateLabel, tweakAdd } = require("../utils/label");
14
14
  const bip32 = BIP32Factory(tinysecp);
15
15
 
16
- const SCAN_PATH = "m/352'/1'/0'/1'/0";
16
+ const MAINNET_SCAN_PATH = "m/352'/0'/0'/1'/0";
17
+ const MAINNET_SPEND_PATH = "m/352'/0'/0'/0'/0";
17
18
 
18
- const SPEND_PATH = "m/352'/1'/0'/0'/0";
19
+ const TESTNET_SCAN_PATH = "m/352'/1'/0'/1'/0";
20
+ const TESTNET_SPEND_PATH = "m/352'/1'/0'/0'/0";
19
21
 
20
22
  class SilentPaymentAddress {
21
23
  static get regex() {
@@ -163,6 +165,10 @@ class KeyGeneration extends SilentPaymentAddress {
163
165
  */
164
166
 
165
167
  static fromHd(bip32, { hrp = "sp", version = 0 } = {}) {
168
+ const SCAN_PATH = hrp == "sp" ? MAINNET_SCAN_PATH : TESTNET_SCAN_PATH;
169
+
170
+ const SPEND_PATH = hrp == "sp" ? MAINNET_SPEND_PATH : TESTNET_SPEND_PATH;
171
+
166
172
  const scanDerivation = bip32.derivePath(SCAN_PATH);
167
173
  const spendDerivation = bip32.derivePath(SPEND_PATH);
168
174
  return new KeyGeneration({
@@ -170,7 +176,7 @@ class KeyGeneration extends SilentPaymentAddress {
170
176
  b_spend: ec.keyFromPrivate(spendDerivation.privateKey).getPrivate(),
171
177
  B_scan: ec.keyFromPrivate(scanDerivation.privateKey).getPublic(),
172
178
  B_spend: ec.keyFromPrivate(spendDerivation.privateKey).getPublic(),
173
- network: hrp == "tsp" ? Network.Testnet : Network.Mainnet,
179
+ network: hrp == "sp" ? Network.Mainnet : Network.Testnet,
174
180
  version: version,
175
181
  });
176
182
  }
@@ -182,9 +188,12 @@ class KeyGeneration extends SilentPaymentAddress {
182
188
  * @returns
183
189
  */
184
190
 
185
- static fromMnemonic(mnemonic, { hrp = "sp", version = 0 } = {}) {
191
+ static fromMnemonic(
192
+ mnemonic,
193
+ { password = "", hrp = "sp", version = 0 } = {}
194
+ ) {
186
195
  return KeyGeneration.fromHd(
187
- bip32.fromSeed(bip39.mnemonicToSeedSync(mnemonic)),
196
+ bip32.fromSeed(bip39.mnemonicToSeedSync(mnemonic, password)),
188
197
  {
189
198
  hrp: hrp,
190
199
  version: version,
package/package.json CHANGED
@@ -1,23 +1,23 @@
1
- {
2
- "name": "@shakesco/silent",
3
- "version": "1.0.5",
4
- "description": "Bitcoin Silent Payments",
5
- "main": "index.js",
6
- "author": "Shawn Kimtai",
7
- "license": "MIT",
8
- "keywords": [
9
- "shakesco",
10
- "shakespay",
11
- "private",
12
- "bitcoin",
13
- "silent payments",
14
- "ECDH"
15
- ],
16
- "dependencies": {
17
- "bip32": "^5.0.0-rc.0",
18
- "bip39": "^3.1.0",
19
- "bn.js": "^5.2.1",
20
- "elliptic": "6.6.0",
21
- "tiny-secp256k1": "^2.2.3"
22
- }
23
- }
1
+ {
2
+ "name": "@shakesco/silent",
3
+ "version": "1.0.7",
4
+ "description": "Bitcoin Silent Payments",
5
+ "main": "index.js",
6
+ "author": "Shawn Kimtai",
7
+ "license": "MIT",
8
+ "keywords": [
9
+ "shakesco",
10
+ "shakespay",
11
+ "private",
12
+ "bitcoin",
13
+ "silent payments",
14
+ "ECDH"
15
+ ],
16
+ "dependencies": {
17
+ "bip32": "^5.0.0-rc.0",
18
+ "bip39": "^3.1.0",
19
+ "bn.js": "^5.2.1",
20
+ "elliptic": "6.6.1",
21
+ "tiny-secp256k1": "^2.2.3"
22
+ }
23
+ }
Binary file
package/images/silent.png DELETED
Binary file