edge-currency-monero 1.3.0 → 1.3.2
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,14 @@
|
|
|
2
2
|
|
|
3
3
|
# Unreleased
|
|
4
4
|
|
|
5
|
+
# 1.3.2 (2024-11-19)
|
|
6
|
+
|
|
7
|
+
- fixed: URI parsing and creation according to the correct format
|
|
8
|
+
|
|
9
|
+
# 1.3.1 (2024-03-21)
|
|
10
|
+
|
|
11
|
+
- fixed: Include missing files in the NPM package.
|
|
12
|
+
|
|
5
13
|
# 1.3.0 (2024-03-21)
|
|
6
14
|
|
|
7
15
|
- changed: Switch our codebase from Flow to TypeScript.
|
package/lib/MoneroTools.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var _biggystring = require('biggystring');
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }var _biggystring = require('biggystring');
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
@@ -115,7 +115,10 @@ function getParameterByName(param, url) {
|
|
|
115
115
|
throw new Error('InvalidPublicAddressError')
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
-
|
|
118
|
+
// Prioritize the correct Monero URI format, while falling back to BIP21
|
|
119
|
+
// formats.
|
|
120
|
+
const amountStr =
|
|
121
|
+
_nullishCoalesce(getParameterByName('tx_amount', uri), () => ( getParameterByName('amount', uri)))
|
|
119
122
|
if (amountStr != null) {
|
|
120
123
|
const denom = getDenomInfo('XMR')
|
|
121
124
|
if (denom == null) {
|
|
@@ -126,8 +129,12 @@ function getParameterByName(param, url) {
|
|
|
126
129
|
currencyCode = 'XMR'
|
|
127
130
|
}
|
|
128
131
|
const uniqueIdentifier = getParameterByName('tx_payment_id', uri)
|
|
129
|
-
const label =
|
|
130
|
-
|
|
132
|
+
const label =
|
|
133
|
+
_nullishCoalesce(getParameterByName('recipient_name', uri), () => (
|
|
134
|
+
getParameterByName('label', uri)))
|
|
135
|
+
const message =
|
|
136
|
+
_nullishCoalesce(getParameterByName('tx_description', uri), () => (
|
|
137
|
+
getParameterByName('message', uri)))
|
|
131
138
|
const category = getParameterByName('category', uri)
|
|
132
139
|
|
|
133
140
|
const edgeParsedUri = {
|
|
@@ -184,13 +191,13 @@ function getParameterByName(param, url) {
|
|
|
184
191
|
}
|
|
185
192
|
const amount = _biggystring.div.call(void 0, nativeAmount, denom.multiplier, 12)
|
|
186
193
|
|
|
187
|
-
queryString += '
|
|
194
|
+
queryString += 'tx_amount=' + amount + '&'
|
|
188
195
|
}
|
|
189
196
|
if (typeof obj.label === 'string') {
|
|
190
|
-
queryString += '
|
|
197
|
+
queryString += 'recipient_name=' + obj.label + '&'
|
|
191
198
|
}
|
|
192
199
|
if (typeof obj.message === 'string') {
|
|
193
|
-
queryString += '
|
|
200
|
+
queryString += 'tx_description=' + obj.message + '&'
|
|
194
201
|
}
|
|
195
202
|
queryString = queryString.substr(0, queryString.length - 1)
|
|
196
203
|
|
|
@@ -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
|
|
@@ -3460,6 +3460,8 @@ var MoneroTools = /*#__PURE__*/function () {
|
|
|
3460
3460
|
key: "parseUri",
|
|
3461
3461
|
value: function () {
|
|
3462
3462
|
var _parseUri = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3(uri) {
|
|
3463
|
+
var _getParameterByName, _getParameterByName2, _getParameterByName3;
|
|
3464
|
+
|
|
3463
3465
|
var parsedUri, address, nativeAmount, currencyCode, amountStr, denom, uniqueIdentifier, label, message, category, edgeParsedUri;
|
|
3464
3466
|
return regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
3465
3467
|
while (1) {
|
|
@@ -3514,7 +3516,9 @@ var MoneroTools = /*#__PURE__*/function () {
|
|
|
3514
3516
|
throw new Error('InvalidPublicAddressError');
|
|
3515
3517
|
|
|
3516
3518
|
case 21:
|
|
3517
|
-
|
|
3519
|
+
// Prioritize the correct Monero URI format, while falling back to BIP21
|
|
3520
|
+
// formats.
|
|
3521
|
+
amountStr = (_getParameterByName = getParameterByName('tx_amount', uri)) !== null && _getParameterByName !== void 0 ? _getParameterByName : getParameterByName('amount', uri);
|
|
3518
3522
|
|
|
3519
3523
|
if (!(amountStr != null)) {
|
|
3520
3524
|
_context3.next = 29;
|
|
@@ -3537,8 +3541,8 @@ var MoneroTools = /*#__PURE__*/function () {
|
|
|
3537
3541
|
|
|
3538
3542
|
case 29:
|
|
3539
3543
|
uniqueIdentifier = getParameterByName('tx_payment_id', uri);
|
|
3540
|
-
label = getParameterByName('label', uri);
|
|
3541
|
-
message = getParameterByName('message', uri);
|
|
3544
|
+
label = (_getParameterByName2 = getParameterByName('recipient_name', uri)) !== null && _getParameterByName2 !== void 0 ? _getParameterByName2 : getParameterByName('label', uri);
|
|
3545
|
+
message = (_getParameterByName3 = getParameterByName('tx_description', uri)) !== null && _getParameterByName3 !== void 0 ? _getParameterByName3 : getParameterByName('message', uri);
|
|
3542
3546
|
category = getParameterByName('category', uri);
|
|
3543
3547
|
edgeParsedUri = {
|
|
3544
3548
|
publicAddress: address
|
|
@@ -3647,15 +3651,15 @@ var MoneroTools = /*#__PURE__*/function () {
|
|
|
3647
3651
|
|
|
3648
3652
|
case 21:
|
|
3649
3653
|
amount = (0,biggystring__WEBPACK_IMPORTED_MODULE_0__.div)(nativeAmount, denom.multiplier, 12);
|
|
3650
|
-
queryString += '
|
|
3654
|
+
queryString += 'tx_amount=' + amount + '&';
|
|
3651
3655
|
|
|
3652
3656
|
case 23:
|
|
3653
3657
|
if (typeof obj.label === 'string') {
|
|
3654
|
-
queryString += '
|
|
3658
|
+
queryString += 'recipient_name=' + obj.label + '&';
|
|
3655
3659
|
}
|
|
3656
3660
|
|
|
3657
3661
|
if (typeof obj.message === 'string') {
|
|
3658
|
-
queryString += '
|
|
3662
|
+
queryString += 'tx_description=' + obj.message + '&';
|
|
3659
3663
|
}
|
|
3660
3664
|
|
|
3661
3665
|
queryString = queryString.substr(0, queryString.length - 1);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "edge-currency-monero",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.2",
|
|
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 -
|
|
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",
|