@sharering/signification v1.0.4
signification
A utility tool to generate structured string that can be JSON-schema validated, signed and verified, and optionally made expired with totp.
Installation
npm install @sharering/signification
// or yarn
yarn add @sharering/signification
Usage
Build a structured string
import { DocumentSchema, construct } from "@sharering/signification";
interface Data {
firstName: string;
lastName: string;
dob: string;
}
const schema: DocumentSchema<"string", Data> = {
output: {
type: "string",
delimiter: "|"
},
version: "ABC123",
fields: {
type: "object",
properties: {
firstName: {
type: "string",
$data: "user.firstName"
},
lastName: {
type: "string",
$data: "user.lastName"
},
dob: {
type: "string",
$data: "user.dob",
format: "date",
pattern: "DD/MM/YYYY"
}
},
required: ["firstName", "lastName", "dob"],
additionalProperties: false
}
};
const data = {
firstName: "John",
lastName: "Doe",
dob: dayjs.utc("1990-03-04", "YYYY-MM-DD").toISOString() // use dayjs and its plugins
};
const output = construct(schema, data);
Parse from a structured string
import { construct } from "@sharering/signification";
destruct(schema, "ABC123|John|Doe|04/03/1990");
Sign
import elliptic from "elliptic";
import { createSign } from "@sharering/signification";
const secp256k1 = new elliptic.ec("secp256k1");
// create a random secp256k1 keypair
const keypair = secp256k1.genKeyPair();
const sign = createSign({
privateKey: keypair.getPrivate("hex"),
delimiter: "|",
expiration: { enabled: true }
});
sign.update("chunk1");
sign.update("chunk2");
// ...
sign.digest(); // output { signature, data }
Verify
import { createVerify } from "@sharering/signification";
const verify = createVerify({
publicKey: secp256k1.keyFromPrivate(privateKey).getPublic(true, "hex"),
delimiter: "|",
expiration: { enabled: true, time: 60 } // time in seconds
});
verify.update(signed.data); // data from the sign.digest()
verify.digest(); // { valid, data }
Test
yarn test
Developing
git clone http://github.com/ShareRing/signification.git
cd signification
yarn
Credits
License
MIT License
Copyright (c) 2025 ShareRing
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.