feat: add networkPrivacy user setting for NYM Mixfetch#100
Conversation
src/MoneroEngine.ts
Outdated
| // Type assertion for WIP mixfetch feature in edge-core-js | ||
| return networkPrivacy === 'nym' ? ({ privacy: 'nym' } as any) : {} |
There was a problem hiding this comment.
Updot edge-core-js before merging, and then the any can go away.
src/utils.ts
Outdated
| export function makeEngineFetch( | ||
| io: EdgeIo, | ||
| getInitOverload: () => EdgeFetchOptions = () => ({}) | ||
| ): EdgeFetchFunction { | ||
| return async (input, init) => { | ||
| const initOverload = getInitOverload() | ||
| const enhancedInit = { ...initOverload, ...init } |
There was a problem hiding this comment.
Since this guy is only called in one place, I would just put it inline in the constructor:
this.engineFetch = async (url, init) => await this.io.fetch(url, {
...init,
privacy: this.currentSettings.privacy ? ...
})It's like 1 line rather than 20, and much easier to understand.
swansontec
left a comment
There was a problem hiding this comment.
Just a one-liner left to fix.
|
|
||
| this.engineFetch = makeEngineFetch(env.io, () => { | ||
| this.engineFetch = async (uri, init) => { | ||
| const { networkPrivacy } = this.currentSettings |
There was a problem hiding this comment.
As noted in the other PR, this.currentSettings?.networkPrivacy would be safer.
c409480 to
d717e77
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
| ...(networkPrivacy === 'nym' ? { privacy: 'nym' } : {}), | ||
| ...init | ||
| }) | ||
| } |
There was a problem hiding this comment.
Privacy setting can be overridden by init options
Low Severity
The engineFetch wrapper spreads the privacy option before init, allowing any privacy field in init to override the user's networkPrivacy setting. The spread order is backwards—the user's privacy preference from currentSettings should take precedence by being spread after init, not before. While MyMoneroApi currently doesn't pass a privacy field in its init object, this doesn't match the intended behavior where the user's setting should always apply.
There was a problem hiding this comment.
Feature not a bug.
Add infrastructure to enable privacy-enhanced fetch requests:
- Add networkPrivacy field to MoneroUserSettings ('none' | 'nym')
- Add makeEngineFetch utility to wrap fetch with dynamic options
- Pass engineFetch to MyMoneroApi for all network requests
- Add networkPrivacy to defaultSettings in currencyInfo
d717e77 to
94390ca
Compare
Add infrastructure to enable privacy-enhanced fetch requests:
CHANGELOG
Does this branch warrant an entry to the CHANGELOG?
Dependencies
noneDescription
noneNote
Introduces optional privacy routing for network requests.
networkPrivacyuser setting ('none' | 'nym') with default'none'tomoneroTypesandmoneroInfodefault settingsengineFetchinMoneroEngineto pass{ privacy: 'nym' }toio.fetchwhen enabled; wires it intoMyMoneroApi.prettierrcand CHANGELOG entryedge-core-jsto^2.41.0(and lockfile), pulling in@nymproject/mix-fetchsupportWritten by Cursor Bugbot for commit 94390ca. This will update automatically on new commits. Configure here.