How to use the libsodium-wrappers.crypto_sign_detached 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
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);

    // format

    const token = header.toString('utf-8') + utils.toB64URLSafe(Buffer.concat([ data, signature ]));

    return (!Buffer.byteLength(footer))
      ? done(null, token)
      : done(null, token + '.' + utils.toB64URLSafe(footer));
  });
}
github airgap-it / airgap-coin-lib / src / protocols / tezos / TezosProtocol.ts View on Github external
public async signWithPrivateKey(privateKey: Buffer, transaction: RawTezosTransaction): Promise {
    await sodium.ready

    const watermark: string = '03'
    const watermarkedForgedOperationBytesHex: string = watermark + transaction.binaryTransaction
    const watermarkedForgedOperationBytes: Buffer = Buffer.from(watermarkedForgedOperationBytesHex, 'hex')
    const hashedWatermarkedOpBytes: Buffer = sodium.crypto_generichash(32, watermarkedForgedOperationBytes)

    const opSignature: Buffer = sodium.crypto_sign_detached(hashedWatermarkedOpBytes, privateKey)
    const signedOpBytes: Buffer = Buffer.concat([Buffer.from(transaction.binaryTransaction, 'hex'), Buffer.from(opSignature)])

    return signedOpBytes.toString('hex')
  }
github ecadlabs / taquito / packages / taquito-signer / src / ed-key.ts View on Github external
async sign(bytes: string, bytesHash: Uint8Array) {
    await this.isInit;
    const signature = sodium.crypto_sign_detached(
      new Uint8Array(bytesHash),
      new Uint8Array(this._key)
    );
    const signatureBuffer = toBuffer(signature);
    const sbytes = bytes + buf2hex(signatureBuffer);

    return {
      bytes,
      sig: b58cencode(signature, prefix.sig),
      prefixSig: b58cencode(signature, prefix.edsig),
      sbytes,
    };
  }
github TankerHQ / sdk-js / packages / crypto / src / tcrypto.js View on Github external
export function sign(data: Uint8Array, privateKey: Uint8Array): Uint8Array {
  return sodium.crypto_sign_detached(data, privateKey);
}
github Picolab / pico-engine / packages / pico-engine-core / src / modules / indy.js View on Github external
], async (ctx, args) => {
    const chann = await core.db.getChannelSecrets(args.eci)
    const key = bs58.decode(chann.sovrin.secret.indyPrivate)
    return b64url(sodium.crypto_sign_detached(Uint8Array.from(args.bytes), key))
  })
github ZeusWPI / MOZAIC / client / src / networking / Handshaker.ts View on Github external
private sendSignedMessage(data: Uint8Array) {
        const key = this.connection.secretKey;
        const signature = sodium.crypto_sign_detached(data, key);
        const encodedMessage = proto.SignedMessage.encode({
            data,
            signature,
        }).finish();
        this.transport.sendFrame(encodedMessage);
    }
}