How to use ecdsa-sig-formatter - 8 common examples

To help you get started, we’ve selected a few ecdsa-sig-formatter 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 blockstack / jsontokens-js / src / cryptoClients / secp256k1.ts View on Github external
// make sure the required parameters are provided
    if (!(signingInputHash && rawPrivateKey)) {
      throw new MissingParametersError(
        'a signing input hash and private key are all required')
    }
    // prepare the private key
    const privateKeyObject = SECP256K1Client.loadPrivateKey(rawPrivateKey)
    // calculate the signature
    const signatureObject = privateKeyObject.sign(signingInputHash)
    const derSignature = Buffer.from(signatureObject.toDER())

    if (format === 'der') {
      return derSignature.toString('hex')
    } else if (format === 'jose') {
      // return the JOSE-formatted signature
      return derToJose(derSignature, 'ES256')
    } else {
      throw Error('Invalid signature format')
    }
  }
github blockstack / jsontokens-js / src / cryptoClients / secp256k1.ts View on Github external
static loadSignature(joseSignature: string | Buffer) {
    // create and return the DER-formatted signature buffer
    return joseToDer(joseSignature, 'ES256')
  }
github jwtk / njwt / lib / jwt.js View on Github external
var signature;
  var cryptoAlgName = enums.algCryptoMap[algorithm];
  var signingType = enums.algTypeMap[algorithm];

  if (!cryptoAlgName) {
    throw new errors.UnsupportedSigningAlgorithmJwtError();
  }

  if (signingType === 'hmac') {
    buffer = crypto.createHmac(cryptoAlgName, cryptoInput).update(payload).digest();
  } else {
    buffer = crypto.createSign(cryptoAlgName).update(payload).sign(cryptoInput);
  }

  if (helpers.isECDSA(algorithm)) {
    signature = ecdsaSigFormatter.derToJose(buffer, algorithm);
  } else {
    signature = helpers.base64urlEncode(buffer);
  }

  return signature;
};
github brianloveswords / node-jwa / index.js View on Github external
return function sign() {
    var signature = inner.apply(null, arguments);
    signature = formatEcdsa.derToJose(signature, 'ES' + bits);
    return signature;
  };
}
github Azure / dev-spaces / actions / add-review-url / node_modules / jwa / index.js View on Github external
return function sign() {
    var signature = inner.apply(null, arguments);
    signature = formatEcdsa.derToJose(signature, 'ES' + bits);
    return signature;
  };
}
github brianloveswords / node-jwa / index.js View on Github external
return function verify(thing, signature, publicKey) {
    signature = formatEcdsa.joseToDer(signature, 'ES' + bits).toString('base64');
    var result = inner(thing, signature, publicKey);
    return result;
  };
}
github Azure / dev-spaces / actions / add-review-url / node_modules / jwa / index.js View on Github external
return function verify(thing, signature, publicKey) {
    signature = formatEcdsa.joseToDer(signature, 'ES' + bits).toString('base64');
    var result = inner(thing, signature, publicKey);
    return result;
  };
}
github jwtk / njwt / lib / verifier.js View on Github external
var verified, digest;

  if (cryptoAlgName === 'none') {
    verified = true;
  } else if (signingType === 'hmac') {
    digest = crypto.createHmac(cryptoAlgName, this.signingKey)
      .update(digstInput)
      .digest('base64');
    verified = signature === digest;
  } else {
    var unescapedSignature;
    var signatureType = undefined;

    if (helpers.isECDSA(header.alg)) {
      try {
        unescapedSignature = ecdsaSigFormatter.joseToDer(signature, header.alg);
      } catch (err) {
        return done(new errors.SignatureMismatchJwtParseError(jwtString, header, body, err));
      }
    } else {
      signatureType = 'base64';
      unescapedSignature = helpers.base64urlUnescape(signature);
    }

    verified = crypto.createVerify(cryptoAlgName)
      .update(digstInput)
      .verify(this.signingKey, unescapedSignature, signatureType);
  }

  var newJwt = new Jwt(body, false);

  newJwt.toString = function () {

ecdsa-sig-formatter

Translate ECDSA signatures between ASN.1/DER and JOSE-style concatenation

Apache-2.0
Latest version published 6 years ago

Package Health Score

65 / 100
Full package analysis