@tradelayerprotocol/tradelayer 1.9.1

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 (249) hide show
  1. package/.claude/settings.local.json +13 -0
  2. package/.claude/skills/tl-algo/SKILL.md +255 -0
  3. package/.gitattributes +2 -0
  4. package/.github/workflows/publish.yaml +26 -0
  5. package/4mm.js +163 -0
  6. package/LICENSE +21 -0
  7. package/NPMSwapRefactor.zip +0 -0
  8. package/README.md +217 -0
  9. package/address.sh +26 -0
  10. package/algoAPI.js +581 -0
  11. package/analyzepsbt.js +92 -0
  12. package/apiEx.js +99 -0
  13. package/bb_hyperscalper.js +290 -0
  14. package/bbo_demo.js +111 -0
  15. package/buyer.js +622 -0
  16. package/client.js +50 -0
  17. package/createTxTest.js +26 -0
  18. package/createWallet.js +75 -0
  19. package/daytrader.js +531 -0
  20. package/decodeTest.js +69 -0
  21. package/fundingManager.js +144 -0
  22. package/index.js +4 -0
  23. package/listener.js +27 -0
  24. package/litecoreTxBuilder.js +1128 -0
  25. package/mmEx.js +356 -0
  26. package/networks.js +51 -0
  27. package/orderbook.js +200 -0
  28. package/package.json +34 -0
  29. package/perTradeQueue.js +36 -0
  30. package/projectsTLNPMTLNPM/package-lock.json +162 -0
  31. package/projectsTLNPMTLNPM/package.json +5 -0
  32. package/quick.js +32 -0
  33. package/quickFut.js +37 -0
  34. package/quickSell.js +37 -0
  35. package/relayerClient.js +117 -0
  36. package/run4mm.js +80 -0
  37. package/run_bbo_tracker.js +241 -0
  38. package/seller.js +443 -0
  39. package/session.js +45 -0
  40. package/setup-lin-ltc.sh +139 -0
  41. package/setup-lin.sh +203 -0
  42. package/setup-win-ltc.bat +108 -0
  43. package/setup-win.bat +167 -0
  44. package/spam_screamer_futures.js +222 -0
  45. package/tradelayer.js/.gitattributes +2 -0
  46. package/tradelayer.js/README.md +2 -0
  47. package/tradelayer.js/oldTests/activationTest.js +6 -0
  48. package/tradelayer.js/oldTests/base58.test.js +23 -0
  49. package/tradelayer.js/oldTests/base64Decode.test.js +16 -0
  50. package/tradelayer.js/oldTests/blocksRefactor.js +140 -0
  51. package/tradelayer.js/oldTests/checkVestBalance.js +25 -0
  52. package/tradelayer.js/oldTests/consensusHashProto.js +151 -0
  53. package/tradelayer.js/oldTests/contractOrderbook.js +243 -0
  54. package/tradelayer.js/oldTests/createPayload.js +0 -0
  55. package/tradelayer.js/oldTests/createTestnetAddr.js +43 -0
  56. package/tradelayer.js/oldTests/decode.js +205 -0
  57. package/tradelayer.js/oldTests/decodeTest.js +50 -0
  58. package/tradelayer.js/oldTests/displayTallyMap.js +19 -0
  59. package/tradelayer.js/oldTests/encodeDecode.js +340 -0
  60. package/tradelayer.js/oldTests/expressTest.js +29 -0
  61. package/tradelayer.js/oldTests/extractBlocksVanilla.js +214 -0
  62. package/tradelayer.js/oldTests/extractBlocksVanillaa.js +179 -0
  63. package/tradelayer.js/oldTests/extractPubkeyTest.js +60 -0
  64. package/tradelayer.js/oldTests/fillInputCacheProto.js +111 -0
  65. package/tradelayer.js/oldTests/getRawTxTest.js +22 -0
  66. package/tradelayer.js/oldTests/indexTest.js +26 -0
  67. package/tradelayer.js/oldTests/initTokensTest.js +32 -0
  68. package/tradelayer.js/oldTests/interfaceChild.js +129 -0
  69. package/tradelayer.js/oldTests/listenerChild.js +112 -0
  70. package/tradelayer.js/oldTests/opdecode.js +26 -0
  71. package/tradelayer.js/oldTests/options.js +79 -0
  72. package/tradelayer.js/oldTests/optxtest.js +116 -0
  73. package/tradelayer.js/oldTests/optxtest1.js +64 -0
  74. package/tradelayer.js/oldTests/oracle.test.js +32 -0
  75. package/tradelayer.js/oldTests/orderbook.test.js +36 -0
  76. package/tradelayer.js/oldTests/parsing.js +93 -0
  77. package/tradelayer.js/oldTests/payload.js +13 -0
  78. package/tradelayer.js/oldTests/persistenceUnitTest.js +23 -0
  79. package/tradelayer.js/oldTests/property.test.js +53 -0
  80. package/tradelayer.js/oldTests/propertyLevel.js +75 -0
  81. package/tradelayer.js/oldTests/propertyTest.js +32 -0
  82. package/tradelayer.js/oldTests/queryAddressTest.js +17 -0
  83. package/tradelayer.js/oldTests/salter.js +14 -0
  84. package/tradelayer.js/oldTests/tally.js +81 -0
  85. package/tradelayer.js/oldTests/tally.test.js +48 -0
  86. package/tradelayer.js/oldTests/tally2.js +124 -0
  87. package/tradelayer.js/oldTests/tally3.js +142 -0
  88. package/tradelayer.js/oldTests/tallyDiag.js +38 -0
  89. package/tradelayer.js/oldTests/testGetRaw.js +40 -0
  90. package/tradelayer.js/oldTests/testHexConvert.js +47 -0
  91. package/tradelayer.js/oldTests/testNewEncoding.js +96 -0
  92. package/tradelayer.js/oldTests/testNewEncoding2.js +113 -0
  93. package/tradelayer.js/oldTests/testNewEncoding3 +112 -0
  94. package/tradelayer.js/oldTests/testNewEncoding3.js +168 -0
  95. package/tradelayer.js/oldTests/testOPReturn.js +102 -0
  96. package/tradelayer.js/oldTests/testPayload.js +23 -0
  97. package/tradelayer.js/oldTests/testRaw.js +50 -0
  98. package/tradelayer.js/oldTests/testSendTooMuch.js +20 -0
  99. package/tradelayer.js/oldTests/testTxBuild +28 -0
  100. package/tradelayer.js/oldTests/testTxBuild.js +42 -0
  101. package/tradelayer.js/oldTests/tokenOrderbook.js +243 -0
  102. package/tradelayer.js/oldTests/txUtilsA.js +515 -0
  103. package/tradelayer.js/oldTests/validityUnitTest.js +53 -0
  104. package/tradelayer.js/oldTests/vaults.js +72 -0
  105. package/tradelayer.js/oldTests/volumeIndex.js +117 -0
  106. package/tradelayer.js/oldTests/volumeIndex2.js +88 -0
  107. package/tradelayer.js/output_base64.txt +1 -0
  108. package/tradelayer.js/package-lock.json +9967 -0
  109. package/tradelayer.js/package.json +61 -0
  110. package/tradelayer.js/server/index.js +88 -0
  111. package/tradelayer.js/server/litecoind.exe +0 -0
  112. package/tradelayer.js/src/activation.js +303 -0
  113. package/tradelayer.js/src/adjuster.js +77 -0
  114. package/tradelayer.js/src/amm.js +400 -0
  115. package/tradelayer.js/src/base256.js +55 -0
  116. package/tradelayer.js/src/base94.js +79 -0
  117. package/tradelayer.js/src/channels.js +1163 -0
  118. package/tradelayer.js/src/clearing.js +3109 -0
  119. package/tradelayer.js/src/clearlist.js +364 -0
  120. package/tradelayer.js/src/client.js +295 -0
  121. package/tradelayer.js/src/consensus.js +613 -0
  122. package/tradelayer.js/src/contractRegistry.js +964 -0
  123. package/tradelayer.js/src/db.js +89 -0
  124. package/tradelayer.js/src/init.js +24 -0
  125. package/tradelayer.js/src/insurance.js +347 -0
  126. package/tradelayer.js/src/interface.js +218 -0
  127. package/tradelayer.js/src/interfaceExpress.js +178 -0
  128. package/tradelayer.js/src/iou.js +509 -0
  129. package/tradelayer.js/src/listener.js +226 -0
  130. package/tradelayer.js/src/logic.js +1702 -0
  131. package/tradelayer.js/src/main.js +927 -0
  132. package/tradelayer.js/src/marginMap.js +2165 -0
  133. package/tradelayer.js/src/options.js +126 -0
  134. package/tradelayer.js/src/oracle.js +394 -0
  135. package/tradelayer.js/src/orderbook.js +4123 -0
  136. package/tradelayer.js/src/persistence.js +554 -0
  137. package/tradelayer.js/src/property.js +411 -0
  138. package/tradelayer.js/src/reOrg.js +41 -0
  139. package/tradelayer.js/src/scaling.js +145 -0
  140. package/tradelayer.js/src/tally.js +1275 -0
  141. package/tradelayer.js/src/tradeHistoryManager.js +552 -0
  142. package/tradelayer.js/src/txDecoder.js +584 -0
  143. package/tradelayer.js/src/txEncoder.js +610 -0
  144. package/tradelayer.js/src/txIndex.js +502 -0
  145. package/tradelayer.js/src/txUtils.js +1392 -0
  146. package/tradelayer.js/src/types.js +429 -0
  147. package/tradelayer.js/src/validity.js +3077 -0
  148. package/tradelayer.js/src/vaults.js +430 -0
  149. package/tradelayer.js/src/vesting.js +491 -0
  150. package/tradelayer.js/src/volumeIndex.js +618 -0
  151. package/tradelayer.js/src/walletInterface.js +220 -0
  152. package/tradelayer.js/src/walletListener.js +665 -0
  153. package/tradelayer.js/tests/256decode.js +82 -0
  154. package/tradelayer.js/tests/UTXOracle.js +205 -0
  155. package/tradelayer.js/tests/base94test.js +23 -0
  156. package/tradelayer.js/tests/cancelTxTest.js +62 -0
  157. package/tradelayer.js/tests/contractInterfaceTest.js +48 -0
  158. package/tradelayer.js/tests/decimalTest.js +65 -0
  159. package/tradelayer.js/tests/decoderTest.js +100 -0
  160. package/tradelayer.js/tests/deltaCount.js +47 -0
  161. package/tradelayer.js/tests/deltaCount2.js +60 -0
  162. package/tradelayer.js/tests/interfaceTest.js +37 -0
  163. package/tradelayer.js/tests/mainTest.js +53 -0
  164. package/tradelayer.js/tests/makeActivationTest.js +24 -0
  165. package/tradelayer.js/tests/maxHeightTest.js +49 -0
  166. package/tradelayer.js/tests/reverseHash.js +72 -0
  167. package/tradelayer.js/tests/sensitiveConsoleOutput.txt +267 -0
  168. package/tradelayer.js/tests/tallyTest.js +40 -0
  169. package/tradelayer.js/tests/testBuybacks.js +46 -0
  170. package/tradelayer.js/tests/testCodeHash.js +49 -0
  171. package/tradelayer.js/tests/testConsensusHash.js +91 -0
  172. package/tradelayer.js/tests/testDecode.js +30 -0
  173. package/tradelayer.js/tests/testEncodingLengths.js +129 -0
  174. package/tradelayer.js/tests/testGetTx +32 -0
  175. package/tradelayer.js/tests/testGetTx.js +32 -0
  176. package/tradelayer.js/tests/testHexHash.js +32 -0
  177. package/tradelayer.js/tests/testIndexHash.js +35 -0
  178. package/tradelayer.js/tests/testInitContracts.js +38 -0
  179. package/tradelayer.js/tests/testMaxConsensus.js +12 -0
  180. package/tradelayer.js/tests/testMaxSynth.js +44 -0
  181. package/tradelayer.js/tests/testMint.js +21 -0
  182. package/tradelayer.js/tests/testNetwork.js +33 -0
  183. package/tradelayer.js/tests/testOrderbookLoad.js +62 -0
  184. package/tradelayer.js/tests/testRebates.js +32 -0
  185. package/tradelayer.js/tests/testRedeem.js +22 -0
  186. package/tradelayer.js/tests/testTokenTrade.js +39 -0
  187. package/tradelayer.js/tests/testTxBuild.js +42 -0
  188. package/tradelayer.js/tests/testUTXOTrade.js +27 -0
  189. package/tradelayer.js/tests/tokenTradeHistory.js +27 -0
  190. package/tradelayer.js/tests/tradeFutures.js +40 -0
  191. package/tradelayer.js/tests/tradeHistoryExample.js +35 -0
  192. package/tradelayer.js/tests/tradeHistoryLoad.js +15 -0
  193. package/tradelayer.js/tests/txScanTest.js +134 -0
  194. package/tradelayer.js/tests/validateTest.js +136 -0
  195. package/tradelayer.js/tests/vestingTest.js +37 -0
  196. package/tradelayer.js/utils/activateMainnet.js +59 -0
  197. package/tradelayer.js/utils/activateMainnetDoge.js +63 -0
  198. package/tradelayer.js/utils/autocompactdb.js +23 -0
  199. package/tradelayer.js/utils/base64toHex.js +32 -0
  200. package/tradelayer.js/utils/broadcastDoge.js +38 -0
  201. package/tradelayer.js/utils/calcRedeem.js +19 -0
  202. package/tradelayer.js/utils/checkNetwork.js +27 -0
  203. package/tradelayer.js/utils/createAddress.js +48 -0
  204. package/tradelayer.js/utils/createAttestation.js +133 -0
  205. package/tradelayer.js/utils/createContract.js +118 -0
  206. package/tradelayer.js/utils/createOracle.js +94 -0
  207. package/tradelayer.js/utils/createwallet.js +20 -0
  208. package/tradelayer.js/utils/crossFuturesTrades.js +57 -0
  209. package/tradelayer.js/utils/crossTokenTrades.js +62 -0
  210. package/tradelayer.js/utils/dumpPriv.js +29 -0
  211. package/tradelayer.js/utils/generateChannel.js +34 -0
  212. package/tradelayer.js/utils/getInfo.js +21 -0
  213. package/tradelayer.js/utils/hardWipe.js +20 -0
  214. package/tradelayer.js/utils/hexTo64.js +16 -0
  215. package/tradelayer.js/utils/importAddress.js +28 -0
  216. package/tradelayer.js/utils/importpriv.js +20 -0
  217. package/tradelayer.js/utils/issueOracleContract.js +67 -0
  218. package/tradelayer.js/utils/issueTokens.js +41 -0
  219. package/tradelayer.js/utils/listunspent.js +66 -0
  220. package/tradelayer.js/utils/litecoinClient.js +30 -0
  221. package/tradelayer.js/utils/loadwallet.js +20 -0
  222. package/tradelayer.js/utils/publishOracle.js +113 -0
  223. package/tradelayer.js/utils/sendActivation.js +21 -0
  224. package/tradelayer.js/utils/sendChannelContractTrade.js +34 -0
  225. package/tradelayer.js/utils/sendChannelTokenTrade.js +34 -0
  226. package/tradelayer.js/utils/sendCommit.js +24 -0
  227. package/tradelayer.js/utils/sendDoge.js +62 -0
  228. package/tradelayer.js/utils/sendDogeMain.js +67 -0
  229. package/tradelayer.js/utils/sendDogeTx.js +46 -0
  230. package/tradelayer.js/utils/sendLTC.js +63 -0
  231. package/tradelayer.js/utils/sendMainnet.js +62 -0
  232. package/tradelayer.js/utils/sendTransfer.js +19 -0
  233. package/tradelayer.js/utils/sendVestTest.js +88 -0
  234. package/tradelayer.js/utils/sendWithdrawal.js +26 -0
  235. package/tradelayer.js/utils/simpleStart.js +8 -0
  236. package/tradelayer.js/utils/startStop.js +27 -0
  237. package/tradelayer.js/utils/structuredTrades.js +136 -0
  238. package/tradelayer.js/utils/verifySignature.js +90 -0
  239. package/tradelayer.js/utils/verifyWitnessAndScriptPubkey.js +41 -0
  240. package/tradelayer.js/utils/walletCache.js +172 -0
  241. package/tradelayer.js/utils/walletContractInterface.js +48 -0
  242. package/tradelayer.js/utils/walletFetchTxs.js +66 -0
  243. package/tradelayer.js/utils/walletUtils.js +97 -0
  244. package/tradelayer.js/utils/wipeDB.js +55 -0
  245. package/tradelayer.js/utils/wipeDBNotTx.js +50 -0
  246. package/txEncoder.js +529 -0
  247. package/utility.js +28 -0
  248. package/verifymessage.js +38 -0
  249. package/ws-transport.js +311 -0
