edge-currency-monero 1.5.0 → 2.0.0

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
@@ -1,5 +1,16 @@
1
1
  # edge-currency-monero
2
2
 
3
+ ## Unreleased
4
+
5
+ ## 2.0.0 (2025-10-02)
6
+
7
+ - changed: *Breaking change* Change to use Edge LWS servers. Must specify edgeApiKey in plugin options, instead of apiKey
8
+
9
+ ## 1.5.1 (2025-07-03)
10
+
11
+ - fixed: Fix `getFreshAddress` to return a non-empty `publicAddress` when calling immediately after creating a wallet.
12
+ - fixed: Handle insufficient funds errors from native library into `InsufficientFundsError`.
13
+
3
14
  ## 1.5.0 (2025-04-21)
4
15
 
5
16
  - added: Support for multiple spend targets.
@@ -85,18 +85,19 @@ const PRIMARY_CURRENCY_TOKEN_ID = null
85
85
 
86
86
 
87
87
 
88
+ __init() {this.loginPromise = null}
88
89
 
89
90
  constructor(
90
91
  env,
91
92
  tools,
92
93
  walletInfo,
93
94
  opts
94
- ) {
95
+ ) {;MoneroEngine.prototype.__init.call(this);
95
96
  const { callbacks, userSettings = {}, walletLocalDisklet } = opts
96
97
  const initOptions = _moneroTypes.asMoneroInitOptions.call(void 0, _nullishCoalesce(env.initOptions, () => ( {})))
97
98
  const { networkInfo } = tools
98
99
 
99
- this.apiKey = initOptions.apiKey
100
+ this.apiKey = initOptions.edgeApiKey
100
101
  this.io = env.io
101
102
  this.log = opts.log
102
103
  this.engineOn = false
@@ -109,7 +110,7 @@ const PRIMARY_CURRENCY_TOKEN_ID = null
109
110
  this.currencyInfo = _moneroInfo.currencyInfo
110
111
  this.currencyTools = tools
111
112
  this.myMoneroApi = new (0, _MyMoneroApi.MyMoneroApi)(tools.cppBridge, {
112
- apiKey: initOptions.apiKey,
113
+ apiKey: initOptions.edgeApiKey,
113
114
  apiServer: networkInfo.defaultServer,
114
115
  fetch: env.io.fetch,
115
116
  nettype: networkInfo.nettype
@@ -133,9 +134,6 @@ const PRIMARY_CURRENCY_TOKEN_ID = null
133
134
  )
134
135
  }
135
136
 
136
- // Hard coded for testing
137
- // this.walletInfo.keys.moneroKey = '389b07b3466eed587d6bdae09a3613611de9add2635432d6cd1521af7bbc3757'
138
- // this.walletInfo.keys.moneroAddress = '0x9fa817e5A48DD1adcA7BEc59aa6E3B1F5C4BeA9a'
139
137
  this.edgeTxLibCallbacks = callbacks
140
138
  this.walletLocalDisklet = walletLocalDisklet
141
139
 
@@ -174,6 +172,20 @@ const PRIMARY_CURRENCY_TOKEN_ID = null
174
172
  // Login to mymonero.com server
175
173
  // **********************************************
176
174
  async loginIfNewAddress(privateKeys) {
175
+ if (this.loginPromise != null) {
176
+ return await this.loginPromise
177
+ }
178
+ this.loginPromise = this.performLogin(privateKeys)
179
+
180
+ try {
181
+ await this.loginPromise
182
+ } finally {
183
+ // Clear the promise once completed (success OR failure)
184
+ this.loginPromise = null
185
+ }
186
+ }
187
+
188
+ async performLogin(privateKeys) {
177
189
  try {
178
190
  const result = await this.myMoneroApi.login({
179
191
  address: this.walletInfo.keys.moneroAddress,
@@ -578,8 +590,18 @@ const PRIMARY_CURRENCY_TOKEN_ID = null
578
590
  async getFreshAddress(
579
591
  options
580
592
  ) {
593
+ // Wait for login to complete if it's in progress
594
+ if (this.loginPromise != null) {
595
+ await this.loginPromise
596
+ }
597
+
581
598
  // Do not show the address before logging into my monero...
582
- if (!this.walletLocalData.hasLoggedIn) return { publicAddress: '' }
599
+ if (!this.walletLocalData.hasLoggedIn) {
600
+ this.log.warn(
601
+ 'Attempted to retrieve `publicAddress` before successfully logging in'
602
+ )
603
+ return { publicAddress: '' }
604
+ }
583
605
  return { publicAddress: this.walletInfo.keys.moneroAddress }
584
606
  }
585
607
 
@@ -629,12 +651,20 @@ const PRIMARY_CURRENCY_TOKEN_ID = null
629
651
  },
630
652
  options
631
653
  )
632
- } catch (e) {
654
+ } catch (error) {
655
+ if (!(error instanceof Error)) {
656
+ throw new Error(String(error))
657
+ }
658
+ if (error.message === 'Not enough spendables') {
659
+ throw new (0, _types.InsufficientFundsError)({
660
+ tokenId: PRIMARY_CURRENCY_TOKEN_ID
661
+ })
662
+ }
633
663
  // This error is specific to mymonero-core-js: github.com/mymonero/mymonero-core-cpp/blob/a53e57f2a376b05bb0f4d851713321c749e5d8d9/src/monero_transfer_utils.hpp#L112-L162
634
- this.log.error(e.message)
664
+ this.log.error(error.message)
635
665
  const regex = / Have (\d*\.?\d+) XMR; need (\d*\.?\d+) XMR./gm
636
666
  const subst = `\nHave: $1 XMR.\nNeed: $2 XMR.`
637
- const msgFormatted = e.message.replace(regex, subst)
667
+ const msgFormatted = error.message.replace(regex, subst)
638
668
  throw new Error(msgFormatted)
639
669
  }
640
670
  }
@@ -37,7 +37,7 @@ function getParameterByName(param, url) {
37
37
 
38
38
 
39
39
  __init() {this.networkInfo = {
40
- defaultServer: 'https://edge.mymonero.com:8443',
40
+ defaultServer: _moneroInfo.MONERO_LWS_SERVER,
41
41
  nettype: 'MAINNET'
42
42
  }}
43
43
 
package/lib/moneroInfo.js CHANGED
@@ -2,9 +2,11 @@
2
2
 
3
3
 
4
4
 
5
+ const MONERO_LWS_SERVER = 'https://monerolws1.edge.app'; exports.MONERO_LWS_SERVER = MONERO_LWS_SERVER
6
+
5
7
  const defaultSettings = {
6
8
  enableCustomServers: false,
7
- moneroLightwalletServer: 'https://edge.mymonero.com:8443'
9
+ moneroLightwalletServer: exports.MONERO_LWS_SERVER
8
10
  }
9
11
 
10
12
  const currencyInfo = {
@@ -16,7 +16,7 @@ var _cleaners = require('cleaners');
16
16
 
17
17
 
18
18
  const asMoneroInitOptions = _cleaners.asObject.call(void 0, {
19
- apiKey: _cleaners.asOptional.call(void 0, _cleaners.asString, '')
19
+ edgeApiKey: _cleaners.asOptional.call(void 0, _cleaners.asString, '')
20
20
  }); exports.asMoneroInitOptions = asMoneroInitOptions
21
21
 
22
22