示例#1
0
文件: ripple.js 项目: dabibbit/swim
module.exports.verifySignature = function (signature, message, address) {
  signature = Buffer.concat([
      new Buffer((4 - signature.length % 4) % 4).fill(0),
      signature
      ]);

  var hex = crypto.Hash('sha256').update(message).digest().toString('hex');
  var bits = sjcl.codec.hex.toBits(hex);

  var sig = sjcl.codec.hex.toBits(signature.toString('hex'));

  var pubKey = null;

  try {
    pubKey = sjcl.ecc.ecdsa.publicKey.recoverFromSignature(bits, sig);
  } catch (error) {
  }

  if (pubKey) {
    var k = ripple.Seed.from_json(Array(32 + 1).join('0')).get_key();
    k._pubkey = pubKey;
    return k.get_address().to_json() === address;
  } else {
    return false;
  }
};
示例#2
0
exports.generateHash = function (data, callback) {

	var hash = new Buffer(0);

	// Hash received data
	crypto.Hash('sha1').on('readable', function () {

		var chunk = this.read() || new Buffer(0);

		// Append data to the hash
		hash = exports.buffer(hash, chunk, hash.length + chunk.length);
	}).on('end', function () {
		callback(hash);
	}).end(data);
};
示例#3
0
utils.generateHash = function (data, encoding, callback) {

	var hash = new Buffer(0);

	// Hash received data
	crypto.Hash('sha1').on('readable', function () {

		var chunk = this.read() || new Buffer(0);

		// Append data to the hash
		hash = Buffer.concat([hash, chunk], hash.length + chunk.length);
	}).on('end', function () {
		callback(hash.toString(encoding));
	}).end(data);
};
示例#4
0
文件: ripple.js 项目: dabibbit/swim
_class.prototype.sign = function (message) {
  var key = this._key;

  var hex = crypto.Hash('sha256').update(message).digest().toString('hex');
  var bits = sjcl.codec.hex.toBits(hex);

  var sig = key.signWithRecoverablePublicKey(bits);

  var buffer = new Buffer(sjcl.codec.bytes.fromBits(sig));

  while (buffer.length > 65 && buffer[0] === 0) {
    buffer = buffer.slice(1);
  }

  return buffer;
};
示例#5
0
	// Generate a new session container
	static generateSession(router) {

		const hash = crypto.Hash('sha1');
		const sessionHashLength = 32; // Length of session hash buffer
		const sessionIdLength = 16; // Length of session id buffer

		return new Promise((resolve, reject) => {

			// Generate random session id
			crypto.randomBytes(sessionHashLength, (error, id) => {
				if (error) {
					reject(error);
				} else {
					resolve({
						container: {},
						hash: hash.update(id).digest('hex'),
						id: id.slice(sessionIdLength).toString('hex'),
						timeout: router._options.session.timeout
					});
				}
			});
		});
	}
示例#6
0
  () => h3.update('foo'),
  {
    code: 'ERR_CRYPTO_HASH_FINALIZED',
    type: Error
  });

common.expectsError(
  () => crypto.createHash('sha256').digest('ucs2'),
  {
    code: 'ERR_CRYPTO_HASH_DIGEST_NO_UTF16',
    type: Error
  }
);

common.expectsError(
  () => crypto.createHash(),
  {
    code: 'ERR_INVALID_ARG_TYPE',
    type: TypeError,
    message: 'The "algorithm" argument must be of type string. ' +
             'Received type undefined'
  }
);

{
  const Hash = crypto.Hash;
  const instance = crypto.Hash('sha256');
  assert(instance instanceof Hash, 'Hash is expected to return a new instance' +
                                   ' when called without `new`');
}