@@ -0,0 +1,59 @@
1
+ const async = require('async');
2
+ const util = require('util');
3
+ const litecore = require('bitcore-lib-ltc');
4
+ const Encode = require('../src/txEncoder.js');
5
+
6
+ // Assuming standard fee and other constants are defined
7
+ const STANDARD_FEE = 3000; // Standard fee in satoshis
8
+ const DUST_THRESHOLD = 54600;
9
+
10
+ async function sendLitecoin(senderAddress, recipientAddress, amountToSend) {
11
+ let send = (amountToSend*100000000)-STANDARD_FEE
12
+ try {
13
+ // Fetch the private key for the sender address
14
+ // Fetch UTXOs for the sender address
15
+
16
+ //console.log('bleh '+litecore.Script.buildScriptHashOut('d9feb2d55d2c022d4fc463ab54dcbdd75f7b0ebc'))
17
+ const utxos = [{
18
+ txId: 'a750adc0f1801f4848e529d3d0c8478c20b384d0688486b318c9dc3ef11be60b',
19
+ outputIndex: 0,
20
+ address: senderAddress,
21
+ script: "a914d9feb2d55d2c022d4fc463ab54dcbdd75f7b0ebc87",
22
+ satoshis: 0.00044 * 1e8, // Amount in satoshis
23
+ }]
24
+ const params = {
25
+ txTypeToActivate: 9, // Activation types
26
+ codeHash: '11b89e7aa5bd3f2b42b25003a76efbc2c191c80ab06526f303f05443d2881fcf'
27
+ };
28
+ const opReturnData = Encode.encodeActivateTradeLayer(params);
29
+ console.log('payload '+opReturnData)
30
+ const opReturnScript = litecore.Script.buildDataOut(opReturnData);
31
+ // Create a new transaction
32
+ const tx = new litecore.Transaction()
33
+ .from(utxos)
34
+ .to(recipientAddress, send)
35
+ //.change(senderAddress)
36
+ .fee(STANDARD_FEE)
37
+ .addOutput(new litecore.Transaction.Output({
38
+ script: opReturnScript,
39
+ satoshis: 0,
40
+ }))
41
+ //.sign(privateKey);
42
+
43
+ // Serialize and broadcast the transaction
44
+ const serializedTx = tx.toString();
45
+ //const txid = await sendrawtransactionAsync(serializedTx);
46
+ console.log(`Transaction hex to sign: ${tx}`);
47
+ } catch (error) {
48
+ console.error('Error sending Litecoin:', error);
49
+ }
50
+ }
51
+
52
+ // Replace with actual values
53
+ const senderAddress = "MTmoypkhRQoJ172ZqxcsVumPZfJ8KCrQCB"; //tltc1qfffvwpftp8w3kv6gg6273ejtsfnu2dara5x4tr
54
+ const recipientAddress = "MTmoypkhRQoJ172ZqxcsVumPZfJ8KCrQCB"
55
+ //tltc1qp5z2la8sy69np798pc36up5zk2vg0fw2g7pml2"//tltc1qn3src8lgu50gxhndn5hnd6zrc9yv2364wu858m" //"tltc1qpgenrwmg9hxgv23mnvd2t7085prjkge2xw7myz"
56
+ const amountToSend = 0.00044; // Amount of LTC to send
57
+
58
+ // Execute the function to send Litecoin
59
+ sendLitecoin(senderAddress, recipientAddress, amountToSend);
@@ -0,0 +1,63 @@
1
+ const async = require('async');
2
+ const litecore = require('bitcore-lib-doge'); // Use Dogecoin version
3
+ const Encode = require('../src/txEncoder.js'); // Assuming TradeLayer encoding logic
4
+
5
+ // Constants
6
+ const STANDARD_FEE = 100000000; // Standard fee in satoshis (e.g., 1 DOGE)
7
+ const DUST_THRESHOLD = 100000000; // Dogecoin dust threshold (e.g., 1 DOGE)
8
+
9
+ async function sendDogecoin(senderAddress, recipientAddress, amountToSend) {
10
+ let send = Math.floor(amountToSend * 1e8) - STANDARD_FEE; // Convert to satoshis and subtract fee
11
+
12
+ try {
13
+ // Mock UTXO for demonstration (replace with real UTXO fetching logic)
14
+ const utxos = [{
15
+ txId: '502ce433a589184cc04c6ee8ac5260a34acc679ec071c6727c1ebbdcf51cc7a6',
16
+ outputIndex: 0,
17
+ address: senderAddress,
18
+ script: "76a914a7dcce4bf35b50dbe9da38e5dc6758b7ab78ae5a88ac",
19
+ satoshis: 5 * 1e8, // Amount in satoshis
20
+ }];
21
+
22
+ // Activation parameters for TradeLayer
23
+ const params = {
24
+ txTypeToActivate: 9, // Activation type
25
+ codeHash: '873af1d08d3603c8296afe6de040d228b76872fa0dc570f7b236dd4900b26f0d',
26
+ };
27
+
28
+ // Encode OP_RETURN data for TradeLayer activation
29
+ const opReturnData = Encode.encodeActivateTradeLayer(params);
30
+ console.log('Payload:', opReturnData);
31
+
32
+ // Create OP_RETURN script
33
+ const opReturnScript = litecore.Script.buildDataOut(opReturnData);
34
+
35
+ // Create a new Dogecoin transaction
36
+ const tx = new litecore.Transaction()
37
+ .from(utxos) // Add UTXOs as inputs
38
+ .to(recipientAddress, send) // Send to recipient
39
+ .fee(STANDARD_FEE) // Set the transaction fee
40
+ .addOutput(new litecore.Transaction.Output({
41
+ script: opReturnScript, // Add OP_RETURN data as output
42
+ satoshis: 0, // OP_RETURN outputs always have 0 value
43
+ }));
44
+
45
+ // Serialize the transaction
46
+ const serializedTx = tx.toString();
47
+ console.log(`Transaction hex to sign: ${serializedTx}`);
48
+
49
+ // Mock broadcasting (replace with actual broadcast logic)
50
+ // const txid = await sendrawtransactionAsync(serializedTx);
51
+ // console.log(`Transaction broadcasted with txid: ${txid}`);
52
+ } catch (error) {
53
+ console.error('Error sending Dogecoin:', error);
54
+ }
55
+ }
56
+
57
+ // Replace with actual values
58
+ const senderAddress = "DLSfu9qvEggkeXAgCAwBBw5BVLvMCtkewz"; // Replace with a valid Dogecoin address
59
+ const recipientAddress = "DLSfu9qvEggkeXAgCAwBBw5BVLvMCtkewz"; // Replace with recipient Dogecoin address
60
+ const amountToSend = 5; // Amount of DOGE to send
61
+
62
+ // Execute the function to send Dogecoin
63
+ sendDogecoin(senderAddress, recipientAddress, amountToSend);
@@ -0,0 +1,23 @@
1
+ const dbInstance = require('./path/to/your/dbInstance'); // Import your database instance
2
+ const COMPACT_INTERVAL_MS = 60000; // Set this to your desired compaction interval in milliseconds
3
+ const COMPACT_MODULO = 10; // Perform compaction every 10th interval
4
+
5
+ let intervalCount = 0;
6
+
7
+ setInterval(() => {
8
+ intervalCount++;
9
+ if (intervalCount % COMPACT_MODULO === 0) {
10
+ console.log('Compacting database...');
11
+ compactDatabase();
12
+ }
13
+ }, COMPACT_INTERVAL_MS);
14
+
15
+ function compactDatabase() {
16
+ // Assuming you have multiple databases to compact, loop through them
17
+ const databases = ['tallyMap', 'propertyList', 'anotherDatabase']; // List your databases here
18
+ databases.forEach(dbName => {
19
+ const db = dbInstance.getDatabase(dbName);
20
+ db.persistence.compactDatafile();
21
+ console.log(`Compacted ${dbName} database.`);
22
+ });
23
+ }
@@ -0,0 +1,32 @@
1
+ // Base64 to Hex Decoder
2
+ const base64ToHex = (base64String) => {
3
+ try {
4
+ // Decode base64 to a buffer
5
+ const buffer = Buffer.from(base64String, 'base64');
6
+ // Convert buffer to hex
7
+ const hexString = buffer.toString('hex');
8
+ return hexString;
9
+ } catch (error) {
10
+ console.error('Error decoding base64 to hex:', error);
11
+ return null;
12
+ }
13
+ };
14
+
15
+ // Example usage
16
+ const readline = require('readline');
17
+
18
+ const rl = readline.createInterface({
19
+ input: process.stdin,
20
+ output: process.stdout
21
+ });
22
+
23
+ rl.question('Enter the Base64 string: ', (base64String) => {
24
+ const hexResult = base64ToHex(base64String.trim());
25
+ if (hexResult) {
26
+ console.log('Hexadecimal Output:');
27
+ console.log(hexResult);
28
+ } else {
29
+ console.log('Failed to convert the input to hex.');
30
+ }
31
+ rl.close();
32
+ });
@@ -0,0 +1,38 @@
1
+ const axios = require('axios');
2
+
3
+ /**
4
+ * Broadcasts a signed Dogecoin transaction to the Dogecoin network.
5
+ *
6
+ * @param {string} txHex - The raw transaction hex string (signed).
7
+ * @param {string} apiUrl - The API endpoint for broadcasting the transaction.
8
+ */
9
+ async function broadcastDogecoinTransaction(txHex, apiUrl = 'https://sochain.com/api/v2/send_tx/DOGE') {
10
+ try {
11
+ // Prepare the payload
12
+ const payload = {
13
+ tx_hex: txHex
14
+ };
15
+
16
+ // Make the POST request to the API
17
+ const response = await axios.post(apiUrl, payload, {
18
+ headers: {
19
+ 'Content-Type': 'application/json'
20
+ }
21
+ });
22
+
23
+ // Check if the broadcast was successful
24
+ if (response.status === 200) {
25
+ console.log("Transaction broadcasted successfully!");
26
+ console.log("Response:", response.data);
27
+ } else {
28
+ console.error(`Failed to broadcast transaction. Status Code: ${response.status}`);
29
+ console.error("Response:", response.data);
30
+ }
31
+ } catch (error) {
32
+ console.error("An error occurred while broadcasting the transaction:", error.message);
33
+ }
34
+ }
35
+
36
+ // Example Usage
37
+ const txHex = "01000000014ceac2bf9640e751498dded188c6b9bb494ddbbbcc8f4fc30b620a583c49867a0000000000ffffffff02c071b504000000001976a914226eae66f1d4da7f47015be99d1c4e2484e39b9c88ac0000000000000000336a31746c32303b44366e4e6e5069384743477a536178375148644246576b48397454477a68746642383b313b68763035633b3000000000"; // Replace with your signed transaction hex
38
+ broadcastDogecoinTransaction(txHex);
@@ -0,0 +1,19 @@
1
+ const crypto = require('crypto');
2
+
3
+ // Public key
4
+ const publicKey = Buffer.from('03860babecfccca06dc6a91e4071e91323464d885547662d4c0aba4660bef7', 'hex');
5
+
6
+ // Step 1: SHA-256
7
+ const sha256Hash = crypto.createHash('sha256').update(publicKey).digest();
8
+
9
+ // Step 2: RIPEMD-160
10
+ const ripemd160Hash = crypto.createHash('ripemd160').update(sha256Hash).digest();
11
+
12
+ // Construct the redeem script
13
+ const redeemScript = Buffer.concat([
14
+ Buffer.from([0x76, 0xa9, 0x14]), // OP_DUP OP_HASH160 (0x14 is length of hash)
15
+ ripemd160Hash, // Public key hash
16
+ Buffer.from([0x88, 0xac]) // OP_EQUALVERIFY OP_CHECKSIG
17
+ ]);
18
+
19
+ console.log('Redeem Script:', redeemScript.toString('hex'));
@@ -0,0 +1,27 @@
1
+ // checkChain.js
2
+ const client = require('../src/client'); // Import the client wrapper directly
3
+
4
+ async function checkNetworkInfo() {
5
+ if (!client) {
6
+ console.error('Failed to initialize client.');
7
+ return;
8
+ }
9
+
10
+ try {
11
+ const networkInfo = await client.getNetworkInfo();
12
+ console.log('Connected chain info:', networkInfo);
13
+
14
+ // Display specific details if available
15
+ console.log('Subversion:', networkInfo.subversion);
16
+ console.log('Connections:', networkInfo.connections);
17
+ } catch (error) {
18
+ console.error('Error fetching network info:', error);
19
+ }
20
+
21
+ const blockchainInfo = await client.getBlockchainInfo();
22
+ const isTestnet = blockchainInfo.chain === 'test';
23
+ console.log(isTestnet ? 'Running on Testnet' : 'Running on Mainnet');
24
+ }
25
+
26
+ // Run the check
27
+ checkNetworkInfo();
@@ -0,0 +1,48 @@
1
+ const litecoin = require('litecoin');
2
+
3
+ const client = new litecoin.Client({
4
+ host: '127.0.0.1',
5
+ port: 18332, // Use 9332 for mainnet
6
+ user: 'user', // Replace with actual RPC username
7
+ pass: 'pass', // Replace with actual RPC password
8
+ timeout: 30000
9
+ });
10
+
11
+ async function createAndImportAddress() {
12
+ try {
13
+ // Create a new address
14
+ const newAddress = await new Promise((resolve, reject) => {
15
+ client.getNewAddress('', (error, address) => {
16
+ if (error) reject(error);
17
+ else resolve(address);
18
+ });
19
+ });
20
+
21
+ console.log(`New address created: ${newAddress}`);
22
+
23
+ // Dump the private key for the new address
24
+ const privateKey = await new Promise((resolve, reject) => {
25
+ client.dumpPrivKey(newAddress, (error, key) => {
26
+ if (error) reject(error);
27
+ else resolve(key);
28
+ });
29
+ });
30
+
31
+ console.log(`Private key for new address: ${privateKey}`);
32
+
33
+ // Import the private key back into the wallet (optional, as it should already be in the wallet)
34
+ await new Promise((resolve, reject) => {
35
+ client.importPrivKey(privateKey, '', false, (error, result) => {
36
+ if (error) reject(error);
37
+ else resolve(result);
38
+ });
39
+ });
40
+
41
+ console.log('Private key imported successfully into the wallet.');
42
+
43
+ } catch (error) {
44
+ console.error('Error during address creation and import:', error);
45
+ }
46
+ }
47
+
48
+ createAndImportAddress();
@@ -0,0 +1,133 @@
1
+ const litecoin = require('litecoin');
2
+ const axios = require('axios');
3
+ const util = require('util');
4
+ const litecore = require('bitcore-lib-ltc');
5
+ const encoder = require('../src/txEncoder.js')
6
+ const interface = require('../src/walletInterface.js')
7
+
8
+ const clientConfig = {
9
+ host: '127.0.0.1',
10
+ port: 18332, // Testnet RPC port
11
+ user: 'user',
12
+ pass: 'pass',
13
+ timeout: 10000
14
+ };
15
+
16
+ const client = new litecoin.Client(clientConfig);
17
+
18
+ // Promisify necessary RPC commands
19
+ const listUnspentAsync = util.promisify(client.cmd.bind(client, 'listunspent'));
20
+ const dumpPrivKeyAsync = util.promisify(client.cmd.bind(client, 'dumpprivkey'));
21
+ const sendrawtransactionAsync = util.promisify(client.cmd.bind(client, 'sendrawtransaction'));
22
+
23
+ // Admin Address
24
+ const adminAddress = 'tltc1qa0kd2d39nmeph3hvcx8ytv65ztcywg5sazhtw8';
25
+
26
+
27
+ // Function to fetch balances for a specific address
28
+ async function getTokenBalancesForAddress(address) {
29
+ try {
30
+ const response = await axios.post('http://localhost:3000/tl_getAllBalancesForAddress', {
31
+ params: address
32
+ });
33
+ console.log(data)
34
+ return response.data;
35
+ } catch (error) {
36
+ console.error(`Error fetching balances for ${address}:`, error.message);
37
+ throw error;
38
+ }
39
+ }
40
+
41
+ // Function to find the first address with $TL balance
42
+ async function findAddressWithTLBalance() {
43
+ try {
44
+ console.log('Fetching all UTXOs to find wallet addresses...');
45
+ const unspentOutputs = await listUnspentAsync(0, 9999999);
46
+
47
+ // Extract unique addresses from UTXOs
48
+ const uniqueAddresses = [...new Set(unspentOutputs.map(utxo => utxo.address))];
49
+ console.log(JSON.stringify(uniqueAddresses))
50
+ console.log(`Found ${uniqueAddresses.length} addresses. Checking for TL balance...`);
51
+
52
+ // Loop through each address and fetch balances
53
+ for (const address of uniqueAddresses) {
54
+ if (address === adminAddress) continue; // Skip admin address
55
+
56
+ const balances = await getTokenBalancesForAddress(address);
57
+
58
+ // Check if property ID 1 (TL) has a balance > 0
59
+ if (balances['1'] && balances['1'].amount > 0) {
60
+ console.log(`Address with TL Balance found: ${address}`);
61
+ return address;
62
+ }
63
+ }
64
+
65
+ throw new Error('No address with TL balance found.');
66
+ } catch (error) {
67
+ console.error('Error finding address with TL balance:', error.message);
68
+ throw error;
69
+ }
70
+ }
71
+
72
+ // Build, sign, and broadcast transaction
73
+ async function buildSignAndSendTransaction(fromAddress, metadata) {
74
+ try {
75
+ console.log('Preparing transaction...');
76
+
77
+ // Step 1: Dump private key and get UTXOs
78
+ const privateKeyWIF = await dumpPrivKeyAsync(fromAddress);
79
+ const privateKey = litecore.PrivateKey.fromWIF(privateKeyWIF);
80
+ const unspentOutputs = await listUnspentAsync(0, 9999999, [fromAddress]);
81
+
82
+ if (!unspentOutputs.length) throw new Error('No unspent outputs available.');
83
+
84
+ // Step 2: Select the largest UTXO
85
+ const largestUTXO = unspentOutputs.reduce((prev, curr) => prev.amount > curr.amount ? prev : curr);
86
+
87
+ console.log('Using UTXO:', largestUTXO);
88
+
89
+ // Step 3: Create and sign transaction
90
+ const utxo = {
91
+ txId: largestUTXO.txid,
92
+ outputIndex: largestUTXO.vout,
93
+ script: largestUTXO.scriptPubKey,
94
+ satoshis: Math.floor(largestUTXO.amount * 1e8)
95
+ };
96
+
97
+ const params = {revoke:0, id:0, targetAddress:fromAddress,metaData:metadata}
98
+
99
+ const payload = encoder.encodeIssueOrRevokeAttestation(params)
100
+
101
+ const transaction = new litecore.Transaction()
102
+ .from(utxo) // UTXO input
103
+ .addOutput(new litecore.Transaction.Output({
104
+ satoshis: 1000, // small OP_RETURN fee
105
+ script: litecore.Script.buildDataOut(payload) // Embed metadata in OP_RETURN
106
+ }))
107
+ .change(fromAddress) // Change back to sender
108
+ .sign(privateKey); // Sign transaction
109
+
110
+ console.log('Raw Transaction Hex:', transaction.toString());
111
+
112
+ // Step 4: Broadcast transaction
113
+ const txid = await sendrawtransactionAsync(transaction.serialize());
114
+ console.log(`Transaction broadcasted successfully. TXID: ${txid}`);
115
+ } catch (error) {
116
+ console.error('Error building/signing transaction:', error.message);
117
+ throw error;
118
+ }
119
+ }
120
+
121
+ // Main function to issue attestation
122
+ async function issueAttestation(metadata) {
123
+ try {
124
+ const fromAddress = await findAddressWithTLBalance();
125
+ console.log(`Sending attestation from ${fromAddress} with metadata: ${metadata}`);
126
+ await buildSignAndSendTransaction(fromAddress, metadata);
127
+ } catch (error) {
128
+ console.error('Failed to issue attestation:', error.message);
129
+ }
130
+ }
131
+
132
+ // Run the attestation script
133
+ buildSignAndSendTransaction('tltc1qn3src8lgu50gxhndn5hnd6zrc9yv2364wu858m','CL');
@@ -0,0 +1,118 @@
1
+ const litecoin = require('litecoin');
2
+ const axios = require('axios');
3
+ const util = require('util');
4
+ const litecore = require('bitcore-lib-ltc');
5
+ const encoder = require('../src/txEncoder.js');
6
+
7
+ const clientConfig = {
8
+ host: '127.0.0.1',
9
+ port: 19332, // Testnet RPC port
10
+ user: 'user',
11
+ pass: 'pass',
12
+ timeout: 10000
13
+ };
14
+
15
+ const client = new litecoin.Client(clientConfig);
16
+
17
+ // Promisify necessary RPC commands
18
+ const listUnspentAsync = util.promisify(client.cmd.bind(client, 'listunspent'));
19
+ const dumpPrivKeyAsync = util.promisify(client.cmd.bind(client, 'dumpprivkey'));
20
+ const sendrawtransactionAsync = util.promisify(client.cmd.bind(client, 'sendrawtransaction'));
21
+
22
+ const BTC_PRICE_API_URL = 'https://api.coingecko.com/api/v3/simple/price?ids=litecoin&vs_currencies=usd';
23
+
24
+ // Fetch the BTC price
25
+ async function fetchBTCPrice() {
26
+ try {
27
+ const response = await axios.get(BTC_PRICE_API_URL);
28
+ const price = response.data.litecoin.usd;
29
+ console.log('Fetched BTC Price:', price);
30
+ return price;
31
+ } catch (error) {
32
+ console.error('Error fetching BTC price:', error.message);
33
+ throw error;
34
+ }
35
+ }
36
+
37
+ // Build, sign, and send the transaction
38
+ async function buildSignAndSendTransaction(fromAddress, btcPrice) {
39
+ //try {
40
+ console.log('Preparing transaction with BTC Price:', btcPrice);
41
+
42
+ // Dump private key and get UTXOs
43
+ const privateKeyWIF = await dumpPrivKeyAsync(fromAddress);
44
+ const privateKey = litecore.PrivateKey.fromWIF(privateKeyWIF);
45
+ const unspentOutputs = await listUnspentAsync(0, 9999999, [fromAddress]);
46
+ console.log('unspent '+JSON.stringify(unspentOutputs))
47
+ if (!unspentOutputs.length) throw new Error('No unspent outputs available.');
48
+
49
+ const underlyingOracleId = 2; // Replace with your underlying oracle ID
50
+ const collateralPropertyId = 5; // Replace with your collateral property ID
51
+ const leverage = 10; // Example leverage
52
+ const expiryPeriod = 4032; // Example expiry period
53
+ const series = 5;
54
+ // Select the largest UTXO
55
+ const largestUTXO = unspentOutputs.reduce((prev, curr) => prev.amount > curr.amount ? prev : curr);
56
+ console.log('Using UTXO:', largestUTXO);
57
+ if(largestUTXO.spendable==true){
58
+ const utxo = {
59
+ txId: largestUTXO.txid,
60
+ outputIndex: largestUTXO.vout,
61
+ script: largestUTXO.scriptPubKey,
62
+ satoshis: Math.floor(largestUTXO.amount * 1e8)
63
+ };
64
+ }else{
65
+ const utxo = unspentOutputs
66
+ }
67
+
68
+
69
+ // Create the payload
70
+ const params = {
71
+ native: false,
72
+ underlyingOracleId: 2,
73
+ onChainData: '',
74
+ notionalPropertyId: 0,
75
+ notionalValue: 1,
76
+ collateralPropertyId: 's1-1',
77
+ leverage: leverage,
78
+ expiryPeriod: expiryPeriod,
79
+ series: series,
80
+ inverse: true,
81
+ fee: false
82
+ }
83
+
84
+ const payload = encoder.encodeCreateFutureContractSeries(params);
85
+
86
+ // Create and sign the transaction
87
+ const transaction = new litecore.Transaction()
88
+ .from(largestUTXO) // Add UTXO as input
89
+ .addOutput(new litecore.Transaction.Output({
90
+ satoshis: 0, // OP_RETURN fee
91
+ script: litecore.Script.buildDataOut(payload) // Embed payload in OP_RETURN
92
+ }))
93
+ .change(fromAddress) // Send change back to sender
94
+ .sign(privateKey); // Sign transaction
95
+
96
+ console.log('Raw Transaction Hex:', transaction.toString());
97
+
98
+ // Broadcast the transaction
99
+ const txid = await sendrawtransactionAsync(transaction.serialize());
100
+ console.log(`Transaction broadcasted successfully. TXID: ${txid}`);
101
+ //} catch (error) {
102
+ // console.error('Error building/signing transaction:', error.message);
103
+ // throw error;
104
+ //}
105
+ }
106
+
107
+ // Main function to fetch BTC price and send the attestation
108
+ async function createContract() {
109
+ //try {
110
+ const fromAddress = 'tltc1qa0kd2d39nmeph3hvcx8ytv65ztcywg5sazhtw8'; // Admin address
111
+ const btcPrice = await fetchBTCPrice();
112
+ await buildSignAndSendTransaction(fromAddress, btcPrice);
113
+ //} catch (error) {
114
+ //console.error('Failed to publish BTC price:', error.message);
115
+ //}
116
+ }
117
+
118
+ createContract()
@@ -0,0 +1,94 @@
1
+ const litecoin = require('litecoin');
2
+ const axios = require('axios');
3
+ const util = require('util');
4
+ const litecore = require('bitcore-lib-ltc');
5
+ const encoder = require('../src/txEncoder.js')
6
+ const interface = require('../src/walletInterface.js')
7
+
8
+ const clientConfig = {
9
+ host: '127.0.0.1',
10
+ port: 18332, // Testnet RPC port
11
+ user: 'user',
12
+ pass: 'pass',
13
+ timeout: 10000
14
+ };
15
+
16
+ const client = new litecoin.Client(clientConfig);
17
+
18
+ // Promisify necessary RPC commands
19
+ const listUnspentAsync = util.promisify(client.cmd.bind(client, 'listunspent'));
20
+ const dumpPrivKeyAsync = util.promisify(client.cmd.bind(client, 'dumpprivkey'));
21
+ const sendrawtransactionAsync = util.promisify(client.cmd.bind(client, 'sendrawtransaction'));
22
+
23
+ // Admin Address
24
+ const adminAddress = 'tltc1qa0kd2d39nmeph3hvcx8ytv65ztcywg5sazhtw8';
25
+
26
+ // Build, sign, and broadcast transaction
27
+ async function buildSignAndSendTransaction(fromAddress) {
28
+ try {
29
+ console.log('Preparing transaction...');
30
+
31
+ // Step 1: Dump private key and get UTXOs
32
+ const privateKeyWIF = await dumpPrivKeyAsync(fromAddress);
33
+ console.log('priv key '+privateKeyWIF)
34
+ const privateKey = litecore.PrivateKey.fromWIF(privateKeyWIF);
35
+ const unspentOutputs = await listUnspentAsync(0, 9999999, [fromAddress]);
36
+
37
+ if (!unspentOutputs.length) throw new Error('No unspent outputs available.');
38
+
39
+ // Step 2: Select the largest UTXO
40
+ const largestUTXO = unspentOutputs.reduce((prev, curr) => prev.amount > curr.amount ? prev : curr);
41
+
42
+ console.log('Using UTXO:', largestUTXO);
43
+
44
+ // Step 3: Create and sign transaction
45
+ const utxo = {
46
+ txId: largestUTXO.txid,
47
+ outputIndex: largestUTXO.vout,
48
+ script: largestUTXO.scriptPubKey,
49
+ satoshis: Math.floor(largestUTXO.amount * 1e8)
50
+ };
51
+
52
+ const params = {ticker:"LTC/USD", url:'', backupAddress:'', whitelists:[],lag:3}
53
+
54
+ const payload = encoder.encodeCreateOracle(params)
55
+
56
+ if (payload.length > 80) {
57
+ throw new Error('Payload exceeds OP_RETURN data size limit.');
58
+ }
59
+
60
+
61
+ const transaction = new litecore.Transaction()
62
+ .from(utxo) // UTXO input
63
+ .addOutput(new litecore.Transaction.Output({
64
+ satoshis: 0, // small OP_RETURN fee
65
+ script: litecore.Script.buildDataOut(payload) // Embed metadata in OP_RETURN
66
+ }))
67
+ .change(fromAddress) // Change back to sender
68
+ .sign(privateKey); // Sign transaction
69
+
70
+ console.log('Raw Transaction Hex:', transaction.toString());
71
+
72
+ // Step 4: Broadcast transaction
73
+ const txid = await sendrawtransactionAsync(transaction.uncheckedSerialize());
74
+ console.log(`Transaction broadcasted successfully. TXID: ${txid}`);
75
+ } catch (error) {
76
+ console.error('Error building/signing transaction:', error.message);
77
+ throw error;
78
+ }
79
+ }
80
+
81
+ // Main function to issue attestation
82
+ async function issueAttestation(address, metadata) {
83
+ try {
84
+ const fromAddress = await findAddressWithTLBalance();
85
+ console.log(`Sending attestation from ${fromAddress} with metadata: ${metadata}`);
86
+ await buildSignAndSendTransaction(fromAddress, metadata);
87
+ } catch (error) {
88
+ console.error('Failed to issue attestation:', error.message);
89
+ }
90
+ }
91
+
92
+ // Run the attestation script
93
+ buildSignAndSendTransaction('tltc1qa0kd2d39nmeph3hvcx8ytv65ztcywg5sazhtw8');
94
+