UNPKG

blockstack

Version:

The Blockstack Javascript library for identity and authentication.

55 lines (40 loc) 3.07 kB
'use strict'; 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)('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'); }); }