Skip to content

Commit

Permalink
names: family, reorder middle-out; first, reorder by hash (pseudo ran…
Browse files Browse the repository at this point in the history
…dom)
  • Loading branch information
iquidus committed Feb 25, 2022
1 parent 291a1ba commit 6ac020f
Show file tree
Hide file tree
Showing 4 changed files with 3,365 additions and 3,358 deletions.
21 changes: 14 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function getPersona(address) {
if (!ADDRESS.test(address)) {
return {
success: false,
error: address + " is not a valid Ubiq/Ethereum address"
error: address + " is not a valid address"
}
}
// hash the address, this will ensure minor differences in a given address
Expand All @@ -25,9 +25,13 @@ export function getPersona(address) {
let sum = new BN(0) // sum of all positions
let even = new BN(0) // sum of even positions
let odd = new BN(0) // sum of odd positions
let h1 = new BN(0) // sum of half 1 positions
let h2 = new BN(0) // sum of half 2 positions

const positions = split.entries()

/* eslint-disable no-unused-vars */
for (const [index, hex] of split.entries()) {
for (const [index, hex] of positions) {
const value = new BN(hex, 16)
sum = sum.add(value)
if (index % 2) {
Expand All @@ -50,16 +54,19 @@ export function getPersona(address) {
// total male given names: 512
// total female given names: 512
// maximum potential odd sum: 4096
let given = ''
// maximum potential even sum: 4096
let given = ''
if (sex === 0) {
given = names.female[Math.floor(odd / 8)]
// female. use sum of even positions
given = names.female[Math.floor(even / 8)]
} else {
// male. use sum of odd positions
given = names.male[Math.floor(odd / 8)]
}

// dertermine family name from a total of 4096
// maximum potential even sum: 4096
const family = names.family[even]
// determine family name from a total of 4096
// maximum potential sum: 8192
const family = names.family[Math.floor(sum/2)]

// done
return {
Expand Down
Loading

0 comments on commit 6ac020f

Please sign in to comment.