autho 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/build/bin.js +53 -597
  2. package/package.json +15 -15
package/build/bin.js CHANGED
@@ -57229,602 +57229,56 @@ var inquirer = {
57229
57229
  };
57230
57230
  var inquirer_default = inquirer;
57231
57231
 
57232
- // node_modules/.pnpm/otpauth@9.2.3/node_modules/otpauth/dist/otpauth.node.mjs
57233
- var crypto = __toESM(require("node:crypto"), 1);
57234
- var uintToBuf = (num) => {
57235
- const buf = new ArrayBuffer(8);
57236
- const arr = new Uint8Array(buf);
57237
- let acc = num;
57238
- for (let i = 7; i >= 0; i--) {
57239
- if (acc === 0)
57240
- break;
57241
- arr[i] = acc & 255;
57242
- acc -= arr[i];
57243
- acc /= 256;
57244
- }
57245
- return buf;
57246
- };
57247
- var jsSHA = void 0;
57248
- var globalScope = (() => {
57249
- if (typeof globalThis === "object")
57250
- return globalThis;
57251
- else {
57252
- Object.defineProperty(Object.prototype, "__GLOBALTHIS__", {
57253
- get() {
57254
- return this;
57255
- },
57256
- configurable: true
57257
- });
57258
- try {
57259
- if (typeof __GLOBALTHIS__ !== "undefined")
57260
- return __GLOBALTHIS__;
57261
- } finally {
57262
- delete Object.prototype.__GLOBALTHIS__;
57263
- }
57264
- }
57265
- if (typeof self !== "undefined")
57266
- return self;
57267
- else if (typeof window !== "undefined")
57268
- return window;
57269
- else if (typeof global !== "undefined")
57270
- return global;
57271
- return void 0;
57272
- })();
57273
- var OPENSSL_JSSHA_ALGO_MAP = {
57274
- SHA1: "SHA-1",
57275
- SHA224: "SHA-224",
57276
- SHA256: "SHA-256",
57277
- SHA384: "SHA-384",
57278
- SHA512: "SHA-512",
57279
- "SHA3-224": "SHA3-224",
57280
- "SHA3-256": "SHA3-256",
57281
- "SHA3-384": "SHA3-384",
57282
- "SHA3-512": "SHA3-512"
57283
- };
57284
- var hmacDigest = (algorithm, key, message) => {
57285
- if (crypto?.createHmac) {
57286
- const hmac = crypto.createHmac(algorithm, globalScope.Buffer.from(key));
57287
- hmac.update(globalScope.Buffer.from(message));
57288
- return hmac.digest().buffer;
57289
- } else {
57290
- const variant = OPENSSL_JSSHA_ALGO_MAP[algorithm.toUpperCase()];
57291
- if (typeof variant === "undefined") {
57292
- throw new TypeError("Unknown hash function");
57293
- }
57294
- const hmac = new jsSHA(variant, "ARRAYBUFFER");
57295
- hmac.setHMACKey(key, "ARRAYBUFFER");
57296
- hmac.update(message);
57297
- return hmac.getHMAC("ARRAYBUFFER");
57298
- }
57299
- };
57300
- var ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
57301
- var base32ToBuf = (str) => {
57302
- let end = str.length;
57303
- while (str[end - 1] === "=")
57304
- --end;
57305
- const cstr = (end < str.length ? str.substring(0, end) : str).toUpperCase();
57306
- const buf = new ArrayBuffer(cstr.length * 5 / 8 | 0);
57307
- const arr = new Uint8Array(buf);
57308
- let bits = 0;
57309
- let value = 0;
57310
- let index = 0;
57311
- for (let i = 0; i < cstr.length; i++) {
57312
- const idx = ALPHABET.indexOf(cstr[i]);
57313
- if (idx === -1)
57314
- throw new TypeError(`Invalid character found: ${cstr[i]}`);
57315
- value = value << 5 | idx;
57316
- bits += 5;
57317
- if (bits >= 8) {
57318
- bits -= 8;
57319
- arr[index++] = value >>> bits;
57320
- }
57321
- }
57322
- return buf;
57323
- };
57324
- var base32FromBuf = (buf) => {
57325
- const arr = new Uint8Array(buf);
57326
- let bits = 0;
57232
+ // packages/sdk/otp.js
57233
+ var import_crypto = __toESM(require("crypto"), 1);
57234
+ function base32Decode(base32) {
57235
+ const base32chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
57236
+ let bits = "";
57327
57237
  let value = 0;
57328
- let str = "";
57329
- for (let i = 0; i < arr.length; i++) {
57330
- value = value << 8 | arr[i];
57331
- bits += 8;
57332
- while (bits >= 5) {
57333
- str += ALPHABET[value >>> bits - 5 & 31];
57334
- bits -= 5;
57238
+ let output = new Uint8Array(base32.length * 5 / 8);
57239
+ for (let i = 0; i < base32.length; i++) {
57240
+ const index = base32chars.indexOf(base32[i].toUpperCase());
57241
+ if (index === -1) {
57242
+ throw new Error("Invalid base32 character.");
57335
57243
  }
57336
- }
57337
- if (bits > 0) {
57338
- str += ALPHABET[value << 5 - bits & 31];
57339
- }
57340
- return str;
57341
- };
57342
- var hexToBuf = (str) => {
57343
- const buf = new ArrayBuffer(str.length / 2);
57344
- const arr = new Uint8Array(buf);
57345
- for (let i = 0; i < str.length; i += 2) {
57346
- arr[i / 2] = parseInt(str.substring(i, i + 2), 16);
57347
- }
57348
- return buf;
57349
- };
57350
- var hexFromBuf = (buf) => {
57351
- const arr = new Uint8Array(buf);
57352
- let str = "";
57353
- for (let i = 0; i < arr.length; i++) {
57354
- const hex = arr[i].toString(16);
57355
- if (hex.length === 1)
57356
- str += "0";
57357
- str += hex;
57358
- }
57359
- return str.toUpperCase();
57360
- };
57361
- var latin1ToBuf = (str) => {
57362
- const buf = new ArrayBuffer(str.length);
57363
- const arr = new Uint8Array(buf);
57364
- for (let i = 0; i < str.length; i++) {
57365
- arr[i] = str.charCodeAt(i) & 255;
57366
- }
57367
- return buf;
57368
- };
57369
- var latin1FromBuf = (buf) => {
57370
- const arr = new Uint8Array(buf);
57371
- let str = "";
57372
- for (let i = 0; i < arr.length; i++) {
57373
- str += String.fromCharCode(arr[i]);
57374
- }
57375
- return str;
57376
- };
57377
- var ENCODER = globalScope.TextEncoder ? new globalScope.TextEncoder("utf-8") : null;
57378
- var DECODER = globalScope.TextDecoder ? new globalScope.TextDecoder("utf-8") : null;
57379
- var utf8ToBuf = (str) => {
57380
- if (!ENCODER) {
57381
- throw new Error("Encoding API not available");
57382
- }
57383
- return ENCODER.encode(str).buffer;
57384
- };
57385
- var utf8FromBuf = (buf) => {
57386
- if (!DECODER) {
57387
- throw new Error("Encoding API not available");
57388
- }
57389
- return DECODER.decode(buf);
57390
- };
57391
- var randomBytes2 = (size) => {
57392
- if (crypto?.randomBytes) {
57393
- return crypto.randomBytes(size).buffer;
57394
- } else {
57395
- if (!globalScope.crypto?.getRandomValues) {
57396
- throw new Error("Cryptography API not available");
57244
+ value = value << 5 | index;
57245
+ bits += "11111";
57246
+ if (bits.length >= 8) {
57247
+ output[i * 5 / 8 | 0] = value >> bits.length - 8 & 255;
57248
+ bits = bits.slice(8);
57397
57249
  }
57398
- return globalScope.crypto.getRandomValues(new Uint8Array(size)).buffer;
57399
- }
57400
- };
57401
- var Secret = class _Secret {
57402
- /**
57403
- * Creates a secret key object.
57404
- * @param {Object} [config] Configuration options.
57405
- * @param {ArrayBuffer} [config.buffer=randomBytes] Secret key.
57406
- * @param {number} [config.size=20] Number of random bytes to generate, ignored if 'buffer' is provided.
57407
- */
57408
- constructor({
57409
- buffer,
57410
- size = 20
57411
- } = {}) {
57412
- this.buffer = typeof buffer === "undefined" ? randomBytes2(size) : buffer;
57413
- }
57414
- /**
57415
- * Converts a Latin-1 string to a Secret object.
57416
- * @param {string} str Latin-1 string.
57417
- * @returns {Secret} Secret object.
57418
- */
57419
- static fromLatin1(str) {
57420
- return new _Secret({
57421
- buffer: latin1ToBuf(str)
57422
- });
57423
- }
57424
- /**
57425
- * Converts an UTF-8 string to a Secret object.
57426
- * @param {string} str UTF-8 string.
57427
- * @returns {Secret} Secret object.
57428
- */
57429
- static fromUTF8(str) {
57430
- return new _Secret({
57431
- buffer: utf8ToBuf(str)
57432
- });
57433
- }
57434
- /**
57435
- * Converts a base32 string to a Secret object.
57436
- * @param {string} str Base32 string.
57437
- * @returns {Secret} Secret object.
57438
- */
57439
- static fromBase32(str) {
57440
- return new _Secret({
57441
- buffer: base32ToBuf(str)
57442
- });
57443
- }
57444
- /**
57445
- * Converts a hexadecimal string to a Secret object.
57446
- * @param {string} str Hexadecimal string.
57447
- * @returns {Secret} Secret object.
57448
- */
57449
- static fromHex(str) {
57450
- return new _Secret({
57451
- buffer: hexToBuf(str)
57452
- });
57453
- }
57454
- /**
57455
- * Latin-1 string representation of secret key.
57456
- * @type {string}
57457
- */
57458
- get latin1() {
57459
- Object.defineProperty(this, "latin1", {
57460
- enumerable: true,
57461
- value: latin1FromBuf(this.buffer)
57462
- });
57463
- return this.latin1;
57464
- }
57465
- /**
57466
- * UTF-8 string representation of secret key.
57467
- * @type {string}
57468
- */
57469
- get utf8() {
57470
- Object.defineProperty(this, "utf8", {
57471
- enumerable: true,
57472
- value: utf8FromBuf(this.buffer)
57473
- });
57474
- return this.utf8;
57475
- }
57476
- /**
57477
- * Base32 string representation of secret key.
57478
- * @type {string}
57479
- */
57480
- get base32() {
57481
- Object.defineProperty(this, "base32", {
57482
- enumerable: true,
57483
- value: base32FromBuf(this.buffer)
57484
- });
57485
- return this.base32;
57486
- }
57487
- /**
57488
- * Hexadecimal string representation of secret key.
57489
- * @type {string}
57490
- */
57491
- get hex() {
57492
- Object.defineProperty(this, "hex", {
57493
- enumerable: true,
57494
- value: hexFromBuf(this.buffer)
57495
- });
57496
- return this.hex;
57497
- }
57498
- };
57499
- var timingSafeEqual2 = (a, b) => {
57500
- if (crypto?.timingSafeEqual) {
57501
- return crypto.timingSafeEqual(globalScope.Buffer.from(a), globalScope.Buffer.from(b));
57502
- } else {
57503
- if (a.length !== b.length) {
57504
- throw new TypeError("Input strings must have the same length");
57505
- }
57506
- let i = -1;
57507
- let out = 0;
57508
- while (++i < a.length) {
57509
- out |= a.charCodeAt(i) ^ b.charCodeAt(i);
57510
- }
57511
- return out === 0;
57512
- }
57513
- };
57514
- var HOTP = class _HOTP {
57515
- /**
57516
- * Default configuration.
57517
- * @type {{
57518
- * issuer: string,
57519
- * label: string,
57520
- * issuerInLabel: boolean,
57521
- * algorithm: string,
57522
- * digits: number,
57523
- * counter: number
57524
- * window: number
57525
- * }}
57526
- */
57527
- static get defaults() {
57528
- return {
57529
- issuer: "",
57530
- label: "OTPAuth",
57531
- issuerInLabel: true,
57532
- algorithm: "SHA1",
57533
- digits: 6,
57534
- counter: 0,
57535
- window: 1
57536
- };
57537
57250
  }
57538
- /**
57539
- * Creates an HOTP object.
57540
- * @param {Object} [config] Configuration options.
57541
- * @param {string} [config.issuer=''] Account provider.
57542
- * @param {string} [config.label='OTPAuth'] Account label.
57543
- * @param {boolean} [config.issuerInLabel=true] Include issuer prefix in label.
57544
- * @param {Secret|string} [config.secret=Secret] Secret key.
57545
- * @param {string} [config.algorithm='SHA1'] HMAC hashing algorithm.
57546
- * @param {number} [config.digits=6] Token length.
57547
- * @param {number} [config.counter=0] Initial counter value.
57548
- */
57549
- constructor({
57550
- issuer = _HOTP.defaults.issuer,
57551
- label = _HOTP.defaults.label,
57552
- issuerInLabel = _HOTP.defaults.issuerInLabel,
57553
- secret = new Secret(),
57554
- algorithm = _HOTP.defaults.algorithm,
57555
- digits: digits2 = _HOTP.defaults.digits,
57556
- counter = _HOTP.defaults.counter
57557
- } = {}) {
57558
- this.issuer = issuer;
57559
- this.label = label;
57560
- this.issuerInLabel = issuerInLabel;
57561
- this.secret = typeof secret === "string" ? Secret.fromBase32(secret) : secret;
57562
- this.algorithm = algorithm.toUpperCase();
57563
- this.digits = digits2;
57564
- this.counter = counter;
57565
- }
57566
- /**
57567
- * Generates an HOTP token.
57568
- * @param {Object} config Configuration options.
57569
- * @param {Secret} config.secret Secret key.
57570
- * @param {string} [config.algorithm='SHA1'] HMAC hashing algorithm.
57571
- * @param {number} [config.digits=6] Token length.
57572
- * @param {number} [config.counter=0] Counter value.
57573
- * @returns {string} Token.
57574
- */
57575
- static generate({
57576
- secret,
57577
- algorithm = _HOTP.defaults.algorithm,
57578
- digits: digits2 = _HOTP.defaults.digits,
57579
- counter = _HOTP.defaults.counter
57580
- }) {
57581
- const digest = new Uint8Array(hmacDigest(algorithm, secret.buffer, uintToBuf(counter)));
57582
- const offset = digest[digest.byteLength - 1] & 15;
57583
- const otp = ((digest[offset] & 127) << 24 | (digest[offset + 1] & 255) << 16 | (digest[offset + 2] & 255) << 8 | digest[offset + 3] & 255) % 10 ** digits2;
57584
- return otp.toString().padStart(digits2, "0");
57585
- }
57586
- /**
57587
- * Generates an HOTP token.
57588
- * @param {Object} [config] Configuration options.
57589
- * @param {number} [config.counter=this.counter++] Counter value.
57590
- * @returns {string} Token.
57591
- */
57592
- generate({
57593
- counter = this.counter++
57594
- } = {}) {
57595
- return _HOTP.generate({
57596
- secret: this.secret,
57597
- algorithm: this.algorithm,
57598
- digits: this.digits,
57599
- counter
57600
- });
57601
- }
57602
- /**
57603
- * Validates an HOTP token.
57604
- * @param {Object} config Configuration options.
57605
- * @param {string} config.token Token value.
57606
- * @param {Secret} config.secret Secret key.
57607
- * @param {string} [config.algorithm='SHA1'] HMAC hashing algorithm.
57608
- * @param {number} config.digits Token length.
57609
- * @param {number} [config.counter=0] Counter value.
57610
- * @param {number} [config.window=1] Window of counter values to test.
57611
- * @returns {number|null} Token delta or null if it is not found in the search window, in which case it should be considered invalid.
57612
- */
57613
- static validate({
57614
- token,
57615
- secret,
57616
- algorithm,
57617
- digits: digits2,
57618
- counter = _HOTP.defaults.counter,
57619
- window: window2 = _HOTP.defaults.window
57620
- }) {
57621
- if (token.length !== digits2)
57622
- return null;
57623
- let delta = null;
57624
- for (let i = counter - window2; i <= counter + window2; ++i) {
57625
- const generatedToken = _HOTP.generate({
57626
- secret,
57627
- algorithm,
57628
- digits: digits2,
57629
- counter: i
57630
- });
57631
- if (timingSafeEqual2(token, generatedToken)) {
57632
- delta = i - counter;
57633
- }
57251
+ return output;
57252
+ }
57253
+ function generateTOTP(secret, window2 = 0) {
57254
+ const key = base32Decode(secret);
57255
+ const epoch = Math.floor(Date.now() / 1e3);
57256
+ let counter = Math.floor(epoch / 30) + window2;
57257
+ const time = Buffer.alloc(8);
57258
+ for (let i = 7; i >= 0; i--) {
57259
+ time[i] = counter & 255;
57260
+ counter >>= 8;
57261
+ }
57262
+ const hmac = import_crypto.default.createHmac("sha1", key);
57263
+ hmac.update(time);
57264
+ const hash = hmac.digest();
57265
+ const offset = hash[hash.length - 1] & 15;
57266
+ const binary = (hash[offset] & 127) << 24 | (hash[offset + 1] & 255) << 16 | (hash[offset + 2] & 255) << 8 | hash[offset + 3] & 255;
57267
+ const token = binary % 1e6;
57268
+ return token.toString().padStart(6, "0");
57269
+ }
57270
+ function verifyTOTP(secret, token, window2 = 1) {
57271
+ for (let errorWindow = -window2; errorWindow <= window2; errorWindow++) {
57272
+ const generatedToken = generateTOTP(secret, errorWindow);
57273
+ if (generatedToken === token) {
57274
+ return true;
57634
57275
  }
57635
- return delta;
57636
- }
57637
- /**
57638
- * Validates an HOTP token.
57639
- * @param {Object} config Configuration options.
57640
- * @param {string} config.token Token value.
57641
- * @param {number} [config.counter=this.counter] Counter value.
57642
- * @param {number} [config.window=1] Window of counter values to test.
57643
- * @returns {number|null} Token delta or null if it is not found in the search window, in which case it should be considered invalid.
57644
- */
57645
- validate({
57646
- token,
57647
- counter = this.counter,
57648
- window: window2
57649
- }) {
57650
- return _HOTP.validate({
57651
- token,
57652
- secret: this.secret,
57653
- algorithm: this.algorithm,
57654
- digits: this.digits,
57655
- counter,
57656
- window: window2
57657
- });
57658
- }
57659
- /**
57660
- * Returns a Google Authenticator key URI.
57661
- * @returns {string} URI.
57662
- */
57663
- toString() {
57664
- const e = encodeURIComponent;
57665
- return `otpauth://hotp/${this.issuer.length > 0 ? this.issuerInLabel ? `${e(this.issuer)}:${e(this.label)}?issuer=${e(this.issuer)}&` : `${e(this.label)}?issuer=${e(this.issuer)}&` : `${e(this.label)}?`}secret=${e(this.secret.base32)}&algorithm=${e(this.algorithm)}&digits=${e(this.digits)}&counter=${e(this.counter)}`;
57666
57276
  }
57667
- };
57668
- var TOTP = class _TOTP {
57669
- /**
57670
- * Default configuration.
57671
- * @type {{
57672
- * issuer: string,
57673
- * label: string,
57674
- * issuerInLabel: boolean,
57675
- * algorithm: string,
57676
- * digits: number,
57677
- * period: number
57678
- * window: number
57679
- * }}
57680
- */
57681
- static get defaults() {
57682
- return {
57683
- issuer: "",
57684
- label: "OTPAuth",
57685
- issuerInLabel: true,
57686
- algorithm: "SHA1",
57687
- digits: 6,
57688
- period: 30,
57689
- window: 1
57690
- };
57691
- }
57692
- /**
57693
- * Creates a TOTP object.
57694
- * @param {Object} [config] Configuration options.
57695
- * @param {string} [config.issuer=''] Account provider.
57696
- * @param {string} [config.label='OTPAuth'] Account label.
57697
- * @param {boolean} [config.issuerInLabel=true] Include issuer prefix in label.
57698
- * @param {Secret|string} [config.secret=Secret] Secret key.
57699
- * @param {string} [config.algorithm='SHA1'] HMAC hashing algorithm.
57700
- * @param {number} [config.digits=6] Token length.
57701
- * @param {number} [config.period=30] Token time-step duration.
57702
- */
57703
- constructor({
57704
- issuer = _TOTP.defaults.issuer,
57705
- label = _TOTP.defaults.label,
57706
- issuerInLabel = _TOTP.defaults.issuerInLabel,
57707
- secret = new Secret(),
57708
- algorithm = _TOTP.defaults.algorithm,
57709
- digits: digits2 = _TOTP.defaults.digits,
57710
- period = _TOTP.defaults.period
57711
- } = {}) {
57712
- this.issuer = issuer;
57713
- this.label = label;
57714
- this.issuerInLabel = issuerInLabel;
57715
- this.secret = typeof secret === "string" ? Secret.fromBase32(secret) : secret;
57716
- this.algorithm = algorithm.toUpperCase();
57717
- this.digits = digits2;
57718
- this.period = period;
57719
- }
57720
- /**
57721
- * Generates a TOTP token.
57722
- * @param {Object} config Configuration options.
57723
- * @param {Secret} config.secret Secret key.
57724
- * @param {string} [config.algorithm='SHA1'] HMAC hashing algorithm.
57725
- * @param {number} [config.digits=6] Token length.
57726
- * @param {number} [config.period=30] Token time-step duration.
57727
- * @param {number} [config.timestamp=Date.now] Timestamp value in milliseconds.
57728
- * @returns {string} Token.
57729
- */
57730
- static generate({
57731
- secret,
57732
- algorithm,
57733
- digits: digits2,
57734
- period = _TOTP.defaults.period,
57735
- timestamp = Date.now()
57736
- }) {
57737
- return HOTP.generate({
57738
- secret,
57739
- algorithm,
57740
- digits: digits2,
57741
- counter: Math.floor(timestamp / 1e3 / period)
57742
- });
57743
- }
57744
- /**
57745
- * Generates a TOTP token.
57746
- * @param {Object} [config] Configuration options.
57747
- * @param {number} [config.timestamp=Date.now] Timestamp value in milliseconds.
57748
- * @returns {string} Token.
57749
- */
57750
- generate({
57751
- timestamp = Date.now()
57752
- } = {}) {
57753
- return _TOTP.generate({
57754
- secret: this.secret,
57755
- algorithm: this.algorithm,
57756
- digits: this.digits,
57757
- period: this.period,
57758
- timestamp
57759
- });
57760
- }
57761
- /**
57762
- * Validates a TOTP token.
57763
- * @param {Object} config Configuration options.
57764
- * @param {string} config.token Token value.
57765
- * @param {Secret} config.secret Secret key.
57766
- * @param {string} [config.algorithm='SHA1'] HMAC hashing algorithm.
57767
- * @param {number} config.digits Token length.
57768
- * @param {number} [config.period=30] Token time-step duration.
57769
- * @param {number} [config.timestamp=Date.now] Timestamp value in milliseconds.
57770
- * @param {number} [config.window=1] Window of counter values to test.
57771
- * @returns {number|null} Token delta or null if it is not found in the search window, in which case it should be considered invalid.
57772
- */
57773
- static validate({
57774
- token,
57775
- secret,
57776
- algorithm,
57777
- digits: digits2,
57778
- period = _TOTP.defaults.period,
57779
- timestamp = Date.now(),
57780
- window: window2
57781
- }) {
57782
- return HOTP.validate({
57783
- token,
57784
- secret,
57785
- algorithm,
57786
- digits: digits2,
57787
- counter: Math.floor(timestamp / 1e3 / period),
57788
- window: window2
57789
- });
57790
- }
57791
- /**
57792
- * Validates a TOTP token.
57793
- * @param {Object} config Configuration options.
57794
- * @param {string} config.token Token value.
57795
- * @param {number} [config.timestamp=Date.now] Timestamp value in milliseconds.
57796
- * @param {number} [config.window=1] Window of counter values to test.
57797
- * @returns {number|null} Token delta or null if it is not found in the search window, in which case it should be considered invalid.
57798
- */
57799
- validate({
57800
- token,
57801
- timestamp,
57802
- window: window2
57803
- }) {
57804
- return _TOTP.validate({
57805
- token,
57806
- secret: this.secret,
57807
- algorithm: this.algorithm,
57808
- digits: this.digits,
57809
- period: this.period,
57810
- timestamp,
57811
- window: window2
57812
- });
57813
- }
57814
- /**
57815
- * Returns a Google Authenticator key URI.
57816
- * @returns {string} URI.
57817
- */
57818
- toString() {
57819
- const e = encodeURIComponent;
57820
- return `otpauth://totp/${this.issuer.length > 0 ? this.issuerInLabel ? `${e(this.issuer)}:${e(this.label)}?issuer=${e(this.issuer)}&` : `${e(this.label)}?issuer=${e(this.issuer)}&` : `${e(this.label)}?`}secret=${e(this.secret.base32)}&algorithm=${e(this.algorithm)}&digits=${e(this.digits)}&period=${e(this.period)}`;
57821
- }
57822
- };
57823
-
57824
- // packages/sdk/otp.js
57277
+ return false;
57278
+ }
57825
57279
  var OTP = class {
57826
57280
  constructor(secret) {
57827
- const options = {
57281
+ this.options = {
57828
57282
  issuer: "Autho",
57829
57283
  label: secret.name,
57830
57284
  algorithm: "SHA1",
@@ -57832,13 +57286,12 @@ var OTP = class {
57832
57286
  period: 30,
57833
57287
  secret: secret.value
57834
57288
  };
57835
- this.totp = new TOTP(options);
57836
57289
  }
57837
57290
  generate() {
57838
- return this.totp.generate();
57291
+ return generateTOTP(this.options.secret);
57839
57292
  }
57840
57293
  validate(token, window2 = 1) {
57841
- return this.totp.validate({ token, window: window2 });
57294
+ return verifyTOTP(this.options.secret, token, window2);
57842
57295
  }
57843
57296
  };
57844
57297
 
@@ -57873,7 +57326,7 @@ var createSecretSchema = import_joi.default.object({
57873
57326
  });
57874
57327
 
57875
57328
  // packages/sdk/cipher.js
57876
- var import_crypto = __toESM(require("crypto"), 1);
57329
+ var import_crypto2 = __toESM(require("crypto"), 1);
57877
57330
  var import_fs = __toESM(require("fs"), 1);
57878
57331
  var import_path = __toESM(require("path"), 1);
57879
57332
  var import_zlib = __toESM(require("zlib"), 1);
@@ -57894,12 +57347,12 @@ var config_default = {
57894
57347
  // packages/sdk/cipher.js
57895
57348
  var Cipher = class _Cipher {
57896
57349
  static hash(text, algorithm = config_default.hashAlgo, encoding = "hex") {
57897
- const hash = import_crypto.default.createHash(algorithm);
57350
+ const hash = import_crypto2.default.createHash(algorithm);
57898
57351
  hash.update(text);
57899
57352
  return hash.digest(encoding);
57900
57353
  }
57901
57354
  static random(size = config_default.randomSize) {
57902
- const rnd = import_crypto.default.randomBytes(size);
57355
+ const rnd = import_crypto2.default.randomBytes(size);
57903
57356
  return rnd;
57904
57357
  }
57905
57358
  static randomString(encoding = "hex") {
@@ -57922,7 +57375,7 @@ var Cipher = class _Cipher {
57922
57375
  encoding = "hex"
57923
57376
  }) {
57924
57377
  const publicKey = _Cipher.randomString();
57925
- let cipher = import_crypto.default.createCipheriv(
57378
+ let cipher = import_crypto2.default.createCipheriv(
57926
57379
  algorithm,
57927
57380
  Buffer.from(encryptionKey, encoding),
57928
57381
  Buffer.from(publicKey, encoding),
@@ -57953,7 +57406,7 @@ var Cipher = class _Cipher {
57953
57406
  encoding = "hex"
57954
57407
  }) {
57955
57408
  value = Buffer.from(value, encoding);
57956
- let decipher = import_crypto.default.createDecipheriv(
57409
+ let decipher = import_crypto2.default.createDecipheriv(
57957
57410
  algorithm,
57958
57411
  Buffer.from(encryptionKey, encoding),
57959
57412
  Buffer.from(publicKey, encoding),
@@ -58098,6 +57551,8 @@ var Secrets = class {
58098
57551
  return this.secrets.find((secret) => secret.id == id);
58099
57552
  }
58100
57553
  async add(secret, encryptionKey) {
57554
+ secret.createdAt = /* @__PURE__ */ new Date();
57555
+ secret.id = Cipher.randomString();
58101
57556
  const { value, error } = createSecretSchema.validate(secret);
58102
57557
  if (error) {
58103
57558
  throw new Error(error);
@@ -59656,7 +59111,8 @@ var createSecret = async (secret, app) => {
59656
59111
  typeOptions: {
59657
59112
  username: secret.username,
59658
59113
  digits: secret.digits,
59659
- description: secret.description
59114
+ description: secret.description,
59115
+ algorithm: secret.algorithm
59660
59116
  }
59661
59117
  };
59662
59118
  created = await app.secrets.add(newSecret, app.encryptionKey);
package/package.json CHANGED
@@ -1,11 +1,25 @@
1
1
  {
2
2
  "name": "autho",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "main": "build/bin.js",
5
5
  "type": "commonjs",
6
6
  "bin": {
7
7
  "autho": "build/bin.js"
8
8
  },
9
+ "scripts": {
10
+ "format": "prettier --check .",
11
+ "format:write": "prettier --write .",
12
+ "lint": "eslint .",
13
+ "lint:fix": "eslint --fix .",
14
+ "build": "esbuild packages/cli/bin.js --bundle --platform=node --target=node18 --outdir=build",
15
+ "pkg": "npm run pkg:linux && npm run pkg:macos && npm run pkg:win",
16
+ "pkg:macos-arm64": "pkg build/bin.js --output dist/autho --target node18-macos-arm64",
17
+ "pkg:macos": "pkg build/bin.js --output dist/autho-macos --target node18-macos-x64",
18
+ "pkg:linux": "pkg build/bin.js --output dist/autho-linux --target node18-linux-x64",
19
+ "pkg:win": "pkg build/bin.js --output dist/autho-win --target node18-win-x64 --win portable",
20
+ "semantic-release": "semantic-release",
21
+ "release": "gh release create v0.0.10 './dist/autho*' --title 'v0.0.10' --generate-notes --prerelease"
22
+ },
9
23
  "keywords": [
10
24
  "secrets",
11
25
  "otp"
@@ -39,19 +53,5 @@
39
53
  "node18-macos-x64"
40
54
  ],
41
55
  "outputPath": "dist"
42
- },
43
- "scripts": {
44
- "format": "prettier --check .",
45
- "format:write": "prettier --write .",
46
- "lint": "eslint .",
47
- "lint:fix": "eslint --fix .",
48
- "build": "esbuild packages/cli/bin.js --bundle --platform=node --target=node18 --outdir=build",
49
- "pkg": "npm run pkg:linux && npm run pkg:macos && npm run pkg:win",
50
- "pkg:macos-arm64": "pkg build/bin.js --output dist/autho --target node18-macos-arm64",
51
- "pkg:macos": "pkg build/bin.js --output dist/autho-macos --target node18-macos-x64",
52
- "pkg:linux": "pkg build/bin.js --output dist/autho-linux --target node18-linux-x64",
53
- "pkg:win": "pkg build/bin.js --output dist/autho-win --target node18-win-x64 --win portable",
54
- "semantic-release": "semantic-release",
55
- "release": "gh release create v0.0.10 './dist/autho*' --title 'v0.0.10' --generate-notes --prerelease"
56
56
  }
57
57
  }