@leocuvee/turtlecoin-utils 0.0.14
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/.github/workflows/ci.yml +27 -0
- package/.idea/codeStyles/codeStyleConfig.xml +5 -0
- package/.idea/inspectionProfiles/Project_Default.xml +7 -0
- package/.idea/misc.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/turtlecoin-utils.iml +12 -0
- package/.idea/vcs.xml +6 -0
- package/.travis.yml +11 -0
- package/CONTRIBUTING.md +3 -0
- package/LICENSE +674 -0
- package/README.md +203 -0
- package/config.json +7 -0
- package/docs/.nojekyll +0 -0
- package/docs/CNAME +1 -0
- package/docs/assets/css/main.css +2321 -0
- package/docs/assets/images/icons.png +0 -0
- package/docs/assets/images/icons@2x.png +0 -0
- package/docs/assets/images/widgets.png +0 -0
- package/docs/assets/images/widgets@2x.png +0 -0
- package/docs/assets/js/main.js +1 -0
- package/docs/assets/js/search.js +3 -0
- package/docs/classes/address.html +964 -0
- package/docs/classes/addressprefix.html +431 -0
- package/docs/classes/block.html +965 -0
- package/docs/classes/blocktemplate.html +695 -0
- package/docs/classes/cryptonote.html +1137 -0
- package/docs/classes/ed25519.keypair.html +400 -0
- package/docs/classes/ed25519.keys.html +373 -0
- package/docs/classes/extranoncetag.extranoncedata.html +454 -0
- package/docs/classes/extranoncetag.extranoncepaymentid.html +453 -0
- package/docs/classes/extranoncetag.iextranonce.html +347 -0
- package/docs/classes/extratag.extramergedmining.html +494 -0
- package/docs/classes/extratag.extranonce.html +530 -0
- package/docs/classes/extratag.extrapadding.html +456 -0
- package/docs/classes/extratag.extrapublickey.html +460 -0
- package/docs/classes/extratag.iextratag.html +355 -0
- package/docs/classes/levinpacket.html +674 -0
- package/docs/classes/levinpayloads.handshake.html +731 -0
- package/docs/classes/levinpayloads.ilevinpayload.html +318 -0
- package/docs/classes/levinpayloads.liteblock.html +494 -0
- package/docs/classes/levinpayloads.missingtransactions.html +494 -0
- package/docs/classes/levinpayloads.newblock.html +540 -0
- package/docs/classes/levinpayloads.newtransactions.html +402 -0
- package/docs/classes/levinpayloads.peerentry.html +610 -0
- package/docs/classes/levinpayloads.ping.html +450 -0
- package/docs/classes/levinpayloads.rawblock.html +344 -0
- package/docs/classes/levinpayloads.requestchain.html +402 -0
- package/docs/classes/levinpayloads.requestgetobjects.html +448 -0
- package/docs/classes/levinpayloads.requesttxpool.html +402 -0
- package/docs/classes/levinpayloads.responsechain.html +494 -0
- package/docs/classes/levinpayloads.responsegetobjects.html +540 -0
- package/docs/classes/levinpayloads.timedsync.html +540 -0
- package/docs/classes/multisig.html +930 -0
- package/docs/classes/multisigmessage.html +694 -0
- package/docs/classes/parentblock.html +347 -0
- package/docs/classes/transaction.html +925 -0
- package/docs/classes/transactioninputs.coinbaseinput.html +390 -0
- package/docs/classes/transactioninputs.itransactioninput.html +321 -0
- package/docs/classes/transactioninputs.keyinput.html +459 -0
- package/docs/classes/transactionoutputs.itransactionoutput.html +317 -0
- package/docs/classes/transactionoutputs.keyoutput.html +422 -0
- package/docs/enums/extranoncetag.noncetagtype.html +246 -0
- package/docs/enums/extratag.extratagtype.html +280 -0
- package/docs/enums/levinprotocol.commandtype.html +391 -0
- package/docs/enums/transactioninputs.inputtype.html +246 -0
- package/docs/enums/transactionoutputs.outputtype.html +229 -0
- package/docs/globals.html +238 -0
- package/docs/index.html +271 -0
- package/docs/interfaces/interfaces.config.html +590 -0
- package/docs/interfaces/interfaces.daemonblocktemplateresponse.html +323 -0
- package/docs/interfaces/interfaces.generatedinput.html +304 -0
- package/docs/interfaces/interfaces.generatedoutput.html +285 -0
- package/docs/interfaces/interfaces.inputkeys.html +304 -0
- package/docs/interfaces/interfaces.ipreparedtransaction.html +268 -0
- package/docs/interfaces/interfaces.output.html +399 -0
- package/docs/interfaces/interfaces.preparedringsignature.html +377 -0
- package/docs/interfaces/interfaces.preparedtransaction.html +329 -0
- package/docs/interfaces/interfaces.randomoutput.html +285 -0
- package/docs/interfaces/interfaces.transactionrecipient.html +285 -0
- package/docs/interfaces/multisiginterfaces.partialkeyimage.html +277 -0
- package/docs/interfaces/multisiginterfaces.partialsigningkey.html +277 -0
- package/docs/modules/ed25519.html +195 -0
- package/docs/modules/extranoncetag.html +208 -0
- package/docs/modules/extratag.html +216 -0
- package/docs/modules/interfaces.html +231 -0
- package/docs/modules/levinpayloads.html +247 -0
- package/docs/modules/levinprotocol.html +191 -0
- package/docs/modules/multisiginterfaces.html +195 -0
- package/docs/modules/transactioninputs.html +208 -0
- package/docs/modules/transactionoutputs.html +204 -0
- package/index.d.ts +417 -0
- package/index.js +1508 -0
- package/lib/base58.js +220 -0
- package/lib/biginteger.js +1591 -0
- package/lib/blocktemplate.js +408 -0
- package/lib/crypto.js +19698 -0
- package/lib/mnemonic.js +1204 -0
- package/lib/nacl-fast-cn.js +608 -0
- package/lib/ringsigs.js +24262 -0
- package/lib/sha3.js +477 -0
- package/package.json +58 -0
- package/src/Address.ts +433 -0
- package/src/AddressPrefix.ts +117 -0
- package/src/Block.ts +556 -0
- package/src/BlockTemplate.ts +289 -0
- package/src/Common.ts +105 -0
- package/src/Config.ts +66 -0
- package/src/CryptoNote.ts +1072 -0
- package/src/LevinPacket.ts +366 -0
- package/src/Multisig.ts +600 -0
- package/src/MultisigMessage.ts +374 -0
- package/src/ParentBlock.ts +39 -0
- package/src/Transaction.ts +628 -0
- package/src/Types/ED25519.ts +187 -0
- package/src/Types/IExtraNonce.ts +225 -0
- package/src/Types/IExtraTag.ts +507 -0
- package/src/Types/ITransaction.ts +230 -0
- package/src/Types/ITransactionInput.ts +190 -0
- package/src/Types/ITransactionOutput.ts +108 -0
- package/src/Types/LevinPayloads.ts +1576 -0
- package/src/Types/MultisigInterfaces.ts +65 -0
- package/src/Types/PortableStorage.ts +289 -0
- package/src/Types.ts +36 -0
- package/src/index.ts +36 -0
- package/test/template.json +6 -0
- package/test/test.js +1457 -0
- package/tests/blocktemplate.json +6 -0
- package/tests/tests.js +215 -0
- package/tsconfig.json +15 -0
- package/tslint.json +36 -0
- package/typedoc.json +10 -0
- package/webpack.config.js +15 -0
package/lib/base58.js
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
// Copyright (c) 2014-2018, MyMonero.com
|
|
2
|
+
// Copyright (c) 2018, The TurtleCoin Developers
|
|
3
|
+
//
|
|
4
|
+
// Please see the included LICENSE file for more information.
|
|
5
|
+
|
|
6
|
+
const BigInteger = require('./biginteger.js')
|
|
7
|
+
|
|
8
|
+
var Base58 = (function () {
|
|
9
|
+
var b58 = {}
|
|
10
|
+
|
|
11
|
+
var alphabetStr = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
|
|
12
|
+
var alphabet = []
|
|
13
|
+
for (var i = 0; i < alphabetStr.length; i++) {
|
|
14
|
+
alphabet.push(alphabetStr.charCodeAt(i))
|
|
15
|
+
}
|
|
16
|
+
var encodedBlockSizes = [0, 2, 3, 5, 6, 7, 9, 10, 11]
|
|
17
|
+
|
|
18
|
+
var alphabetSize = alphabet.length
|
|
19
|
+
var fullBlockSize = 8
|
|
20
|
+
var fullEncodedBlockSize = 11
|
|
21
|
+
|
|
22
|
+
var UINT64_MAX = new BigInteger(2).pow(64)
|
|
23
|
+
|
|
24
|
+
function hextobin (hex) {
|
|
25
|
+
if (hex.length % 2 !== 0) throw new Error('Hex string has invalid length!')
|
|
26
|
+
var res = new Uint8Array(hex.length / 2)
|
|
27
|
+
for (var i = 0; i < hex.length / 2; ++i) {
|
|
28
|
+
res[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16)
|
|
29
|
+
}
|
|
30
|
+
return res
|
|
31
|
+
}
|
|
32
|
+
b58.hextobin = hextobin
|
|
33
|
+
|
|
34
|
+
function bintohex (bin) {
|
|
35
|
+
var out = []
|
|
36
|
+
for (var i = 0; i < bin.length; ++i) {
|
|
37
|
+
out.push(('0' + bin[i].toString(16)).slice(-2))
|
|
38
|
+
}
|
|
39
|
+
return out.join('')
|
|
40
|
+
}
|
|
41
|
+
b58.bintohex = bintohex
|
|
42
|
+
|
|
43
|
+
function strtobin (str) {
|
|
44
|
+
var res = new Uint8Array(str.length)
|
|
45
|
+
for (var i = 0; i < str.length; i++) {
|
|
46
|
+
res[i] = str.charCodeAt(i)
|
|
47
|
+
}
|
|
48
|
+
return res
|
|
49
|
+
}
|
|
50
|
+
b58.strtobin = strtobin
|
|
51
|
+
|
|
52
|
+
function hextostr (hex) {
|
|
53
|
+
var h2b = hextobin(hex)
|
|
54
|
+
var res = ''
|
|
55
|
+
for (var i = 0; i < h2b.length; i++) {
|
|
56
|
+
res = res + String.fromCharCode(h2b[i])
|
|
57
|
+
}
|
|
58
|
+
return res
|
|
59
|
+
}
|
|
60
|
+
b58.hextostr = hextostr
|
|
61
|
+
|
|
62
|
+
function strtohex (str) {
|
|
63
|
+
return bintohex(strtobin(str))
|
|
64
|
+
}
|
|
65
|
+
b58.strtohex = strtohex
|
|
66
|
+
|
|
67
|
+
function bintostr (bin) {
|
|
68
|
+
var out = []
|
|
69
|
+
for (var i = 0; i < bin.length; i++) {
|
|
70
|
+
out.push(String.fromCharCode(bin[i]))
|
|
71
|
+
}
|
|
72
|
+
return out.join('')
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function uint8BeTo64 (data) {
|
|
76
|
+
if (data.length < 1 || data.length > 8) {
|
|
77
|
+
throw new Error('Invalid input length')
|
|
78
|
+
}
|
|
79
|
+
var res = BigInteger.ZERO
|
|
80
|
+
var twopow8 = new BigInteger(2).pow(8)
|
|
81
|
+
var i = 0
|
|
82
|
+
switch (9 - data.length) {
|
|
83
|
+
case 1:
|
|
84
|
+
res = res.add(data[i++])
|
|
85
|
+
/* falls through */
|
|
86
|
+
case 2:
|
|
87
|
+
res = res.multiply(twopow8).add(data[i++])
|
|
88
|
+
/* falls through */
|
|
89
|
+
case 3:
|
|
90
|
+
res = res.multiply(twopow8).add(data[i++])
|
|
91
|
+
/* falls through */
|
|
92
|
+
case 4:
|
|
93
|
+
res = res.multiply(twopow8).add(data[i++])
|
|
94
|
+
/* falls through */
|
|
95
|
+
case 5:
|
|
96
|
+
res = res.multiply(twopow8).add(data[i++])
|
|
97
|
+
/* falls through */
|
|
98
|
+
case 6:
|
|
99
|
+
res = res.multiply(twopow8).add(data[i++])
|
|
100
|
+
/* falls through */
|
|
101
|
+
case 7:
|
|
102
|
+
res = res.multiply(twopow8).add(data[i++])
|
|
103
|
+
/* falls through */
|
|
104
|
+
case 8:
|
|
105
|
+
res = res.multiply(twopow8).add(data[i++])
|
|
106
|
+
break
|
|
107
|
+
default:
|
|
108
|
+
throw new Error('Impossible condition')
|
|
109
|
+
}
|
|
110
|
+
return res
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function uint64To8be (num, size) {
|
|
114
|
+
var res = new Uint8Array(size)
|
|
115
|
+
if (size < 1 || size > 8) {
|
|
116
|
+
throw new Error('Invalid input length')
|
|
117
|
+
}
|
|
118
|
+
var twopow8 = new BigInteger(2).pow(8)
|
|
119
|
+
for (var i = size - 1; i >= 0; i--) {
|
|
120
|
+
res[i] = num.remainder(twopow8).toJSValue()
|
|
121
|
+
num = num.divide(twopow8)
|
|
122
|
+
}
|
|
123
|
+
return res
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
b58.encode_block = function (data, buf, index) {
|
|
127
|
+
if (data.length < 1 || data.length > fullEncodedBlockSize) {
|
|
128
|
+
throw new Error('Invalid block length: ' + data.length)
|
|
129
|
+
}
|
|
130
|
+
var num = uint8BeTo64(data)
|
|
131
|
+
var i = encodedBlockSizes[data.length] - 1
|
|
132
|
+
while (num.compare(0) === 1) {
|
|
133
|
+
var div = num.divRem(alphabetSize)
|
|
134
|
+
var remainder = div[1]
|
|
135
|
+
num = div[0]
|
|
136
|
+
buf[index + i] = alphabet[remainder.toJSValue()]
|
|
137
|
+
i--
|
|
138
|
+
}
|
|
139
|
+
return buf
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
b58.encode = function (hex) {
|
|
143
|
+
var data = hextobin(hex)
|
|
144
|
+
if (data.length === 0) {
|
|
145
|
+
return ''
|
|
146
|
+
}
|
|
147
|
+
var fullBlockCount = Math.floor(data.length / fullBlockSize)
|
|
148
|
+
var lastBlockSize = data.length % fullBlockSize
|
|
149
|
+
var resSize = fullBlockCount * fullEncodedBlockSize + encodedBlockSizes[lastBlockSize]
|
|
150
|
+
|
|
151
|
+
var res = new Uint8Array(resSize)
|
|
152
|
+
var i
|
|
153
|
+
for (i = 0; i < resSize; ++i) {
|
|
154
|
+
res[i] = alphabet[0]
|
|
155
|
+
}
|
|
156
|
+
for (i = 0; i < fullBlockCount; i++) {
|
|
157
|
+
res = b58.encode_block(data.subarray(i * fullBlockSize, i * fullBlockSize + fullBlockSize), res, i * fullEncodedBlockSize)
|
|
158
|
+
}
|
|
159
|
+
if (lastBlockSize > 0) {
|
|
160
|
+
res = b58.encode_block(data.subarray(fullBlockCount * fullBlockSize, fullBlockCount * fullBlockSize + lastBlockSize), res, fullBlockCount * fullEncodedBlockSize)
|
|
161
|
+
}
|
|
162
|
+
return bintostr(res)
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
b58.decode_block = function (data, buf, index) {
|
|
166
|
+
if (data.length < 1 || data.length > fullEncodedBlockSize) {
|
|
167
|
+
throw new Error('Invalid block length: ' + data.length)
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
var resSize = encodedBlockSizes.indexOf(data.length)
|
|
171
|
+
if (resSize <= 0) {
|
|
172
|
+
throw new Error('Invalid block size')
|
|
173
|
+
}
|
|
174
|
+
var resNum = new BigInteger(0)
|
|
175
|
+
var order = new BigInteger(1)
|
|
176
|
+
for (var i = data.length - 1; i >= 0; i--) {
|
|
177
|
+
var digit = alphabet.indexOf(data[i])
|
|
178
|
+
if (digit < 0) {
|
|
179
|
+
throw new Error('Invalid symbol')
|
|
180
|
+
}
|
|
181
|
+
var product = order.multiply(digit).add(resNum)
|
|
182
|
+
if (product.compare(UINT64_MAX) === 1) {
|
|
183
|
+
throw new Error('Overflow')
|
|
184
|
+
}
|
|
185
|
+
resNum = product
|
|
186
|
+
order = order.multiply(alphabetSize)
|
|
187
|
+
}
|
|
188
|
+
if (resSize < fullBlockSize && (new BigInteger(2).pow(8 * resSize).compare(resNum) <= 0)) {
|
|
189
|
+
throw new Error('Overflow 2')
|
|
190
|
+
}
|
|
191
|
+
buf.set(uint64To8be(resNum, resSize), index)
|
|
192
|
+
return buf
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
b58.decode = function (enc) {
|
|
196
|
+
enc = strtobin(enc)
|
|
197
|
+
if (enc.length === 0) {
|
|
198
|
+
return ''
|
|
199
|
+
}
|
|
200
|
+
var fullBlockCount = Math.floor(enc.length / fullEncodedBlockSize)
|
|
201
|
+
var lastBlockSize = enc.length % fullEncodedBlockSize
|
|
202
|
+
var lastBlockDecodedSize = encodedBlockSizes.indexOf(lastBlockSize)
|
|
203
|
+
if (lastBlockDecodedSize < 0) {
|
|
204
|
+
throw new Error('Invalid encoded length')
|
|
205
|
+
}
|
|
206
|
+
var dataSize = fullBlockCount * fullBlockSize + lastBlockDecodedSize
|
|
207
|
+
var data = new Uint8Array(dataSize)
|
|
208
|
+
for (var i = 0; i < fullBlockCount; i++) {
|
|
209
|
+
data = b58.decode_block(enc.subarray(i * fullEncodedBlockSize, i * fullEncodedBlockSize + fullEncodedBlockSize), data, i * fullBlockSize)
|
|
210
|
+
}
|
|
211
|
+
if (lastBlockSize > 0) {
|
|
212
|
+
data = b58.decode_block(enc.subarray(fullBlockCount * fullEncodedBlockSize, fullBlockCount * fullEncodedBlockSize + lastBlockSize), data, fullBlockCount * fullBlockSize)
|
|
213
|
+
}
|
|
214
|
+
return bintohex(data)
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
return b58
|
|
218
|
+
})()
|
|
219
|
+
|
|
220
|
+
module.exports = Base58
|