Javascript e-signature library for digitally signing and verifying files on EVM-based blockchains using the OpenSig standard. See https://opensig.net/about.
Also supports public and private notarisation to the blockchain.
<script src="https://cdn.jsdelivr.net/gh/opensig/opensig-js/dist/opensig-js.js"></script>
npm install opensig-js
// Construct a blockchain provider (see opensig.providers)
const provider = new window.opensig.providers.MetamaskProvider({
chainId: 1,
name: "Ethereum",
contract: "0x73eF7A3643aCbC3D616Bd5f7Ee5153Aa5f14DB30",
blockTime: 12000,
creationBlock: 16764681
});
// Construct an OpenSig Document object from a File
// (or construct one from a hash - see Document Class below)
const myDoc = new window.opensig.File(provider, new File('./myfile.txt'));
// Verify signatures on the blockchain
const signatures = await myDoc.verify();
signatures.forEach(sig => console.log(sig.time, sig.signatory, sig.data));
// Sign using Metamask
const signData = {
type: 'string',
encrypted: true,
content: 'some data'
};
const result = await myDoc.sign(signData);
console.log(result.txHash, result.signatory, result.signature);
const receipt = await result.confirmationInformer;
console.log('signature published successfully', receipt));
import * as opensig from 'opensig-js';
import MetaMaskSDK from '@metamask/sdk';
const MMSDK = new MetaMaskSDK(options);
const ethereumProvider = MMSDK.getProvider();
// Construct a blockchain provider (see opensig.providers)
const provider = new opensig.providers.MetamaskProvider({
chainId: 1,
name: "Ethereum",
contract: "0x73eF7A3643aCbC3D616Bd5f7Ee5153Aa5f14DB30",
blockTime: 12000,
creationBlock: 16764681,
ethereum: ethereumProvider,
});
...
The Document
class is an alternative to the File
class. It takes a pre-determined document hash instead of a file.
const myDocHash = ...
const myDoc = new opensig.Document(provider, myDocHash);
const signatures = await myDoc.verify();
...
Blockchain providers publish sign transactions to the blockchain and query the blockchain for signatures using whatever transport protocol is appropriate.
Implement your own or use one of the bundled providers. See src/providers.js for the BlockchainProvider interface.
OpenSig is bundled with 3 types of provider accessed via opensig.providers
. At this time all three use Metamask to sign signature transactions but use different services to query the blockchain for signatures:
MetamaskProvider - Uses the local Metamask wallet to query the blockchain for signatures and to sign transactions.
HTTPProvider - Uses a web3 http provider to query the blockchain for signatures. Uses the local Metamask wallet to sign and publish transactions.
AnkrProvider - Uses the Ankr network to query the blockchain for signatures. Uses the local Metamask wallet to sign and publish transactions.
A BlockchainProvider
takes the following parameters:
chainId
- blockchain's chain idname
- labelcontract
- address of that blockchain's Registry Contract (see https://opensig.net/about#contracts)blockTime
- the network block time in mscreationBlock
- the registry contract's creation block number (minimises search window when querying for signatures)
MetamaskProvider
extends BlockchainProvider
and takes in addition:
ethereum
- optional Metamask ethereum provider. Defaults towindow.ethereum
HTTPProvider
extends MetamaskProvider
and takes in addition:
url
- url of the http service, e.g. Infura
AnkrProvider
extends MetamaskProvider
and takes in addition:
endpoint
- url of the Ankr network endpoint, e.g.https://rpc.ankr.com/multichain