diff --git a/lib/thirty-two/LICENSE.txt b/lib/base32/LICENSE.txt similarity index 95% rename from lib/thirty-two/LICENSE.txt rename to lib/base32/LICENSE.txt index 364e7fa..1e3aadd 100644 --- a/lib/thirty-two/LICENSE.txt +++ b/lib/base32/LICENSE.txt @@ -1,4 +1,4 @@ -Copyright (c) 2011, Chris Umbel +Copyright (c) 2023, Chris Umbel, Lisoveliy Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/lib/base32/README.md b/lib/base32/README.md new file mode 100644 index 0000000..1242794 --- /dev/null +++ b/lib/base32/README.md @@ -0,0 +1,10 @@ +# base32 + +Implementation of RFC 3548 Base32 encoding/decoding for zepp quickjs. + +## Usage + import {encode, decode} from 'base32/index.js' + base32.encode('node'); + // output: NZXWIZI= + base32.decode('NZXWIZI='); + //output: node diff --git a/lib/thirty-two/index.js b/lib/base32/index.js similarity index 91% rename from lib/thirty-two/index.js rename to lib/base32/index.js index e0eebe2..fb23939 100644 --- a/lib/thirty-two/index.js +++ b/lib/base32/index.js @@ -1,5 +1,5 @@ /* -Copyright (c) 2011, Chris Umbel +Copyright (c) 2023, Chris Umbel, Lisoveliy Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -20,4 +20,4 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -export {encode, decode} from './lib/thirty-two/thirty-two.js' \ No newline at end of file +export { encode, decode } from './lib/base32/base32.js' \ No newline at end of file diff --git a/lib/thirty-two/lib/thirty-two/thirty-two.js b/lib/base32/lib/base32/base32.js similarity index 83% rename from lib/thirty-two/lib/thirty-two/thirty-two.js rename to lib/base32/lib/base32/base32.js index 2887dfa..514f7c6 100644 --- a/lib/thirty-two/lib/thirty-two/thirty-two.js +++ b/lib/base32/lib/base32/base32.js @@ -1,5 +1,5 @@ /* -Copyright (c) 2011, Chris Umbel +Copyright (c) 2023, Chris Umbel, Lisoveliy Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -37,12 +37,12 @@ var byteTable = [ function quintetCount(buff) { var quintets = Math.floor(buff.length / 5); - return buff.length % 5 === 0 ? quintets: quintets + 1; + return buff.length % 5 === 0 ? quintets : quintets + 1; } export function encode(plain) { - if(!Buffer.isBuffer(plain)){ - plain = new Buffer(plain); + if (!Buffer.isBuffer(plain)) { + plain = new Buffer(plain); } var i = 0; var j = 0; @@ -52,10 +52,10 @@ export function encode(plain) { /* byte by byte isn't as pretty as quintet by quintet but tests a bit faster. will have to revisit. */ - while(i < plain.length) { + while (i < plain.length) { var current = plain[i]; - if(shiftIndex > 3) { + if (shiftIndex > 3) { digit = current & (0xff >> shiftIndex); shiftIndex = (shiftIndex + 5) % 8; digit = (digit << shiftIndex) | ((i + 1 < plain.length) ? @@ -64,14 +64,14 @@ export function encode(plain) { } else { digit = (current >> (8 - (shiftIndex + 5))) & 0x1f; shiftIndex = (shiftIndex + 5) % 8; - if(shiftIndex === 0) i++; + if (shiftIndex === 0) i++; } encoded[j] = charTable.charCodeAt(digit); j++; } - for(i = j; i < encoded.length; i++) { + for (i = j; i < encoded.length; i++) { encoded[i] = 0x3d; //'='.charCodeAt(0) } @@ -83,27 +83,27 @@ export function decode(encoded) { var plainDigit = 0; var plainChar; var plainPos = 0; - if(!Buffer.isBuffer(encoded)){ - encoded = new Buffer(encoded); + if (!Buffer.isBuffer(encoded)) { + encoded = new Buffer(encoded); } var decoded = new Buffer(Math.ceil(encoded.length * 5 / 8)); /* byte by byte isn't as pretty as octet by octet but tests a bit faster. will have to revisit. */ - for(var i = 0; i < encoded.length; i++) { - if(encoded[i] === 0x3d){ //'=' - break; - } + for (var i = 0; i < encoded.length; i++) { + if (encoded[i] === 0x3d) { //'=' + break; + } var encodedByte = encoded[i] - 0x30; - if(encodedByte < byteTable.length) { + if (encodedByte < byteTable.length) { plainDigit = byteTable[encodedByte]; - if(shiftIndex <= 3) { + if (shiftIndex <= 3) { shiftIndex = (shiftIndex + 5) % 8; - if(shiftIndex === 0) { + if (shiftIndex === 0) { plainChar |= plainDigit; decoded[plainPos] = plainChar; plainPos++; @@ -120,7 +120,7 @@ export function decode(encoded) { plainChar = 0xff & (plainDigit << (8 - shiftIndex)); } } else { - throw new Error('Invalid input - it is not base32 encoded string'); + throw new Error('Invalid input - it is not base32 encoded string'); } } diff --git a/lib/thirty-two/package.json b/lib/base32/package.json similarity index 67% rename from lib/thirty-two/package.json rename to lib/base32/package.json index fc341c7..9e3ede1 100644 --- a/lib/thirty-two/package.json +++ b/lib/base32/package.json @@ -1,13 +1,10 @@ { - "name": "thirty-two", + "name": "base32", "description": "Implementation RFC 3548 Base32 encoding/decoding for node.", - "version": "1.0.2", - "engines": { - "node": ">=0.2.6" - }, + "version": "1.0.2-zepp", "author": "Chris Umbel ", "keywords": ["base32", "encoding"], - "main": "./lib/thirty-two/index.js", + "main": "index.js", "repository": { "type": "git", "url": "git://github.com/chrisumbel/thirty-two.git" diff --git a/lib/thirty-two/.npmignore b/lib/thirty-two/.npmignore deleted file mode 100644 index 3ee8de4..0000000 --- a/lib/thirty-two/.npmignore +++ /dev/null @@ -1,4 +0,0 @@ -*.kpf -*~ -\#* -node_modules diff --git a/lib/thirty-two/Makefile b/lib/thirty-two/Makefile deleted file mode 100644 index 6011230..0000000 --- a/lib/thirty-two/Makefile +++ /dev/null @@ -1,24 +0,0 @@ -# Copyright (c) 2011, Chris Umbel - -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: - -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. - -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. - -SHELL := /bin/bash - -test: - jasmine-node spec/ diff --git a/lib/thirty-two/README.md b/lib/thirty-two/README.md deleted file mode 100644 index fd81e38..0000000 --- a/lib/thirty-two/README.md +++ /dev/null @@ -1,15 +0,0 @@ -# thirty-two - -Implementation of RFC 3548 Base32 encoding/decoding for node. - -## Installation - - npm install thirty-two - -## Usage - - var base32 = require('thirty-two'); - base32.encode('node'); - // output: NZXWIZI= - base32.decode('NZXWIZI='); - //output: node diff --git a/lib/thirty-two/spec/thirty-two_spec.js b/lib/thirty-two/spec/thirty-two_spec.js deleted file mode 100644 index a0e0c0a..0000000 --- a/lib/thirty-two/spec/thirty-two_spec.js +++ /dev/null @@ -1,63 +0,0 @@ -/* -Copyright (c) 2011, Chris Umbel - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ -if(!expect){ - function expect(a){ - return { - toBe: function(b){ - require('assert').strictEqual(a, b); - } - }; - } -} -var base32 = require('../lib/thirty-two/'); - -describe('thirty-two', function() { - it('should encode', function() { - expect(base32.encode('a').toString()).toBe('ME======'); - expect(base32.encode('be').toString()).toBe('MJSQ===='); - expect(base32.encode('bee').toString()).toBe('MJSWK==='); - expect(base32.encode('beer').toString()).toBe('MJSWK4Q='); - expect(base32.encode('beers').toString()).toBe('MJSWK4TT'); - expect(base32.encode('beers 1').toString()).toBe('MJSWK4TTEAYQ===='); - expect(base32.encode('shockingly dismissed').toString()).toBe('ONUG6Y3LNFXGO3DZEBSGS43NNFZXGZLE'); - }); - - - it('should decode', function() { - expect(base32.decode('ME======').toString()).toBe('a'); - expect(base32.decode('MJSQ====').toString()).toBe('be'); - expect(base32.decode('ONXW4===').toString()).toBe('son'); - expect(base32.decode('MJSWK===').toString()).toBe('bee'); - expect(base32.decode('MJSWK4Q=').toString()).toBe('beer'); - expect(base32.decode('MJSWK4TT').toString()).toBe('beers'); - expect(base32.decode('mjswK4TT').toString()).toBe('beers'); - expect(base32.decode('MJSWK4TTN5XA====').toString()).toBe('beerson'); - expect(base32.decode('MJSWK4TTEAYQ====').toString()).toBe('beers 1'); - expect(base32.decode('ONUG6Y3LNFXGO3DZEBSGS43NNFZXGZLE').toString()).toBe('shockingly dismissed'); - }); - - it('should be binary safe', function() { - expect(base32.decode(base32.encode(new Buffer([0x00, 0xff, 0x88]))).toString('hex')).toBe('00ff88'); - expect(base32.encode(new Buffer("f61e1f998d69151de8334dbe753ab17ae831c13849a6aecd95d0a4e5dc25", 'hex')).toString()).toBe('6YPB7GMNNEKR32BTJW7HKOVRPLUDDQJYJGTK5TMV2CSOLXBF'); - expect(base32.decode('6YPB7GMNNEKR32BTJW7HKOVRPLUDDQJYJGTK5TMV2CSOLXBF').toString('hex')).toBe('f61e1f998d69151de8334dbe753ab17ae831c13849a6aecd95d0a4e5dc25'); - }); -}); diff --git a/lib/totp.js/.travis.yml b/lib/totp.js/.travis.yml deleted file mode 100644 index efb0983..0000000 --- a/lib/totp.js/.travis.yml +++ /dev/null @@ -1,3 +0,0 @@ -language: node_js -node_js: - - "8" diff --git a/lib/totp.js/README.md b/lib/totp.js/README.md deleted file mode 100644 index 4cfac1e..0000000 --- a/lib/totp.js/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# totp.js -Two-factor authentication implementation in pure javascript. One-time password generator (HOTP/TOTP) with support for Google Authenticator. - -[![Build Status](https://travis-ci.org/wuyanxin/totp.js.svg?branch=master)](https://travis-ci.org/wuyanxin/totp.js) - diff --git a/lib/totp.js/index.js b/lib/totp.js/index.js index 17fed34..7dcf2e0 100644 --- a/lib/totp.js/index.js +++ b/lib/totp.js/index.js @@ -1,9 +1,2 @@ -/* - * @Author: wuyanxin - * @Date: 2018-03-21 23:12:14 - * @Last Modified by: wuyanxin - * @Last Modified time: 2018-03-21 23:12:14 - */ - -export {HOTP} from './lib/hotp.js' -export {TOTP} from './lib/totp.js' +export { HOTP } from './lib/hotp.js' +export { TOTP } from './lib/totp.js' diff --git a/lib/totp.js/lib/hotp.js b/lib/totp.js/lib/hotp.js index 3c1c9b9..3614db9 100644 --- a/lib/totp.js/lib/hotp.js +++ b/lib/totp.js/lib/hotp.js @@ -1,11 +1,4 @@ -/* - * @Author: wuyanxin - * @Date: 2018-03-21 22:25:37 - * @Last Modified by: wuyanxin - * @Last Modified time: 2018-03-21 22:29:43 - */ - -import {encode, decode} from '../../thirty-two/index.js' +import { encode, decode } from '../../base32/index.js' import jsSHA from 'jssha' export class HOTP { @@ -54,11 +47,11 @@ export class HOTP { } _truncat(hmac_result) { - const offset = hmac_result[19].charCodeAt() & 0xf; - const bin_code = (hmac_result[offset].charCodeAt() & 0x7f) << 24 - | (hmac_result[offset+1].charCodeAt() & 0xff) << 16 - | (hmac_result[offset+2].charCodeAt() & 0xff) << 8 - | (hmac_result[offset+3].charCodeAt() & 0xff); + const offset = hmac_result[19].charCodeAt() & 0xf; + const bin_code = (hmac_result[offset].charCodeAt() & 0x7f) << 24 + | (hmac_result[offset + 1].charCodeAt() & 0xff) << 16 + | (hmac_result[offset + 2].charCodeAt() & 0xff) << 8 + | (hmac_result[offset + 3].charCodeAt() & 0xff); let otp = (bin_code % 10 ** this.digit).toString(); while (otp.length < this.digit) { otp = '0' + otp; diff --git a/lib/totp.js/lib/totp.js b/lib/totp.js/lib/totp.js index ebae234..172414e 100644 --- a/lib/totp.js/lib/totp.js +++ b/lib/totp.js/lib/totp.js @@ -1,14 +1,7 @@ -/* - * @Author: wuyanxin - * @Date: 2018-03-21 22:25:42 - * @Last Modified by: wuyanxin - * @Last Modified time: 2018-03-21 22:42:28 - */ - -import {HOTP} from "./hotp.js"; +import { HOTP } from "./hotp.js"; export class TOTP extends HOTP { - constructor(key){ + constructor(key) { super(key) } @@ -20,5 +13,4 @@ export class TOTP extends HOTP { verify(otp, timeStep = 30, t0 = 0) { return otp === this.genOTP(timeStep, t0); } - } \ No newline at end of file diff --git a/lib/totp.js/package.json b/lib/totp.js/package.json index 798a589..a915c48 100644 --- a/lib/totp.js/package.json +++ b/lib/totp.js/package.json @@ -1,6 +1,6 @@ { "name": "totp.js", - "version": "0.0.1", + "version": "1.0.1-zepp", "description": "Two-factor authentication implementation in pure javascript. One-time password generator (HOTP/TOTP) with support for Google Authenticator. ", "main": "index.js", "scripts": { @@ -24,8 +24,7 @@ }, "homepage": "https://github.com/wuyanxin/totp.js#readme", "dependencies": { - "jssha": "^2.3.1", - "thirty-two": "^1.0.2" + "jssha": "^2.3.1" }, "devDependencies": { "mocha": "^5.0.4"