@metamask/json-rpc-engine
Version:
A tool for processing JSON-RPC messages
20 lines • 620 B
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.getUniqueId = void 0;
// uint32 (two's complement) max
// more conservative than Number.MAX_SAFE_INTEGER
const MAX = 4294967295;
let idCounter = Math.floor(Math.random() * MAX);
/**
* Gets an ID that is guaranteed to be unique so long as no more than
* 4_294_967_295 (uint32 max) IDs are created, or the IDs are rapidly turned
* over.
*
* @returns The unique ID.
*/
function getUniqueId() {
idCounter = (idCounter + 1) % MAX;
return idCounter;
}
exports.getUniqueId = getUniqueId;
//# sourceMappingURL=getUniqueId.cjs.map
;