Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function sign(data, key, footer, cb) {
footer = footer || '';
const self = this;
const done = utils.ret(cb);
if (!(key.protocol() instanceof V2)) {
return done(new InvalidVersionError('The given key is not intended for this version of PASETO.'));
}
return sodium.ready.then(() => {
const header = utils.public(self);
[ data, footer ] = (utils.parse('utf-8'))(data, footer);
// sign
let payload;
try {
payload = utils.pae(header, data, footer);
} catch (ex) {
return done(ex);
}
const _signature = sodium.crypto_sign_detached(payload, key.raw());
const signature = Buffer.from(_signature);
static async init() {
await _sodium.ready;
return new LibsodiumWrappersBackend(_sodium);
}
async publicKeyHash(): Promise {
await this.isInit;
await sodium.ready;
return b58cencode(sodium.crypto_generichash(20, new Uint8Array(this._publicKey)), prefix.tz1);
}
static async onCache() {
const _sodium = require('libsodium-wrappers');
await _sodium.ready;
if (!libsodium) {
libsodium = _sodium;
}
}
export async function initIdentity(ephemeral: boolean = false) {
await sodium.ready
if (ephemeral) {
return keyPair()
}
let localKeyPair: KeyPair | undefined
{
const publicKey = localStorage.getItem(PUBKEY_PROP)
const privateKey = localStorage.getItem(SECKEY_PROP)
if (publicKey && privateKey) {
localKeyPair = {
publicKey: sodium.from_hex(publicKey),
privateKey: sodium.from_hex(privateKey),
keyType: 'curve25519'
export const getSodium = async () => {
await _sodium.ready
const sodium = _sodium
return sodium
}
function inject(rkey, cb) {
const self = this;
const done = utils.ret(cb);
if (!(rkey instanceof Buffer)) { return done(new TypeError('Raw key must be provided as a buffer')); }
return sodium.ready.then(() => {
self._key = rkey;
return done();
});
}
componentDidMount() {
this.fetchMetadata();
sodium.ready.then(() => {
this.setState({ sodiumReady: true });
});
}
const initSodium = async () => {
await sodiumWrappers.ready;
return sodiumWrappers;
};