diff --git a/browser/generate-trusted.sh b/browser/generate-trusted.sh index a712ead..b726bb8 100755 --- a/browser/generate-trusted.sh +++ b/browser/generate-trusted.sh @@ -14,10 +14,20 @@ pushd lib &> /dev/null sed -i '$s/,$//g' RootCerts.js -echo "module.exports = ["$'\n'"$(cat RootCerts.js)" > RootCerts.js +echo "var RootCerts = ["$'\n'"$(cat RootCerts.js)" > RootCerts.js echo "];" >> RootCerts.js sed -i 's/^"/+ "/g' RootCerts.js sed -i 's/^+ "-----B/"-----B/g' RootCerts.js +cat < RootCerts.js +// Use hash table for efficiency: +RootCerts = RootCerts.reduce(function(trusted, cert) { + cert = cert.replace(/\s+/g, ''); + trusted[cert] = true; + return trusted; +}, {}); +module.exports = RootCerts; +EOF + popd &> /dev/null diff --git a/lib/PayPro.js b/lib/PayPro.js index 1d972b1..3aa0079 100644 --- a/lib/PayPro.js +++ b/lib/PayPro.js @@ -3,14 +3,7 @@ var protobufjs = protobufjs || require('protobufjs/dist/ProtoBuf'); var Message = Message || require('./Message'); var KJUR = require('jsrsasign'); -var Trusted = require('./RootCerts'); - -// Use hash table for efficiency: -Trusted = Trusted.reduce(function(trusted, cert) { - cert = cert.replace(/\s+/g, ''); - trusted[cert] = true; - return trusted; -}, {}); +var RootCerts = require('./RootCerts'); // BIP 70 - payment protocol function PayPro() { @@ -227,7 +220,7 @@ PayPro.prototype.sign = function(key) { var trusted = [].concat(pki_data).every(function(cert) { var der = cert.toString('hex'); var pem = KJUR.asn1.ASN1Util.getPEMStringFromHex(der, 'CERTIFICATE'); - return !!Trusted[pem.replace(/\s+/g, '')]; + return !!RootCerts[pem.replace(/\s+/g, '')]; }); if (!trusted) { @@ -272,7 +265,7 @@ PayPro.prototype.verify = function() { var der = cert.toString('hex'); var pem = KJUR.asn1.ASN1Util.getPEMStringFromHex(der, 'CERTIFICATE'); - if (!Trusted[pem.replace(/\s+/g, '')]) { + if (!RootCerts[pem.replace(/\s+/g, '')]) { // throw new Error('Unstrusted certificate.'); } diff --git a/lib/browser/PayPro.js b/lib/browser/PayPro.js index 524569c..867fdb1 100644 --- a/lib/browser/PayPro.js +++ b/lib/browser/PayPro.js @@ -4,14 +4,7 @@ var Key = require('./Key'); var KJUR = require('./x509'); var assert = require('assert'); var PayPro = require('../PayPro'); -var Trusted = require('../RootCerts'); - -// Use hash table for efficiency: -Trusted = Trusted.reduce(function(trusted, cert) { - cert = cert.replace(/\s+/g, ''); - trusted[cert] = true; - return trusted; -}, {}); +var RootCerts = require('../RootCerts'); PayPro.sign = function(key) { if (this.messageType !== 'PaymentRequest') @@ -32,7 +25,7 @@ PayPro.sign = function(key) { var trusted = [].concat(pki_data).every(function(cert) { var der = cert.toString('hex'); var pem = KJUR.asn1.ASN1Util.getPEMStringFromHex(der, 'CERTIFICATE'); - return !!Trusted[pem.replace(/\s+/g, '')]; + return !!RootCerts[pem.replace(/\s+/g, '')]; }); if (!trusted) { @@ -82,7 +75,7 @@ PayPro.verify = function() { var der = cert.toString('hex'); var pem = KJUR.asn1.ASN1Util.getPEMStringFromHex(der, 'CERTIFICATE'); - if (!Trusted[pem.replace(/\s+/g, '')]) { + if (!RootCerts[pem.replace(/\s+/g, '')]) { // throw new Error('Unstrusted certificate.'); }