Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bitcore-payment-protocol

Package Overview
Dependencies
Maintainers
4
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bitcore-payment-protocol - npm Package Compare versions

Comparing version 1.5.0 to 1.6.0

38

lib/common.js

@@ -16,5 +16,6 @@ 'use strict';

// BIP 70 - payment protocol
function PaymentProtocol() {
function PaymentProtocol(currency) {
this.messageType = null;
this.message = null;
this.currency = currency || 'BTC';
}

@@ -25,6 +26,20 @@

PaymentProtocol.PAYMENT_ACK_MAX_SIZE = 60000;
PaymentProtocol.PAYMENT_REQUEST_CONTENT_TYPE = 'application/bitcoin-paymentrequest';
PaymentProtocol.PAYMENT_CONTENT_TYPE = 'application/bitcoin-payment';
PaymentProtocol.PAYMENT_ACK_CONTENT_TYPE = 'application/bitcoin-paymentack';
PaymentProtocol.JSON_PAYMENT_REQUEST_CONTENT_TYPE = 'application/payment-request';
PaymentProtocol.JSON_PAYMENT_CONTENT_TYPE = 'application/payment';
PaymentProtocol.JSON_PAYMENT_ACK_CONTENT_TYPE = 'application/payment-ack';
PaymentProtocol.LEGACY_PAYMENT = {
BTC: {},
BCH: {}
};
PaymentProtocol.LEGACY_PAYMENT.BTC.REQUEST_CONTENT_TYPE = 'application/bitcoin-paymentrequest';
PaymentProtocol.LEGACY_PAYMENT.BTC.CONTENT_TYPE = 'application/bitcoin-payment';
PaymentProtocol.LEGACY_PAYMENT.BTC.ACK_CONTENT_TYPE = 'application/bitcoin-paymentack';
PaymentProtocol.LEGACY_PAYMENT.BCH.REQUEST_CONTENT_TYPE = 'application/bitcoincash-paymentrequest';
PaymentProtocol.LEGACY_PAYMENT.BCH.CONTENT_TYPE = 'application/bitcoincash-payment';
PaymentProtocol.LEGACY_PAYMENT.BCH.ACK_CONTENT_TYPE = 'application/bitcoincash-paymentack';
// https://www.google.com/search?q=signatureAlgorithm+1.2.840.113549.1.1.1

@@ -218,5 +233,6 @@ // http://msdn.microsoft.com/en-us/library/windows/desktop/aa379057(v=vs.85).aspx

PaymentProtocol.prototype.makePaymentRequest = function(obj) {
PaymentProtocol.prototype.makePaymentRequest = function(obj, currency) {
this.messageType = 'PaymentRequest';
this.message = new PaymentProtocol.PaymentRequest();
this.currency = this.currency || currency || 'BTC';
this.setObj(obj);

@@ -226,5 +242,6 @@ return this;

PaymentProtocol.prototype.makePayment = function(obj) {
PaymentProtocol.prototype.makePayment = function(obj, currency) {
this.messageType = 'Payment';
this.message = new PaymentProtocol.Payment();
this.currency = this.currency || currency || 'BTC';
this.setObj(obj);

@@ -234,5 +251,6 @@ return this;

PaymentProtocol.prototype.makePaymentACK = function(obj) {
PaymentProtocol.prototype.makePaymentACK = function(obj, currency) {
this.messageType = 'PaymentACK';
this.message = new PaymentProtocol.PaymentACK();
this.currency = currency || 'BTC';
this.setObj(obj);

@@ -265,11 +283,11 @@ return this;

if (this.messageType === 'PaymentRequest') {
return PaymentProtocol.PAYMENT_REQUEST_CONTENT_TYPE;
return PaymentProtocol.LEGACY_PAYMENT[this.currency].REQUEST_CONTENT_TYPE;
}
if (this.messageType === 'Payment') {
return PaymentProtocol.PAYMENT_CONTENT_TYPE;
return PaymentProtocol.LEGACY_PAYMENT[this.currency].CONTENT_TYPE;
}
if (this.messageType === 'PaymentACK') {
return PaymentProtocol.PAYMENT_ACK_CONTENT_TYPE;
return PaymentProtocol.LEGACY_PAYMENT[this.currency].ACK_CONTENT_TYPE;
}

@@ -276,0 +294,0 @@

{
"name": "bitcore-payment-protocol",
"version": "1.5.0",
"version": "1.6.0",
"description": "Payment Protocol (BIP70 and related) support for bitcore",

@@ -5,0 +5,0 @@ "author": "BitPay <dev@bitpay.com>",

@@ -224,3 +224,3 @@ 'use strict';

var contentType = ack.getContentType();
contentType.should.equal(PaymentProtocol.PAYMENT_ACK_CONTENT_TYPE);
contentType.should.equal(PaymentProtocol.LEGACY_PAYMENT['BTC'].ACK_CONTENT_TYPE);
var serialized = ack.serialize();

@@ -234,2 +234,14 @@ serialized.length.should.be.greaterThan(0);

it('makePaymentACK BCH', function () {
var payment = new PaymentProtocol.Payment();
var ack = new PaymentProtocol().makePaymentACK(null, 'BCH');
ack.set('payment', payment);
ack.set('memo', 'this is a memo');
ack.get('memo').should.equal('this is a memo');
var valid = ack.isValidSize();
valid.should.equal(true);
var contentType = ack.getContentType();
contentType.should.equal(PaymentProtocol.LEGACY_PAYMENT['BCH'].ACK_CONTENT_TYPE);
});
});

@@ -345,3 +357,3 @@

var contentType = paypro.getContentType();
contentType.should.equal(PaymentProtocol.PAYMENT_REQUEST_CONTENT_TYPE);
contentType.should.equal(PaymentProtocol.LEGACY_PAYMENT['BTC'].REQUEST_CONTENT_TYPE);
valid.should.equal(true);

@@ -351,2 +363,18 @@ buf.length.should.be.greaterThan(0);

it('should serialize a BCH PaymentRequest and not fail', function() {
var pd = new PaymentProtocol.PaymentDetails();
pd.set('time', 0);
var pdbuf = pd.toBuffer();
var paypro = new PaymentProtocol('BCH');
paypro.makePaymentRequest();
paypro.set('serialized_payment_details', pdbuf);
var buf = paypro.serializeForSig();
var valid = paypro.isValidSize();
var contentType = paypro.getContentType();
contentType.should.equal(PaymentProtocol.LEGACY_PAYMENT['BCH'].REQUEST_CONTENT_TYPE);
valid.should.equal(true);
buf.length.should.be.greaterThan(0);
});
});

@@ -353,0 +381,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc