How to use the libsodium-wrappers.ready function in libsodium-wrappers

To help you get started, we’ve selected a few libsodium-wrappers examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sjudson / paseto.js / lib / protocol / V2.js View on Github external
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);
github paragonie / sodium-plus / lib / backend / libsodium-wrappers.js View on Github external
static async init() {
        await _sodium.ready;
        return new LibsodiumWrappersBackend(_sodium);
    }
github ecadlabs / taquito / packages / taquito-signer / src / ed-key.ts View on Github external
async publicKeyHash(): Promise {
    await this.isInit;
    await sodium.ready;
    return b58cencode(sodium.crypto_generichash(20, new Uint8Array(this._publicKey)), prefix.tz1);
  }
github blinksocks / blinksocks / lib / presets / ss-aead-cipher.js View on Github external
static async onCache() {
    const _sodium = require('libsodium-wrappers');

    await _sodium.ready;

    if (!libsodium) {
      libsodium = _sodium;
    }
  }
github samuelmaddock / metastream / packages / metastream-app / src / platform / web / identity.ts View on Github external
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'
github transmute-industries / transmute / packages / transmute-crypto / src / TransmuteSodium / index.ts View on Github external
export const getSodium = async () => {
  await _sodium.ready
  const sodium = _sodium
  return sodium
}
github sjudson / paseto.js / lib / key / symmetric.js View on Github external
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();
  });
}
github whs / ipfs-encrypted-share / src / Download.js View on Github external
componentDidMount() {
		this.fetchMetadata();
		sodium.ready.then(() => {
			this.setState({ sodiumReady: true });
		});
	}