blockstack
Version:
The Blockstack Javascript library for authentication, identity, and storage.
75 lines (55 loc) • 4.05 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
exports.runUtilsTests = runUtilsTests;
var _tape = require('tape-promise/tape');
var _tape2 = _interopRequireDefault(_tape);
var _jsontokens = require('jsontokens');
var _lib = require('../../../lib');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function runUtilsTests() {
(0, _tape2.default)('makeECPrivateKey', function (t) {
t.plan(5);
var entropy = (0, _lib.getEntropy)(32);
t.ok(entropy, 'Entropy should have been created');
var privateKey = (0, _lib.makeECPrivateKey)();
t.ok(privateKey, 'Private key should have been created');
t.equal(typeof privateKey === 'undefined' ? 'undefined' : _typeof(privateKey), 'string', 'Private key should be a string');
var publicKey = _jsontokens.SECP256K1Client.derivePublicKey(privateKey);
var address = (0, _lib.publicKeyToAddress)(publicKey);
t.ok(address, 'Address should have been created');
t.equal(typeof address === 'undefined' ? 'undefined' : _typeof(address), 'string', 'Address should be a string');
});
(0, _tape2.default)('ecPairToHexString', function (t) {
t.plan(2);
var privateKey = '00cdce6b5f87d38f2a830cae0da82162e1b487f07c5affa8130f01fe1a2a25fb01';
var expectedAddress = '1WykMawQRnLh7SWmmoRL4qTDNCgAsVRF1';
var computedECPair = (0, _lib.hexStringToECPair)(privateKey);
t.equal(privateKey, (0, _lib.ecPairToHexString)(computedECPair), 'Should return same hex string');
t.equal(expectedAddress, (0, _lib.ecPairToAddress)(computedECPair), 'Should parse to correct address');
});
(0, _tape2.default)('isLaterVersion', function (t) {
t.plan(4);
t.false((0, _lib.isLaterVersion)(undefined, '1.1.0', 'undefined version is not later than 1.1.0'));
t.true((0, _lib.isLaterVersion)('1.2.0', '1.1.0', '1.2.0 version is later than 1.1.0'));
t.true((0, _lib.isLaterVersion)('1.1.0', '1.1.0', '1.1.0 version is later than 1.1.0'));
t.false((0, _lib.isLaterVersion)('1.1.0', '1.2.0', '1.1.0 version is later than 1.2.0'));
});
(0, _tape2.default)('isSameOriginAbsoluteUrl', function (t) {
t.plan(12);
t.true((0, _lib.isSameOriginAbsoluteUrl)('http://example.com', 'http://example.com/'), 'should be same origin');
t.true((0, _lib.isSameOriginAbsoluteUrl)('https://example.com', 'https://example.com/'), 'should be same origin');
t.true((0, _lib.isSameOriginAbsoluteUrl)('http://example.com', 'http://example.com/manifest.json'), 'should be same origin');
t.true((0, _lib.isSameOriginAbsoluteUrl)('https://example.com', 'https://example.com/manifest.json'), 'should be same origin');
t.true((0, _lib.isSameOriginAbsoluteUrl)('http://localhost:3000', 'http://localhost:3000/manifest.json'), 'should be same origin');
t.true((0, _lib.isSameOriginAbsoluteUrl)('http://app.example.com', 'http://app.example.com/manifest.json'), 'should be same origin');
t.true((0, _lib.isSameOriginAbsoluteUrl)('http://app.example.com:80', 'http://app.example.com/manifest.json'), 'should be same origin');
t.true((0, _lib.isSameOriginAbsoluteUrl)('https://app.example.com:80', 'https://app.example.com:80/manifest.json'), 'should be same origin');
t.false((0, _lib.isSameOriginAbsoluteUrl)('http://example.com', 'https://example.com/'), 'should not be same origin');
t.false((0, _lib.isSameOriginAbsoluteUrl)('http://example.com', 'http://example.com:1234'), 'should not be same origin');
t.false((0, _lib.isSameOriginAbsoluteUrl)('http://app.example.com', 'https://example.com/manifest.json'), 'should not be same origin');
t.false((0, _lib.isSameOriginAbsoluteUrl)('http://app.example.com', '/manifest.json'), 'should not be same origin');
});
}