@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.
Files changed (132) hide show
  1. package/.github/workflows/ci.yml +27 -0
  2. package/.idea/codeStyles/codeStyleConfig.xml +5 -0
  3. package/.idea/inspectionProfiles/Project_Default.xml +7 -0
  4. package/.idea/misc.xml +6 -0
  5. package/.idea/modules.xml +8 -0
  6. package/.idea/turtlecoin-utils.iml +12 -0
  7. package/.idea/vcs.xml +6 -0
  8. package/.travis.yml +11 -0
  9. package/CONTRIBUTING.md +3 -0
  10. package/LICENSE +674 -0
  11. package/README.md +203 -0
  12. package/config.json +7 -0
  13. package/docs/.nojekyll +0 -0
  14. package/docs/CNAME +1 -0
  15. package/docs/assets/css/main.css +2321 -0
  16. package/docs/assets/images/icons.png +0 -0
  17. package/docs/assets/images/icons@2x.png +0 -0
  18. package/docs/assets/images/widgets.png +0 -0
  19. package/docs/assets/images/widgets@2x.png +0 -0
  20. package/docs/assets/js/main.js +1 -0
  21. package/docs/assets/js/search.js +3 -0
  22. package/docs/classes/address.html +964 -0
  23. package/docs/classes/addressprefix.html +431 -0
  24. package/docs/classes/block.html +965 -0
  25. package/docs/classes/blocktemplate.html +695 -0
  26. package/docs/classes/cryptonote.html +1137 -0
  27. package/docs/classes/ed25519.keypair.html +400 -0
  28. package/docs/classes/ed25519.keys.html +373 -0
  29. package/docs/classes/extranoncetag.extranoncedata.html +454 -0
  30. package/docs/classes/extranoncetag.extranoncepaymentid.html +453 -0
  31. package/docs/classes/extranoncetag.iextranonce.html +347 -0
  32. package/docs/classes/extratag.extramergedmining.html +494 -0
  33. package/docs/classes/extratag.extranonce.html +530 -0
  34. package/docs/classes/extratag.extrapadding.html +456 -0
  35. package/docs/classes/extratag.extrapublickey.html +460 -0
  36. package/docs/classes/extratag.iextratag.html +355 -0
  37. package/docs/classes/levinpacket.html +674 -0
  38. package/docs/classes/levinpayloads.handshake.html +731 -0
  39. package/docs/classes/levinpayloads.ilevinpayload.html +318 -0
  40. package/docs/classes/levinpayloads.liteblock.html +494 -0
  41. package/docs/classes/levinpayloads.missingtransactions.html +494 -0
  42. package/docs/classes/levinpayloads.newblock.html +540 -0
  43. package/docs/classes/levinpayloads.newtransactions.html +402 -0
  44. package/docs/classes/levinpayloads.peerentry.html +610 -0
  45. package/docs/classes/levinpayloads.ping.html +450 -0
  46. package/docs/classes/levinpayloads.rawblock.html +344 -0
  47. package/docs/classes/levinpayloads.requestchain.html +402 -0
  48. package/docs/classes/levinpayloads.requestgetobjects.html +448 -0
  49. package/docs/classes/levinpayloads.requesttxpool.html +402 -0
  50. package/docs/classes/levinpayloads.responsechain.html +494 -0
  51. package/docs/classes/levinpayloads.responsegetobjects.html +540 -0
  52. package/docs/classes/levinpayloads.timedsync.html +540 -0
  53. package/docs/classes/multisig.html +930 -0
  54. package/docs/classes/multisigmessage.html +694 -0
  55. package/docs/classes/parentblock.html +347 -0
  56. package/docs/classes/transaction.html +925 -0
  57. package/docs/classes/transactioninputs.coinbaseinput.html +390 -0
  58. package/docs/classes/transactioninputs.itransactioninput.html +321 -0
  59. package/docs/classes/transactioninputs.keyinput.html +459 -0
  60. package/docs/classes/transactionoutputs.itransactionoutput.html +317 -0
  61. package/docs/classes/transactionoutputs.keyoutput.html +422 -0
  62. package/docs/enums/extranoncetag.noncetagtype.html +246 -0
  63. package/docs/enums/extratag.extratagtype.html +280 -0
  64. package/docs/enums/levinprotocol.commandtype.html +391 -0
  65. package/docs/enums/transactioninputs.inputtype.html +246 -0
  66. package/docs/enums/transactionoutputs.outputtype.html +229 -0
  67. package/docs/globals.html +238 -0
  68. package/docs/index.html +271 -0
  69. package/docs/interfaces/interfaces.config.html +590 -0
  70. package/docs/interfaces/interfaces.daemonblocktemplateresponse.html +323 -0
  71. package/docs/interfaces/interfaces.generatedinput.html +304 -0
  72. package/docs/interfaces/interfaces.generatedoutput.html +285 -0
  73. package/docs/interfaces/interfaces.inputkeys.html +304 -0
  74. package/docs/interfaces/interfaces.ipreparedtransaction.html +268 -0
  75. package/docs/interfaces/interfaces.output.html +399 -0
  76. package/docs/interfaces/interfaces.preparedringsignature.html +377 -0
  77. package/docs/interfaces/interfaces.preparedtransaction.html +329 -0
  78. package/docs/interfaces/interfaces.randomoutput.html +285 -0
  79. package/docs/interfaces/interfaces.transactionrecipient.html +285 -0
  80. package/docs/interfaces/multisiginterfaces.partialkeyimage.html +277 -0
  81. package/docs/interfaces/multisiginterfaces.partialsigningkey.html +277 -0
  82. package/docs/modules/ed25519.html +195 -0
  83. package/docs/modules/extranoncetag.html +208 -0
  84. package/docs/modules/extratag.html +216 -0
  85. package/docs/modules/interfaces.html +231 -0
  86. package/docs/modules/levinpayloads.html +247 -0
  87. package/docs/modules/levinprotocol.html +191 -0
  88. package/docs/modules/multisiginterfaces.html +195 -0
  89. package/docs/modules/transactioninputs.html +208 -0
  90. package/docs/modules/transactionoutputs.html +204 -0
  91. package/index.d.ts +417 -0
  92. package/index.js +1508 -0
  93. package/lib/base58.js +220 -0
  94. package/lib/biginteger.js +1591 -0
  95. package/lib/blocktemplate.js +408 -0
  96. package/lib/crypto.js +19698 -0
  97. package/lib/mnemonic.js +1204 -0
  98. package/lib/nacl-fast-cn.js +608 -0
  99. package/lib/ringsigs.js +24262 -0
  100. package/lib/sha3.js +477 -0
  101. package/package.json +58 -0
  102. package/src/Address.ts +433 -0
  103. package/src/AddressPrefix.ts +117 -0
  104. package/src/Block.ts +556 -0
  105. package/src/BlockTemplate.ts +289 -0
  106. package/src/Common.ts +105 -0
  107. package/src/Config.ts +66 -0
  108. package/src/CryptoNote.ts +1072 -0
  109. package/src/LevinPacket.ts +366 -0
  110. package/src/Multisig.ts +600 -0
  111. package/src/MultisigMessage.ts +374 -0
  112. package/src/ParentBlock.ts +39 -0
  113. package/src/Transaction.ts +628 -0
  114. package/src/Types/ED25519.ts +187 -0
  115. package/src/Types/IExtraNonce.ts +225 -0
  116. package/src/Types/IExtraTag.ts +507 -0
  117. package/src/Types/ITransaction.ts +230 -0
  118. package/src/Types/ITransactionInput.ts +190 -0
  119. package/src/Types/ITransactionOutput.ts +108 -0
  120. package/src/Types/LevinPayloads.ts +1576 -0
  121. package/src/Types/MultisigInterfaces.ts +65 -0
  122. package/src/Types/PortableStorage.ts +289 -0
  123. package/src/Types.ts +36 -0
  124. package/src/index.ts +36 -0
  125. package/test/template.json +6 -0
  126. package/test/test.js +1457 -0
  127. package/tests/blocktemplate.json +6 -0
  128. package/tests/tests.js +215 -0
  129. package/tsconfig.json +15 -0
  130. package/tslint.json +36 -0
  131. package/typedoc.json +10 -0
  132. 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