@jeswr/rdfjs-sign
v1.3.1
Published
A set of utilities for signing RDF. :warning: Not for production use :warning:
Downloads
146
Maintainers
Readme
RDFJS Sign
A set of utilities for signing RDF. :warning: Not for production use :warning:
Usage
import { DataFactory } from 'n3';
import {
generateKeyPair, exportKey, signQuads, verifyQuads, importKey,
} from '@jeswr/rdfjs-sign';
const { quad, namedNode } = DataFactory;
const q1 = quad(namedNode('http://example.org/s'), namedNode('http://example.org/p'), namedNode('http://example.org/o1'));
const q2 = quad(namedNode('http://example.org/s'), namedNode('http://example.org/p'), namedNode('http://example.org/o2'));
const q3 = quad(namedNode('http://example.org/s'), namedNode('http://example.org/p'), namedNode('http://example.org/o3'));
const keyPair = await generateKeyPair();
const signature = await signQuads([q1, q2], keyPair.privateKey);
// true
await verifyQuads([q2, q1], signature, keyPair.publicKey);
// false
await verifyQuads([q1, q3], signature, keyPair.publicKey);
// true
await verifyQuads([q2, q1], signature, await importKey(await exportKey(keyPair.publicKey)));
CLI Usage
To sign data with a private key
npx @jeswr/rdfjs-sign --private-key ./key.json --hash "abc123"
To sign a hash with a private key
npx @jeswr/rdfjs-sign --private-key ./key.json --data ./data.ttl
License
©2024–present Jesse Wright, MIT License.
This is based on code written in this prototype in collaboration with Ruben Dedecker and Wout Slabbinck.