edge-currency-monero 1.3.0 → 1.3.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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  # Unreleased
4
4
 
5
+ # 1.3.1 (2024-03-21)
6
+
7
+ - fixed: Include missing files in the NPM package.
8
+
5
9
  # 1.3.0 (2024-03-21)
6
10
 
7
11
  - changed: Switch our codebase from Flow to TypeScript.
@@ -0,0 +1,204 @@
1
+ // This has been taken from @mymonero/mymonero-response-parser-utils v2.0.0
2
+ // We have made the "__sync" methods async and deleted the rest.
3
+
4
+ // Copyright (c) 2014-2019, MyMonero.com
5
+ //
6
+ // All rights reserved.
7
+ //
8
+ // Redistribution and use in source and binary forms, with or without modification, are
9
+ // permitted provided that the following conditions are met:
10
+ //
11
+ // 1. Redistributions of source code must retain the above copyright notice, this list of
12
+ // conditions and the following disclaimer.
13
+ //
14
+ // 2. Redistributions in binary form must reproduce the above copyright notice, this list
15
+ // of conditions and the following disclaimer in the documentation and/or other
16
+ // materials provided with the distribution.
17
+ //
18
+ // 3. Neither the name of the copyright holder nor the names of its contributors may be
19
+ // used to endorse or promote products derived from this software without specific
20
+ // prior written permission.
21
+ //
22
+ // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
23
+ // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
24
+ // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
25
+ // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26
+ // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27
+ // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28
+ // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29
+ // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
30
+ // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
+ //
32
+ 'use strict'
33
+ //
34
+ const JSBigInt = require('@mymonero/mymonero-bigint').BigInteger
35
+ const monero_amount_format_utils = require('@mymonero/mymonero-money-format')
36
+ const monero_keyImage_cache_utils = require("./mymonero-keyimage-cache.js")
37
+ //
38
+ async function Parsed_AddressInfo__async (
39
+ keyImage_cache,
40
+ data,
41
+ address,
42
+ view_key__private,
43
+ spend_key__public,
44
+ spend_key__private,
45
+ coreBridge_instance
46
+ ) {
47
+ // -> returnValuesByKey
48
+ const total_received = new JSBigInt(data.total_received || 0)
49
+ const locked_balance = new JSBigInt(data.locked_funds || 0)
50
+ var total_sent = new JSBigInt(data.total_sent || 0) // will be modified in place
51
+ //
52
+ const account_scanned_tx_height = data.scanned_height || 0
53
+ const account_scanned_block_height = data.scanned_block_height || 0
54
+ const account_scan_start_height = data.start_height || 0
55
+ const transaction_height = data.transaction_height || 0
56
+ const blockchain_height = data.blockchain_height || 0
57
+ const spent_outputs = data.spent_outputs || []
58
+ //
59
+ for (let spent_output of spent_outputs) {
60
+ var key_image = await monero_keyImage_cache_utils.Lazy_KeyImage(
61
+ keyImage_cache,
62
+ spent_output.tx_pub_key,
63
+ spent_output.out_index,
64
+ address,
65
+ view_key__private,
66
+ spend_key__public,
67
+ spend_key__private,
68
+ coreBridge_instance
69
+ )
70
+ if (spent_output.key_image !== key_image) {
71
+ // console.log('💬 Output used as mixin (' + spent_output.key_image + '/' + key_image + ')')
72
+ total_sent = new JSBigInt(total_sent).subtract(spent_output.amount)
73
+ }
74
+ }
75
+ //
76
+ const ratesBySymbol = data.rates || {} // jic it's not there
77
+ //
78
+ const returnValuesByKey = {
79
+ total_received_String: total_received
80
+ ? total_received.toString()
81
+ : null,
82
+ locked_balance_String: locked_balance
83
+ ? locked_balance.toString()
84
+ : null,
85
+ total_sent_String: total_sent ? total_sent.toString() : null,
86
+ // ^serialized JSBigInt
87
+ spent_outputs: spent_outputs,
88
+ account_scanned_tx_height: account_scanned_tx_height,
89
+ account_scanned_block_height: account_scanned_block_height,
90
+ account_scan_start_height: account_scan_start_height,
91
+ transaction_height: transaction_height,
92
+ blockchain_height: blockchain_height,
93
+ //
94
+ ratesBySymbol: ratesBySymbol
95
+ }
96
+ return returnValuesByKey
97
+ }
98
+ exports.Parsed_AddressInfo__async = Parsed_AddressInfo__async
99
+ //
100
+ async function Parsed_AddressTransactions__async (
101
+ keyImage_cache,
102
+ data,
103
+ address,
104
+ view_key__private,
105
+ spend_key__public,
106
+ spend_key__private,
107
+ coreBridge_instance
108
+ ) {
109
+ const account_scanned_height = data.scanned_height || 0
110
+ const account_scanned_block_height = data.scanned_block_height || 0
111
+ const account_scan_start_height = data.start_height || 0
112
+ const transaction_height = data.transaction_height || 0
113
+ const blockchain_height = data.blockchain_height || 0
114
+ //
115
+ const transactions = data.transactions || []
116
+ //
117
+ // TODO: rewrite this with more clarity if possible
118
+ for (let i = 0; i < transactions.length; ++i) {
119
+ if ((transactions[i].spent_outputs || []).length > 0) {
120
+ for (var j = 0; j < transactions[i].spent_outputs.length; ++j) {
121
+ var key_image = await monero_keyImage_cache_utils.Lazy_KeyImage(
122
+ keyImage_cache,
123
+ transactions[i].spent_outputs[j].tx_pub_key,
124
+ transactions[i].spent_outputs[j].out_index,
125
+ address,
126
+ view_key__private,
127
+ spend_key__public,
128
+ spend_key__private,
129
+ coreBridge_instance
130
+ )
131
+ if (transactions[i].spent_outputs[j].key_image !== key_image) {
132
+ // console.log('Output used as mixin, ignoring (' + transactions[i].spent_outputs[j].key_image + '/' + key_image + ')')
133
+ transactions[i].total_sent = new JSBigInt(
134
+ transactions[i].total_sent
135
+ )
136
+ .subtract(transactions[i].spent_outputs[j].amount)
137
+ .toString()
138
+ transactions[i].spent_outputs.splice(j, 1)
139
+ j--
140
+ }
141
+ }
142
+ }
143
+ if (
144
+ new JSBigInt(transactions[i].total_received || 0)
145
+ .add(transactions[i].total_sent || 0)
146
+ .compare(0) <= 0
147
+ ) {
148
+ transactions.splice(i, 1)
149
+ i--
150
+ continue
151
+ }
152
+ transactions[i].amount = new JSBigInt(
153
+ transactions[i].total_received || 0
154
+ )
155
+ .subtract(transactions[i].total_sent || 0)
156
+ .toString()
157
+ transactions[i].approx_float_amount = parseFloat(
158
+ monero_amount_format_utils.formatMoney(transactions[i].amount)
159
+ )
160
+ transactions[i].timestamp = transactions[i].timestamp
161
+ const record__payment_id = transactions[i].payment_id
162
+ if (typeof record__payment_id !== 'undefined' && record__payment_id) {
163
+ if (record__payment_id.length == 16) {
164
+ // short (encrypted) pid
165
+ if (transactions[i].approx_float_amount < 0) {
166
+ // outgoing
167
+ delete transactions[i]['payment_id'] // need to filter these out .. because the server can't filter out short (encrypted) pids on outgoing txs
168
+ }
169
+ }
170
+ }
171
+ }
172
+ transactions.sort(function (a, b) {
173
+ if (a.mempool == true) {
174
+ if (b.mempool != true) {
175
+ return -1 // a first
176
+ }
177
+ // both mempool - fall back to .id compare
178
+ } else if (b.mempool == true) {
179
+ return 1 // b first
180
+ }
181
+ return b.id - a.id
182
+ })
183
+ // prepare transactions to be serialized
184
+ for (let transaction of transactions) {
185
+ transaction.amount = transaction.amount.toString() // JSBigInt -> String
186
+ if (
187
+ typeof transaction.total_sent !== 'undefined' &&
188
+ transaction.total_sent !== null
189
+ ) {
190
+ transaction.total_sent = transaction.total_sent.toString()
191
+ }
192
+ }
193
+ // on the other side, we convert transactions timestamp to Date obj
194
+ const returnValuesByKey = {
195
+ account_scanned_height: account_scanned_height,
196
+ account_scanned_block_height: account_scanned_block_height,
197
+ account_scan_start_height: account_scan_start_height,
198
+ transaction_height: transaction_height,
199
+ blockchain_height: blockchain_height,
200
+ serialized_transactions: transactions
201
+ }
202
+ return returnValuesByKey
203
+ }
204
+ exports.Parsed_AddressTransactions__async = Parsed_AddressTransactions__async
@@ -0,0 +1,37 @@
1
+ // This has been taken from @mymonero/mymonero-keyimage-cache v2.0.0
2
+ // We have made `Lazy_KeyImage` async and deleted the rest.
3
+ // We have also renamed generate_key_image to generateKeyImage.
4
+
5
+ 'use strict'
6
+
7
+ const Lazy_KeyImage = async function (
8
+ mutable_keyImagesByCacheKey, // pass a mutable JS dictionary
9
+ tx_pub_key,
10
+ out_index,
11
+ public_address,
12
+ view_key__private,
13
+ spend_key__public,
14
+ spend_key__private,
15
+ coreBridge_instance // must pass this so this fn can remain synchronous
16
+ ) {
17
+ var cache_index = tx_pub_key + ':' + public_address + ':' + out_index
18
+ const cached__key_image = mutable_keyImagesByCacheKey[cache_index]
19
+ if (
20
+ typeof cached__key_image !== 'undefined' &&
21
+ cached__key_image !== null
22
+ ) {
23
+ return cached__key_image
24
+ }
25
+ var key_image = await coreBridge_instance.generateKeyImage(
26
+ tx_pub_key,
27
+ view_key__private,
28
+ spend_key__public,
29
+ spend_key__private,
30
+ out_index
31
+ )
32
+ // cache:
33
+ mutable_keyImagesByCacheKey[cache_index] = key_image
34
+ //
35
+ return key_image
36
+ }
37
+ exports.Lazy_KeyImage = Lazy_KeyImage
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "edge-currency-monero",
3
- "version": "1.3.0",
3
+ "version": "1.3.1",
4
4
  "description": "Edge Monero currency plugin",
5
5
  "homepage": "https://edge.app",
6
6
  "repository": {
@@ -21,7 +21,7 @@
21
21
  "README.md"
22
22
  ],
23
23
  "scripts": {
24
- "build": "rimraf lib && sucrase ./src -q -d ./lib -t typescript,imports && webpack",
24
+ "build": "rimraf lib && sucrase ./src -d ./lib -q -t typescript,imports && cp src/mymonero-utils/*.js lib/mymonero-utils && webpack",
25
25
  "fix": "eslint . --fix && yarn-deduplicate",
26
26
  "lint": "eslint .",
27
27
  "precommit": "lint-staged && tsc && npm test && npm run build",