Socket
Socket
Sign inDemoInstall

scru160

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

scru160 - npm Package Compare versions

Comparing version 0.2.3 to 0.2.4

6

dist/index.d.ts
/**
* SCRU-160: Sortable, Clock and Random number-based Unique identifier
* SCRU160: Sortable, Clock and Random number-based Unique identifier
*

@@ -10,3 +10,3 @@ * @license Apache-2.0

/**
* Generates a new SCRU-160 ID encoded in the base32hex format.
* Generates a new SCRU160 ID encoded in the base32hex format.
*

@@ -17,3 +17,3 @@ * @returns 32-character base32hexupper string (`/^[0-9A-V]{32}$/`).

/**
* Generates a new SCRU-160 ID encoded in the hexadecimal format.
* Generates a new SCRU160 ID encoded in the hexadecimal format.
*

@@ -20,0 +20,0 @@ * @returns 40-character hexadecimal string (`/^[0-9a-f]{40}$/`).

"use strict";
/**
* SCRU-160: Sortable, Clock and Random number-based Unique identifier
* SCRU160: Sortable, Clock and Random number-based Unique identifier
*

@@ -12,5 +12,5 @@ * @license Apache-2.0

const crypto_1 = require("crypto");
/** Represents SCRU-160 ID generator. */
/** Represents SCRU160 ID generator. */
class Generator {
/** Create a new SCRU-160 generator. */
/** Create a new SCRU160 generator. */
constructor() {

@@ -45,3 +45,3 @@ /** Internal state - timestamp at last generation */

/**
* Generates a new SCRU-160 ID encoded in the base32hex format.
* Generates a new SCRU160 ID encoded in the base32hex format.
*

@@ -56,3 +56,3 @@ * @returns 32-character base32hexupper string (`/^[0-9A-V]{32}$/`).

/**
* Generates a new SCRU-160 ID encoded in the hexadecimal format.
* Generates a new SCRU160 ID encoded in the hexadecimal format.
*

@@ -67,3 +67,3 @@ * @returns 40-character hexadecimal string (`/^[0-9a-f]{40}$/`).

/**
* Generates a byte sequence that represents a new SCRU-160 ID.
* Generates a byte sequence that represents a new SCRU160 ID.
*

@@ -80,3 +80,3 @@ * @returns 20-byte sequence.

}
/** Generates a new SCRU-160 ID in the form of four 40-bit integer values. */
/** Generates a new SCRU160 ID in the form of four 40-bit integer values. */
generateQuad() {

@@ -119,3 +119,3 @@ const bs = this.generate();

/**
* Generates a new SCRU-160 ID encoded in the base32hex format.
* Generates a new SCRU160 ID encoded in the base32hex format.
*

@@ -127,3 +127,3 @@ * @returns 32-character base32hexupper string (`/^[0-9A-V]{32}$/`).

/**
* Generates a new SCRU-160 ID encoded in the hexadecimal format.
* Generates a new SCRU160 ID encoded in the hexadecimal format.
*

@@ -130,0 +130,0 @@ * @returns 40-character hexadecimal string (`/^[0-9a-f]{40}$/`).

{
"name": "scru160",
"version": "0.2.3",
"description": "SCRU-160: Sortable, Clock and Random number-based Unique identifier",
"version": "0.2.4",
"description": "SCRU160: Sortable, Clock and Random number-based Unique identifier",
"main": "./dist/index.js",

@@ -45,3 +45,3 @@ "types": "./dist/index.d.ts",

"devDependencies": {
"@types/node": "^16.9.2",
"@types/node": "^16.9.6",
"mocha": "^9.1.1",

@@ -48,0 +48,0 @@ "typedoc": "^0.22.4",

@@ -1,11 +0,11 @@

# SCRU-160: Sortable, Clock and Random number-based Unique identifier
# SCRU160: Sortable, Clock and Random number-based Unique identifier
SCRU-160 ID is yet another attempt to supersede [UUID] in the use cases that
need decentralized, globally unique time-ordered identifiers. SCRU-160 is
inspired by [ULID] and [KSUID] and has the following features:
SCRU160 ID is yet another attempt to supersede [UUID] in the use cases that need
decentralized, globally unique time-ordered identifiers. SCRU160 is inspired by
[ULID] and [KSUID] and has the following features:
- 160-bit length
- 160-bit feature-rich worry-free design suitable for general purposes
- Sortable by generation time (in binary and in text)
- Two case-insensitive encodings: 32-character base32hex and 40-character hex
- More than 32,768 unique, time-ordered but unpredictable IDs per millisecond
- Case-insensitive, highly portable encodings: 32-char base32hex and 40-char hex
- More than 32,000 unique, time-ordered but unpredictable IDs per millisecond
- Nearly 111-bit randomness for collision resistance

@@ -23,49 +23,9 @@

See [the specification] for further details.
[uuid]: https://en.wikipedia.org/wiki/Universally_unique_identifier
[ulid]: https://github.com/ulid/spec
[ksuid]: https://github.com/segmentio/ksuid
[the specification]: https://github.com/scru160/spec
## Binary Layout and Byte Order
A SCRU-160 ID is an 160-bit object that consists of the following four fields:
| Bit # | Field | Data Type |
| ------------ | --------- | ----------------------------------- |
| Msb 0 - 47 | timestamp | 48-bit unsigned integer, big-endian |
| Msb 48 - 63 | counter | 16-bit unsigned integer, big-endian |
| Msb 64 - 79 | random16 | 16-bit unsigned integer, big-endian |
| Msb 80 - 159 | random80 | 80-bit unsigned integer, big-endian |
- `timestamp` - Unix time in milliseconds
- `counter` - Reset to a 15-bit random number when `timestamp` changes;
incremented by one for each new ID generated within the same `timestamp` (a
different implementation may reset it to a smaller random number or zero to
accommodate more IDs per millisecond)
- `random16` - Random number (documented separately from `random80` for future
expansion)
- `random80` - Random number
Cryptographically secure random number generators are employed if possible.
## Encodings
The _base32hex_ encoding as defined in [RFC 4648] is used by default to produce
a 32-character textual representation consisting of `[0-9A-V]`.
```javascript
scru160(); // e.g. "05TUIM8J8SU9O6P30I56PP49PI0RGNPM"
```
Alternatively, hexadecimal encoding can be used to produce a 40-character hex
string that looks like the commonly seen SHA-1 hashes.
```javascript
scru160f(); // e.g. "017be95b2d6042db903a19a0974182ec7445188a"
```
The base32hex representations and hex representations cannot be mixed when
SCRU-160 IDs need to be lexicographically sortable.
[rfc 4648]: https://datatracker.ietf.org/doc/html/rfc4648
## License

@@ -72,0 +32,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc