<commit_before>'use strict';

var should = require('chai').should();
var bitcore = require('../..');
var BN = bitcore.crypto.BN;
var Signature = bitcore.crypto.Signature;
var JSUtil = bitcore.util.js;
var Interpreter = bitcore.Script.Interpreter;

var sig_canonical = require('../data/bitcoind/sig_canonical');
var sig_noncanonical = require('../data/bitcoind/sig_noncanonical');

describe('Signature', function() {

  it('should make a blank signature', function() {
    var sig = new Signature();
    should.exist(sig);
  });

  it('should work with conveniently setting r, s', function() {
    var r = new BN();
    var s = new BN();
    var sig = new Signature(r, s);
    should.exist(sig);
    sig.r.toString().should.equal(r.toString());
    sig.s.toString().should.equal(s.toString());
  });

  describe('#set', function() {

    it('should set compressed', function() {
      should.exist(Signature().set({
        compressed: true
      }));
    });

  });

  describe('#fromCompact', function() {

    it('should create a signature from a compressed signature', function() {
      var blank = new Buffer(32);
      blank.fill(0);
      var compressed = Buffer.concat([
        new Buffer([0 + 27 + 4]),
        blank,
        blank
      ]);
      var sig = Signature.fromCompact(compressed);
      sig.r.cmp(BN.Zero).should.equal(0);
      sig.s.cmp(BN.Zero).should.equal(0);
    });

  });

  describe('#fromDER', function() {

    var buf = new Buffer('3044022075fc517e541bd54769c080b64397e32161c850f6c1b2b67a5c433affbb3e62770220729e85cc46ffab881065ec07694220e71d4df9b2b8c8fd12c3122cf3a5efbcf2', 'hex');

    it('should parse this DER format signature', function() {
      var sig = Signature.fromDER(buf);
      sig.r.toBuffer({
        size: 32
      }).toString('hex').should.equal('75fc517e541bd54769c080b64397e32161c850f6c1b2b67a5c433affbb3e6277');
      sig.s.toBuffer({
        size: 32
      }).toString('hex').should.equal('729e85cc46ffab881065ec07694220e71d4df9b2b8c8fd12c3122cf3a5efbcf2');
    });

  });

  describe('#fromString', function() {

    var buf = new Buffer('3044022075fc517e541bd54769c080b64397e32161c850f6c1b2b67a5c433affbb3e62770220729e85cc46ffab881065ec07694220e71d4df9b2b8c8fd12c3122cf3a5efbcf2', 'hex');

    it('should parse this DER format signature in hex', function() {
      var sig = Signature.fromString(buf.toString('hex'));<commit_msg>Add test with uncompressed pubkey compact signature.<commit_after>'use strict';

var should = require('chai').should();
var bitcore = require('../..');
var BN = bitcore.crypto.BN;
var Signature = bitcore.crypto.Signature;
var JSUtil = bitcore.util.js;
var Interpreter = bitcore.Script.Interpreter;

var sig_canonical = require('../data/bitcoind/sig_canonical');
var sig_noncanonical = require('../data/bitcoind/sig_noncanonical');

describe('Signature', function() {

  it('should make a blank signature', function() {
    var sig = new Signature();
    should.exist(sig);
  });

  it('should work with conveniently setting r, s', function() {
    var r = new BN();
    var s = new BN();
    var sig = new Signature(r, s);
    should.exist(sig);
    sig.r.toString().should.equal(r.toString());
    sig.s.toString().should.equal(s.toString());
  });

  describe('#set', function() {

    it('should set compressed', function() {
      should.exist(Signature().set({
        compressed: true
      }));
    });

  });

  describe('#fromCompact', function() {

    it('should create a signature from a compressed signature', function() {
      var blank = new Buffer(32);
      blank.fill(0);
      var compressed = Buffer.concat([
        new Buffer([0 + 27 + 4]),
        blank,
        blank
      ]);
      var sig = Signature.fromCompact(compressed);
      sig.r.cmp(BN.Zero).should.equal(0);
      sig.s.cmp(BN.Zero).should.equal(0);
    });

    it('should create a signature from an uncompressed signature', function() {
      var uncompressed = '1c49f92a610fa934f45b3a01036055ebbe65a6b910e8c3cfbbb0b64f575' +
        '196f2fe18dc5a236d7883434cf48c11d56c804493dfe31b5a09a1a3cab378b2aac8c934';
      var sig = Signature.fromCompact(uncompressed);
      sig.r.toString('hex').should.equal('38a5e6d9a9fda73a2a8275413be68f408a1859173f07ae557be54ce1fdd5f3b1');
      sig.s.toString('hex').should.equal('21135fd5b20a73b09a7389910fe2b20f59b6fd0990c84169367db069cd6e3ea1');
    });

  });

  describe('#fromDER', function() {

    var buf = new Buffer('3044022075fc517e541bd54769c080b64397e32161c850f6c1b2b67a5c433affbb3e62770220729e85cc46ffab881065ec07694220e71d4df9b2b8c8fd12c3122cf3a5efbcf2', 'hex');

    it('should parse this DER format signature', function() {
      var sig = Signature.fromDER(buf);
      sig.r.toBuffer({
        size: 32
      }).toString('hex').should.equal('75fc517e541bd54769c080b64397e32161c850f6c1b2b67a5c433affbb3e6277');
      sig.s.toBuffer({
        size: 32
      }).toString('hex').should.equal('729e85cc46ffab881065ec07694220e71d4df9b2b8c8fd12c3122cf3a5efbcf2');
    });

  });

  describe('#fromString', function() {

    var buf = new Buffer('3044022075fc517e541bd54769c080b64397e32161c850f6c1b2b67a5c433affbb3e62770220729e85cc46ffab881065ec07694220e71d4df9b2b8c8fd12c3122cf3a5efbcf2', 'hex');

    it('should parse this DER format signature in hex', function() {
      var sig = Signature.fromString(buf.toString('hex'));
{'fraction_non_alphanumeric': 0.1400785487189078, 'fraction_numerical': 0.13390686366186647, 'mean_word_length': 3.9748837209302326, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6506247', 'n_tokens_mistral': 2315, 'n_tokens_neox': 1910, 'n_words': 315}