als-hidden-data-link
v1.0.0
Published
**als-hidden-data-link** is a Node.js library designed for embedding hidden numeric IDs or other data into messages using invisible characters. These hidden IDs can be used to retrieve associated data later, making it useful for scenarios where you need t
Downloads
3
Readme
als-hidden-data-link
als-hidden-data-link is a Node.js library designed for embedding hidden numeric IDs or other data into messages using invisible characters. These hidden IDs can be used to retrieve associated data later, making it useful for scenarios where you need to embed identifiers into text that will be transmitted via messaging platforms, such as WhatsApp or email.
Installation
To install the library, run the following command in your Node.js project:
npm install als-hidden-data-link
Usage
1. Import the Library
First, import the DataLinkManager
class from the library:
const DataLinkManager = require('als-hidden-data-link');
2. Initialize the DataLinkManager
You can initialize the DataLinkManager
with a maximum number of entries it can store. The default is 300, but you can set a custom value as needed.
const manager = new DataLinkManager(300);
3. Encrypting a Message
To embed a hidden numeric ID into a message, use the getMsg
method. This method takes a message and an associated ID, and it will return the message with the embedded ID.
const message = 'This is a secret message';
const userId = 'user123'; // This can be any data you want to associate
const encryptedMessage = manager.getMsg(message, userId);
console.log(encryptedMessage);
The encrypted message will contain invisible characters representing the numeric ID associated with the message.
4. Decrypting a Message
To retrieve the ID associated with an encrypted message, use the getData
method. This will extract the embedded ID from the message.
const decryptedId = manager.getData(encryptedMessage);
if (decryptedId) {
console.log(`The decrypted ID is: ${decryptedId}`);
} else {
console.log('No ID found in the message.');
}
5. Handling Maximum Entries
If the number of stored entries exceeds the maxN
limit, the class will automatically overwrite the oldest entry. For example, if you set maxN
to 2 and attempt to store three entries, the first entry will be replaced.
const manager = new DataLinkManager(2);
manager.getMsg('First message', 'id1');
manager.getMsg('Second message', 'id2');
const encryptedThird = manager.getMsg('Third message', 'id3'); // This will overwrite 'id1'
const retrievedId = manager.getData(encryptedThird);
console.log(`The decrypted ID is: ${retrievedId}`); // Should return 'id3'
6. Invalid Message Handling
If you attempt to decrypt a message that does not contain any embedded ID, the getData
method will return null
.
const invalidMessage = 'This message has no hidden ID';
const result = manager.getData(invalidMessage);
console.log(result); // Output: null
API Reference
new DataLinkManager(maxN)
maxN
: The maximum number of entries that theDataLinkManager
can store. Default is 300.- Returns: A new instance of
DataLinkManager
.
getMsg(message, data)
message
: The message in which to embed the ID.data
: The data to associate with the message.- Returns: The message with the hidden ID embedded in it.
getData(encryptedMessage)
encryptedMessage
: The message from which to extract the hidden ID.- Returns: The associated ID if found, or
null
if no ID is embedded.
Example
const DataLinkManager = require('als-hidden-data-link');
// Initialize the manager
const manager = new DataLinkManager();
// Encrypt a message with an ID
const message = 'Hello world!';
const encryptedMessage = manager.getMsg(message, 'myCustomId');
// Later, decrypt the message to retrieve the ID
const retrievedId = manager.getData(encryptedMessage);
console.log(`The retrieved ID is: ${retrievedId}`);