Skip to content

Commit eeef44c

Browse files
committed
ref: update types and fix checker issues
1 parent 3adbdc3 commit eeef44c

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

base58check.types.js

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -119,15 +119,13 @@ module.exports._types = true;
119119
/**
120120
* @callback Checksum
121121
* @param {Parts|EncodeParts} parts - private key or public hash or xkey parts
122-
* @returns {String} - 8 hex chars (4 bytes) of checksum
122+
* @returns {Promise<String>} - 8 hex chars (4 bytes) of checksum
123123
*/
124124

125125
/**
126126
* @callback Decode
127127
* @param {String} base58check - WIF, Payment Address, xPrv, or xPub
128-
* @param {Object} opts
129-
* @param {[String, String]} opts.versions
130-
* @param {[String, String]} opts.xversions
128+
* @param {DecodeOpts} opts
131129
* @returns {Parts}
132130
*/
133131

@@ -148,33 +146,32 @@ module.exports._types = true;
148146
* @callback Verify
149147
* @param {String} base58check - WIF, Payment Address, xPrv, or xPub
150148
* @param {VerifyOpts} [opts]
151-
* @returns {Parts}
149+
* @returns {Promise<Parts>}
152150
* @throws {Error}
153151
*/
154152

155153
/**
156154
* @callback VerifyHex
157155
* @param {String} hex - magic version bytes + data + checksum
158156
* @param {VerifyOpts} [opts]
159-
* @returns {Parts}
157+
* @returns {Promise<Parts>}
160158
* @throws {Error}
161159
*/
162160

163161
/**
164-
* @typedef VerifyOpts
162+
* @typedef {DecodeOpts & VerifyOptsPartial} VerifyOpts
163+
* @typedef VerifyOptsPartial
165164
* @prop {Boolean} [verify] - set 'false' to set 'valid' false rather than throw
166-
* @param {[String, String]} [versions]
167-
* @param {[String, String]} [xversions]
168165
*/
169166

170167
/**
171168
* @callback Encode
172169
* @param {EncodeParts} parts
173-
* @returns {String} - base58check WIF, Payment Address, xPrv, or xPub
170+
* @returns {Promise<String>} - base58check WIF, Payment Address, xPrv, or xPub
174171
*/
175172

176173
/**
177174
* @callback EncodeHex
178175
* @param {EncodeParts} parts
179-
* @returns {String} - hex magic version bytes + key + checksum
176+
* @returns {Promise<String>} - hex magic version bytes + key + checksum
180177
*/

dashkeys.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
/** @typedef {import('./base-x.types.js').DecodeUnsafe} BaseXDecodeUnsafe */
55
/** @typedef {import('./base-x.types.js').Encode} BaseXEncode */
66
/** @typedef {import('./base58check.types.js').Base58Check} Base58Check */
7+
/** @typedef {import('./base58check.types.js').base58Check} Base58CheckInstance */
78
/** @typedef {import('./base58check.types.js').Checksum} Base58CheckChecksum */
89
/** @typedef {import('./base58check.types.js').Create} Base58CheckCreate */
910
/** @typedef {import('./base58check.types.js').Decode} Base58CheckDecode */
@@ -37,6 +38,8 @@
3738
* @prop {WifToAddress} wifToAddr
3839
* @prop {WifToPrivateKey} wifToPrivKey
3940
* @prop {DashKeysUtils} utils
41+
* @prop {EncodeKeyUint8Array} _encodeXKey
42+
* @prop {Base58CheckInstance} _dash58check
4043
*/
4144

4245
/**
@@ -456,7 +459,7 @@ var DashKeys = ("object" === typeof module && exports) || {};
456459

457460
/** @type {Base58CheckVerify} */
458461
b58c.verify = async function (b58Addr, opts) {
459-
let bytes = bs58.decode(b58Addr, opts);
462+
let bytes = bs58.decode(b58Addr);
460463
let hex = Utils.bytesToHex(bytes);
461464
return await b58c.verifyHex(hex, opts);
462465
};
@@ -964,6 +967,8 @@ var DashKeys = ("object" === typeof module && exports) || {};
964967

965968
/** @type {AddressToPubKeyHash} */
966969
_DashKeys.addrToPkh = async function (address, opts) {
970+
/** @type {Base58CheckPubKeyHashParts} */
971+
//@ts-ignore - address has pkh parts
967972
let addrParts = await _DashKeys.decode(address, opts);
968973
let shaRipeBytes = Utils.hexToBytes(addrParts.pubKeyHash);
969974

@@ -972,6 +977,7 @@ var DashKeys = ("object" === typeof module && exports) || {};
972977

973978
/** @type {DecodeBase58Check} */
974979
_DashKeys.decode = async function (keyB58c, opts) {
980+
/* jshint maxcomplexity:35 */
975981
let _opts = {};
976982
if (opts?.version) {
977983
switch (opts.version) {
@@ -1039,7 +1045,7 @@ var DashKeys = ("object" === typeof module && exports) || {};
10391045
let check = await dash58check.checksum(parts);
10401046
let valid = parts.check === check;
10411047
if (!valid) {
1042-
if (false !== opts.validate) {
1048+
if (false !== opts?.validate) {
10431049
// to throw the inner error
10441050
await dash58check.verify(keyB58c, _opts);
10451051
}
@@ -1220,7 +1226,11 @@ var DashKeys = ("object" === typeof module && exports) || {};
12201226
/** @type {PublicKeyToAddress} */
12211227
_DashKeys.pubkeyToAddr = async function (pubBytes, opts) {
12221228
let shaRipeBytes = await _DashKeys.pubkeyToPkh(pubBytes);
1223-
let addr = await _DashKeys.pkhToAddr(shaRipeBytes, opts);
1229+
let addr = await _DashKeys.pkhToAddr(
1230+
shaRipeBytes,
1231+
//@ts-ignore - has version property
1232+
opts,
1233+
);
12241234

12251235
return addr;
12261236
};
@@ -1276,6 +1286,7 @@ var DashKeys = ("object" === typeof module && exports) || {};
12761286
/**
12771287
* @callback PrivateKeyToWif
12781288
* @param {Uint8Array} privBytes
1289+
* @param {EncodeKeyUint8ArrayOpts} [opts]
12791290
* @returns {Promise<String>} - wif
12801291
*/
12811292

@@ -1305,13 +1316,14 @@ if ("object" === typeof module) {
13051316
/**
13061317
* @callback AddressToPubKeyHash
13071318
* @param {String} addr - Base58Check encoded version + pkh + check
1319+
* @param {DecodeOpts} [opts]
13081320
* @returns {Promise<Uint8Array>} - pkh bytes (no version or check, NOT Base58Check)
13091321
*/
13101322

13111323
/**
13121324
* @callback DecodeBase58Check
13131325
* @param {String} keyB58c - addr, wif, or xkey (xprv, xpub)
1314-
* @param {DecodeOpts} opts
1326+
* @param {DecodeOpts} [opts]
13151327
* @returns {Promise<Base58CheckParts>}
13161328
*/
13171329

0 commit comments

Comments
 (0)