-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbase58check.types.js
177 lines (152 loc) · 4.67 KB
/
base58check.types.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
module.exports._types = true;
/**
* @typedef Base58Check
* @prop {Create} create
*/
/**
* @callback Create
* @param {Base58CheckOpts} [opts]
*/
/**
* @typedef base58Check
* @prop {Checksum} checksum
* @prop {Decode} decode
* @prop {DecodeHex} decodeHex
* @prop {Encode} encode
* @prop {EncodeHex} encodeHex
* @prop {Verify} verify
* @prop {VerifyHex} verifyHex
* @prop {Function} _checksumHexRaw
* @prop {Function} _encodeXKey
* @prop {Function} _encodePrivateKeyHex
* @prop {Function} _encodePubKeyHashHex
* @prop {Function} _setVersion
*/
/**
* Base58Check Options, see https://github.com/dashhive/dashkeys.js/blob/1f0f4e0d0aabf9e68d94925d660f00666f502391/dashkeys.js#L38 and see https://bitcoin.stackexchange.com/questions/38878/how-does-the-bip32-version-bytes-convert-to-base58
* @typedef Base58CheckOpts
* @prop {String} [opts.dictionary] - "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz" for Dash / Bitcoin Base58
* @prop {String} [opts.privateKeyVersion] - "cc" for mainnet (default), "ef" for testnet, '80' for bitcoin
* @prop {String} [opts.pubKeyHashVersion] - "4c" for mainnet (default), "8c" for testnet, "00" for bitcoin
* @prop {String} [opts.xprvVersion] - "4c" for mainnet (default), "8c" for testnet, "00" for bitcoin
* @prop {String} [opts.xprvVersion] - "0488ade4" for "xprv" on mainnet (default), "04358394" for "tprv" on testnet
* @prop {String} [opts.xpubVersion] - "0488b21e" for "xpub" on mainnet (default), "043587cf" for "tpub" on testnet
*/
/**
* @typedef {PrivateParts|PubKeyHashParts|XPrvParts|XPubParts} Parts
*/
/**
* @typedef PrivatePartial
* @prop {String} privateKey
*/
/**
* @typedef PubKeyHashPartial
* @prop {String} pubKeyHash
*/
/**
* @typedef XPrvPartial
* @prop {String} xprv
*/
/**
* @typedef XPubPartial
* @prop {String} xpub
*/
/**
* @typedef {PrivatePartial|PubKeyHashPartial|XPrvPartial|XPubPartial} PartsPartial
*/
/**
* @typedef PartsOptionalPartial
* @prop {String} [check]
* @prop {true} [compressed]
* @prop {String} [version]
*/
/**
* @typedef {PartsPartial & PartsOptionalPartial} EncodeParts
*/
/** @typedef {"private"|"pkh"|"xprv"|"xpub"|""} KeyType */
/**
* @typedef PrivateParts
* @prop {String} check - the 4 checksum bytes
* @prop {true} compressed - expect (public key) hash to be of the X value only
* @prop {String} privateKey - hex private key
* @prop {String} [pubKeyHash] - hex (public key) hash
* @prop {KeyType} [type] - "private"
* @prop {Boolean} [valid] - checksum passed
* @prop {String} version - 1 magic bytes
*/
/**
* @typedef PubKeyHashParts
* @prop {String} check - the 4 checksum bytes
* @prop {String} pubKeyHash - hex sha256-ripemd160 hash of public key
* @prop {KeyType} [type] - "pkh"
* @prop {Boolean} [valid] - checksum passed
* @prop {String} version - 1 magic bytes
*/
/**
* @typedef XPrvParts
* @prop {String} check - the 4 checksum bytes
* @prop {String} xprv - hex extended private key
* @prop {KeyType} [type] - "xprv"
* @prop {Boolean} [valid] - checksum passed
* @prop {String} version - 4 magic bytes
* @prop {String} [xpub] - hex extended public key
*/
/**
* @typedef XPubParts
* @prop {String} check - the 4 checksum bytes
* @prop {KeyType} [type] - "xpub"
* @prop {Boolean} [valid] - checksum passed
* @prop {String} version - 4 magic bytes
* @prop {String} xpub - hex extended public key
*/
/**
* @callback Checksum
* @param {Parts|EncodeParts} parts - private key or public hash or xkey parts
* @returns {Promise<String>} - 8 hex chars (4 bytes) of checksum
*/
/**
* @callback Decode
* @param {String} base58check - WIF, Payment Address, xPrv, or xPub
* @param {DecodeOpts} opts
* @returns {Parts}
*/
/**
* @callback DecodeHex
* @param {String} hex - magic version bytes + data + checksum
* @param {DecodeOpts} [opts]
* @returns {Parts}
*/
/**
* @typedef DecodeOpts
* @prop {[String, String]} [versions]
* @prop {[String, String]} [xversions]
*/
/**
* @callback Verify
* @param {String} base58check - WIF, Payment Address, xPrv, or xPub
* @param {VerifyOpts} [opts]
* @returns {Promise<Parts>}
* @throws {Error}
*/
/**
* @callback VerifyHex
* @param {String} hex - magic version bytes + data + checksum
* @param {VerifyOpts} [opts]
* @returns {Promise<Parts>}
* @throws {Error}
*/
/**
* @typedef {DecodeOpts & VerifyOptsPartial} VerifyOpts
* @typedef VerifyOptsPartial
* @prop {Boolean} [verify] - set 'false' to set 'valid' false rather than throw
*/
/**
* @callback Encode
* @param {EncodeParts} parts
* @returns {Promise<String>} - base58check WIF, Payment Address, xPrv, or xPub
*/
/**
* @callback EncodeHex
* @param {EncodeParts} parts
* @returns {Promise<String>} - hex magic version bytes + key + checksum
*/