Skip to content

Commit cddfa2e

Browse files
committed
ref!: drop node:crypto support
1 parent 570d5af commit cddfa2e

File tree

1 file changed

+1
-23
lines changed

1 file changed

+1
-23
lines changed

dashhd.js

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ var DashHd = ("object" === typeof module && exports) || {};
8585
const PUBLIC = false;
8686

8787
//@ts-ignore
88-
let Crypto = window.crypto || require("crypto");
88+
let Crypto = globalThis.crypto;
8989

9090
//@ts-ignore
9191
/** @type {import('dashkeys').DashKeys} */
@@ -99,8 +99,6 @@ var DashHd = ("object" === typeof module && exports) || {};
9999
* @param {Object.<String, any>} [opts]
100100
*/
101101
Utils.decode = async function (base58key, opts) {
102-
//@ts-ignore - wth?
103-
let DashKeys = window.DashKeys || require("dashkeys");
104102
//@ts-ignore
105103
return await DashKeys.decode(base58key, opts);
106104
};
@@ -111,8 +109,6 @@ var DashHd = ("object" === typeof module && exports) || {};
111109
* @param {Number} [opts.version]
112110
*/
113111
Utils.encodeXPrv = async function (keyBytes, opts) {
114-
//@ts-ignore - wth?
115-
let DashKeys = window.DashKeys || require("dashkeys");
116112
let version = "xprv";
117113
if (opts?.version) {
118114
version = opts?.version.toString(16);
@@ -127,8 +123,6 @@ var DashHd = ("object" === typeof module && exports) || {};
127123
* TODO - pass tpub
128124
*/
129125
Utils.encodeXPub = async function (keyBytes) {
130-
//@ts-ignore - wth?
131-
let DashKeys = window.DashKeys || require("dashkeys");
132126
//@ts-ignore
133127
return await DashKeys.encodeKey(keyBytes, { version: "xpub" });
134128
};
@@ -177,30 +171,19 @@ var DashHd = ("object" === typeof module && exports) || {};
177171

178172
/** @type {HDHasher} */
179173
Utils.ripemd160sum = async function (bytes) {
180-
//@ts-ignore
181-
let DashKeys = window.DashKeys || require("dashkeys");
182174
//@ts-ignore
183175
return await DashKeys.utils.ripemd160sum(bytes);
184176
};
185177

186178
/** @type {HDHasher} */
187179
Utils.sha256sum = async function (bytes) {
188-
if (!Crypto.subtle) {
189-
let sha256 = Crypto.createHash("sha256").update(bytes).digest();
190-
return new Uint8Array(sha256);
191-
}
192180
let arrayBuffer = await Crypto.subtle.digest("SHA-256", bytes);
193181
let hashBytes = new Uint8Array(arrayBuffer);
194182
return hashBytes;
195183
};
196184

197185
/** @type {HDHmac} */
198186
Utils.sha512hmac = async function (entropy, data) {
199-
if (!Crypto.subtle) {
200-
let buf = Crypto.createHmac("sha512", entropy).update(data).digest();
201-
return new Uint8Array(buf);
202-
}
203-
204187
/** @type {"raw"|"pkcs8"|"spki"} */
205188
let format = "raw";
206189
let algo = {
@@ -241,11 +224,6 @@ var DashHd = ("object" === typeof module && exports) || {};
241224

242225
/** @type {HDSecureErase} */
243226
Utils.secureErase = function (buf) {
244-
if (!Crypto.getRandomValues) {
245-
Crypto.randomBytes(buf.length).copy(buf);
246-
return;
247-
}
248-
249227
Crypto.getRandomValues(buf);
250228
};
251229

0 commit comments

Comments
 (0)