fix: let tests run without requiring 'dom' among typescript's libs
Massimo Melina committed
Aug 29, 2022 at 14:44 UTC
07531fb8be5bf8928053b80fd57657384c6adff0
3 files changed
+16
-14
shared/src/index.ts
+1
-13
@@ -1,9 +1,9 @@
1
// This file is part of HFS - Copyright 2021-2022, Massimo Melina <a@rejetto.com> - License https://www.gnu.org/licenses/gpl-3.0.txt
2
3
import _ from 'lodash'
4
-import { SRPClientSession, SRPParameters, SRPRoutines } from 'tssrp6a'
4
export * from './react'
5
export * from './dialogs'
6
+export * from './srp'
7
8
export type Dict<T=any> = Record<string, T>
9
export type Falsy = false | null | undefined | '' | 0
@@ -72,15 +72,3 @@ export function setHidden(dest: object, src:object) {
72
})))
73
}
74
75
-export async function srpSequence(username:string, password:string, apiCall: (cmd:string, params:any) => any) {
76
- const { pubKey, salt } = await apiCall('loginSrp1', { username })
77
- if (!salt) throw Error('salt')
78
- const srp6aNimbusRoutines = new SRPRoutines(new SRPParameters())
79
- const srp = new SRPClientSession(srp6aNimbusRoutines);
80
- const resStep1 = await srp.step1(username, password)
81
- const resStep2 = await resStep1.step2(BigInt(salt), BigInt(pubKey))
82
- const res = await apiCall('loginSrp2', { pubKey: String(resStep2.A), proof: String(resStep2.M1) }) // bigint-s must be cast to string to be json-ed
83
- await resStep2.step3(BigInt(res.proof)).catch(() => Promise.reject('trust'))
84
- return res
85
-}
86
-
shared/src/srp.ts
new
+14
@@ -0,0 +1,14 @@
1
+import { SRPClientSession, SRPParameters, SRPRoutines } from 'tssrp6a'
2
+
3
+export async function srpSequence(username:string, password:string, apiCall: (cmd:string, params:any) => any) {
4
+ const { pubKey, salt } = await apiCall('loginSrp1', { username })
5
+ if (!salt) throw Error('salt')
6
+ const srp6aNimbusRoutines = new SRPRoutines(new SRPParameters())
7
+ const srp = new SRPClientSession(srp6aNimbusRoutines);
8
+ const resStep1 = await srp.step1(username, password)
9
+ const resStep2 = await resStep1.step2(BigInt(salt), BigInt(pubKey))
10
+ const res = await apiCall('loginSrp2', { pubKey: String(resStep2.A), proof: String(resStep2.M1) }) // bigint-s must be cast to string to be json-ed
11
+ await resStep2.step3(BigInt(res.proof)).catch(() => Promise.reject('trust'))
12
+ return res
13
+}
14
+
tests/test.ts
+1
-1
@@ -2,7 +2,7 @@ import axios from 'axios'
2
import { wrapper } from 'axios-cookiejar-support'
3
import { CookieJar } from 'tough-cookie'
4
import { Done } from 'mocha'
5
-import { srpSequence } from '@hfs/shared/src'
5
+import { srpSequence } from '@hfs/shared/src/srp'
6
/*
7
import { PORT, srv } from '../src'
8