@shakesco/silent 1.0.6 → 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 +65 -65
- package/classes/KeyGeneration.js +14 -5
- package/package.json +23 -23
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
|
-
|
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
|
-
|
43
|
-
|
44
|
-
|
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:
|
48
|
-
|
49
|
-
|
50
|
-
|
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
|
-
|
80
|
-
|
81
|
-
|
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:
|
85
|
-
|
86
|
-
|
87
|
-
|
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
|
-
|
104
|
-
|
103
|
+
const addressPubKeys = KeyGeneration.fromAddress(silentPaymentAddress);
|
104
|
+
const vinOutpoints = [
|
105
105
|
{
|
106
|
-
|
107
|
-
|
106
|
+
txid: "367e24cac43a7d77621ceb1cbc1cf4a7719fc81b05b07b38f99b043f4e8b95dc",
|
107
|
+
index: 1,
|
108
108
|
},
|
109
|
-
|
109
|
+
];
|
110
110
|
|
111
|
-
|
111
|
+
const pubkeys = [
|
112
112
|
"025c471f0e7d30d6f9095058bbaedaf13e1de67dbfcbe8328e6378d2a3bfb5cfd0",
|
113
|
-
|
114
|
-
|
115
|
-
|
113
|
+
];
|
114
|
+
const UTXOPrivatekey = "";
|
115
|
+
const builder = new SilentPaymentBuilder({
|
116
116
|
vinOutpoints: vinOutpoints,
|
117
117
|
pubkeys: pubkeys,
|
118
|
-
|
118
|
+
}).createOutputs(
|
119
119
|
[
|
120
|
-
|
120
|
+
new ECPrivateInfo(
|
121
121
|
UTXOPrivatekey,
|
122
122
|
false // If the output is from a taproot address
|
123
|
-
|
123
|
+
),
|
124
124
|
],
|
125
125
|
[
|
126
|
-
|
126
|
+
new SilentPaymentDestination({
|
127
127
|
amount: 1000,
|
128
|
-
network:
|
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
|
-
|
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
|
-
|
151
|
+
const vinOutpoints = [
|
152
152
|
{
|
153
|
-
|
154
|
-
|
153
|
+
txid: "367e24cac43a7d77621ceb1cbc1cf4a7719fc81b05b07b38f99b043f4e8b95dc",
|
154
|
+
index: 1,
|
155
155
|
},
|
156
|
-
|
156
|
+
];
|
157
157
|
|
158
|
-
|
158
|
+
const pubkeys = [
|
159
159
|
"025c471f0e7d30d6f9095058bbaedaf13e1de67dbfcbe8328e6378d2a3bfb5cfd0",
|
160
|
-
|
161
|
-
|
160
|
+
];
|
161
|
+
const search = new SilentPaymentBuilder({
|
162
162
|
vinOutpoints: vinOutpoints,
|
163
163
|
pubkeys: pubkeys,
|
164
|
-
network:
|
165
|
-
|
164
|
+
network: SilentNetwork.Testnet,
|
165
|
+
}).scanOutputs(keys.b_scan, keys.B_spend, [
|
166
166
|
new BitcoinScriptOutput(
|
167
|
-
|
168
|
-
|
167
|
+
"5120fdcb28bcea339a5d36d0c00a3e110b837bf1151be9e7ac9a8544e18b2f63307d",
|
168
|
+
BigInt(1000)
|
169
169
|
),
|
170
|
-
|
170
|
+
]);
|
171
171
|
|
172
|
-
|
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
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
192
|
+
const vinOutpoints = [
|
193
|
+
{
|
194
|
+
txid: "367e24cac43a7d77621ceb1cbc1cf4a7719fc81b05b07b38f99b043f4e8b95dc",
|
195
|
+
index: 1,
|
196
|
+
},
|
197
|
+
];
|
198
|
+
|
199
|
+
const pubkeys = [
|
200
200
|
"025c471f0e7d30d6f9095058bbaedaf13e1de67dbfcbe8328e6378d2a3bfb5cfd0",
|
201
|
-
|
202
|
-
|
201
|
+
];
|
202
|
+
const private_key = new SilentPaymentBuilder({
|
203
203
|
vinOutpoints: vinOutpoints,
|
204
204
|
pubkeys: pubkeys,
|
205
|
-
|
205
|
+
}).spendOutputs(keys.b_scan, keys.b_spend);
|
206
206
|
|
207
|
-
|
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
|
|
package/classes/KeyGeneration.js
CHANGED
@@ -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
|
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
|
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 == "
|
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(
|
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.
|
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.
|
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
|
+
}
|