Merge pull request #874 from sharetribe/improve-clientside-coord-obfuscation

Seeded random used on obfuscatedCoordinatesImpl
This commit is contained in:
Vesa Luusua 2018-07-27 14:16:03 +03:00 committed by GitHub
commit a032ad2fd2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 3 deletions

View file

@ -12,6 +12,10 @@ way to update this template, but currently, we follow a pattern:
---
## Upcoming version
* [change] Use seeded random for client side coordinate obfuscation
[#874](https://github.com/sharetribe/flex-template-web/pull/874)
## v1.2.2
* [change] Change static map to dynamic map when clicked.
[#871](https://github.com/sharetribe/flex-template-web/pull/871)

View file

@ -47,6 +47,7 @@
"redux": "^4.0.0",
"redux-thunk": "^2.2.0",
"sanitize.css": "^5.0.0",
"seedrandom": "^2.4.3",
"sharetribe-scripts": "1.1.2",
"sharetribe-sdk": "https://github.com/sharetribe/sharetribe-sdk-js.git#b7ffe0fe0a5bdb0a1471e2ff36cdd25b997fb39b",
"smoothscroll-polyfill": "^0.4.0",

View file

@ -1,10 +1,16 @@
import memoize from 'lodash/memoize';
import seedrandom from 'seedrandom';
import { types as sdkTypes } from './sdkLoader';
import config from '../config';
const { LatLng } = sdkTypes;
const obfuscatedCoordinatesImpl = latlng => {
/**
* This obfuscatedCoordinatesImpl function is a temporary solution for the coordinate obfuscation.
* In the future, improved version needs to have protectedData working and
* available in accepted transaction.
*/
const obfuscatedCoordinatesImpl = (latlng, cacheKey) => {
const { lat, lng } = latlng;
const offset = config.coordinates.coordinateOffset;
@ -12,8 +18,19 @@ const obfuscatedCoordinatesImpl = latlng => {
const r = offset / 111300;
const y0 = lat;
const x0 = lng;
const u = Math.random();
const v = Math.random();
// Two seeded random numbers to be used to calculate new location
// We need seeded so that the static map URL doesn't change between requests
// (i.e. URL is cacheable)
const u = cacheKey ? seedrandom(cacheKey)() : Math.random();
const v = cacheKey
? seedrandom(
cacheKey
.split('')
.reverse()
.join('')
)()
: Math.random();
const w = r * Math.sqrt(u);
const t = 2 * Math.PI * v;
const x = w * Math.cos(t);

View file

@ -7406,6 +7406,10 @@ scriptjs@^2.5.8:
version "2.5.8"
resolved "https://registry.yarnpkg.com/scriptjs/-/scriptjs-2.5.8.tgz#d0c43955c2e6bad33b6e4edf7b53b8965aa7ca5f"
seedrandom@^2.4.3:
version "2.4.3"
resolved "https://registry.yarnpkg.com/seedrandom/-/seedrandom-2.4.3.tgz#2438504dad33917314bff18ac4d794f16d6aaecc"
select-hose@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/select-hose/-/select-hose-2.0.0.tgz#625d8658f865af43ec962bfc376a37359a4994ca"