How to use the bitcore-lib.PublicKey function in bitcore-lib

To help you get started, we’ve selected a few bitcore-lib 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 bitpay / bwdb / test / utils.unit.js View on Github external
}, function(err, res) {
        if (err) {
          return done(err);
        }
        var privKey = res.toString('hex');
        var addressFromCompressedPubKey = new bitcore.PublicKey(pubkey, {network: 'testnet'}).toAddress().toString();
        var addressFromRawPrivateKey = new bitcore.PrivateKey(privKey, 'testnet').toAddress().toString();
        var actual = '4a9f87c9384a60d1fe95f5cc6c94e54d76457798b687639fb83f2d0cf365ad7b';
        privKey.should.equal(actual);
        addressFromCompressedPubKey.should.equal(addressFromRawPrivateKey);
        done();
      });
    });
github timbowhite / botbouncer / test / mockreq.js View on Github external
deriveAddressFromHdPubKey = function(hdpubkey, idx, network){
        var hdpk = bitcorelib.HDPublicKey(hdpubkey);
        var publicKey = hdpk.derive(0).derive(idx).toObject().publicKey;
        var pk = new bitcorelib.PublicKey(publicKey);
        var address = pk.toAddress(network);
        return address.toString()
    },
    getBitcoinZombieAddresses = function(){
github poetapp / poet-js / src / Common.ts View on Github external
export function verifies(hashFn: any, encoded: Buffer, signature: string, publicKey: string) {
  if (!encoded || !signature || !publicKey) {
    return false
  }

  if (!verify(
      new bitcore.PublicKey(publicKey),
      new Buffer(signature, 'hex'),
      hashFn(encoded)))
  {
    console.log('Signature is invalid')
    return false
  }
  return true
}
github bitpay / bitcore / packages / bitcore-node / src / utils / auth.ts View on Github external
export function verifyRequestSignature(params: VerificationPayload): boolean {
  const { message, pubKey, signature } = params;
  const pub = new bitcoreLib.PublicKey(pubKey).toBuffer();
  const messageHash = bitcoreLib.crypto.Hash.sha256sha256(Buffer.from(message));
  if (typeof signature === 'string') {
    return secp256k1.verify(messageHash, Buffer.from(signature, 'hex'), pub);
  } else {
    throw new Error('Signature must exist');
  }
}
github BIUT-Block / biutjs-crypto / src / index.js View on Github external
encryptWithPublicKey (publicKey, message) {
    if (!_encryptWithPublicKeyEciesCache.has(publicKey)) {
      let alice = ECIES()
        .privateKey(_encryptWithPublicKeyDefaultKey)
        .publicKey(new bitcore.PublicKey(publicKey))
      _encryptWithPublicKeyEciesCache.set(
        publicKey,
        alice
      )
    }
    let alice = _encryptWithPublicKeyEciesCache.get(publicKey)
    let encrypted = alice.encrypt(message)
    let ret = encrypted.toString('hex')
    return ret
  }
  decryptWithPrivateKey (privateKey, encrypted) {
github bitpay / bwdb / scripts / verify_and_extract.js View on Github external
}, function(err, privKey) {
        if(err) {
          setImmediate(function() {
            next(err);
          });
        }
        var recordPubkey;
        try {
          recordPubkey = new bitcore.PublicKey(record.pubKey);
        } catch(e) {
          process.stdout.write('ERROR: invalid public key in json export: ' + record.pubKey + '\n');
          setImmediate(function() {
            next();
          });
        }
        var privateKey = bitcore.PrivateKey.fromObject({
          bn: privKey,
          compressed: recordPubkey.compressed,
          network: livenet
        });
        var pubKey = privateKey.toPublicKey();
        if (recordPubkey.toString('hex') !== pubKey.toString('hex')) {
          process.stdout.write('public key: ' + record.pubKey + ' in json export did not match: ' + pubKey + '\n');
          next();
        }
github miller46 / digital-identity / js / crypto.js View on Github external
function encrypt(publicKey, privateKey, message) {
    var privateKey = new bitcore.PrivateKey(privateKey);
    var alice = ECIES().privateKey(privateKey).publicKey(new bitcore.PublicKey(publicKey));
    var encrypted = alice.encrypt(message);
    return encrypted.toString('hex');
}
github bitpay / bitcore-channel / lib / consumer.js View on Github external
/**
   * @type number
   * @desc The expiration date for the channel, in seconds since UNIX epoch
   */
  this.expires = opts.expires || Math.round(new Date().getTime() / 1000) + ONE_DAY;

  /**
   * @type bitcore.PrivateKey
   * @desc This is the key used for the 2-of-2 locking of funds
   */
  this.commitmentKey = new PrivateKey(opts.commitmentKey);

  /**
   * @type {bitcore.PublicKey}
   */
  this.providerPublicKey = new PublicKey(opts.providerPublicKey);

  /**
   * @type {bitcore.Address|string}
   * @desc The address where the server will be paid.
   */
  this.providerAddress = opts.providerAddress ? new Address(opts.providerAddress) : this.providerPublicKey.toAddress();

  /**
   * @type bitcore.PrivateKey
   * @desc A private key for funding the channel. An alternative implementation could
   * provide a list of unspent outputs and the keys needed to sign the outputs
   */
  $.checkArgument(opts.fundingKey instanceof PrivateKey, 'fundingKey is expected to be a PrivateKey');
  this.fundingKey = opts.fundingKey;

  /**