mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-26 02:11:53 +00:00
feat: lazy loading node-jose (#2177)
This commit is contained in:
committed by
Aiden McClelland
parent
3c0a82293c
commit
efb318a979
@@ -2,5 +2,6 @@
|
||||
"singleQuote": true,
|
||||
"semi": false,
|
||||
"arrowParens": "avoid",
|
||||
"trailingComma": "all"
|
||||
"trailingComma": "all",
|
||||
"htmlWhitespaceSensitivity": "ignore"
|
||||
}
|
||||
|
||||
@@ -4,20 +4,24 @@ import { RR, Encrypted } from './api.types'
|
||||
import { DataModel } from 'src/app/services/patch-db/data-model'
|
||||
import { Log } from '@start9labs/shared'
|
||||
import { WebSocketSubjectConfig } from 'rxjs/webSocket'
|
||||
import * as jose from 'node-jose'
|
||||
import type { JWK } from 'node-jose'
|
||||
|
||||
export abstract class ApiService {
|
||||
protected readonly jose = import('node-jose')
|
||||
|
||||
readonly patchStream$ = new BehaviorSubject<Update<DataModel>[]>([])
|
||||
pubkey?: jose.JWK.Key
|
||||
pubkey?: JWK.Key
|
||||
|
||||
async encrypt(toEncrypt: string): Promise<Encrypted> {
|
||||
if (!this.pubkey) throw new Error('No pubkey found!')
|
||||
const encrypted = await jose.JWE.createEncrypt(this.pubkey!)
|
||||
.update(toEncrypt)
|
||||
.final()
|
||||
return {
|
||||
encrypted,
|
||||
}
|
||||
const { pubkey } = this
|
||||
|
||||
if (!pubkey) throw new Error('No pubkey found!')
|
||||
|
||||
const encrypted = await this.jose.then(jose =>
|
||||
jose.JWE.createEncrypt(pubkey).update(toEncrypt).final(),
|
||||
)
|
||||
|
||||
return { encrypted }
|
||||
}
|
||||
|
||||
// http
|
||||
|
||||
@@ -38,7 +38,6 @@ import { WebSocketSubjectConfig } from 'rxjs/webSocket'
|
||||
import { AuthService } from '../auth.service'
|
||||
import { ConnectionService } from '../connection.service'
|
||||
import { StoreInfo } from '@start9labs/marketplace'
|
||||
import * as jose from 'node-jose'
|
||||
|
||||
const PROGRESS: InstallProgress = {
|
||||
size: 120,
|
||||
@@ -122,12 +121,14 @@ export class MockApiService extends ApiService {
|
||||
// this.pubkey = await keystore.generate('EC', 'P-256')
|
||||
|
||||
// generated from backend
|
||||
this.pubkey = await jose.JWK.asKey({
|
||||
kty: 'EC',
|
||||
crv: 'P-256',
|
||||
x: 'yHTDYSfjU809fkSv9MmN4wuojf5c3cnD7ZDN13n-jz4',
|
||||
y: '8Mpkn744A5KDag0DmX2YivB63srjbugYZzWc3JOpQXI',
|
||||
})
|
||||
this.pubkey = await this.jose.then(jose =>
|
||||
jose.JWK.asKey({
|
||||
kty: 'EC',
|
||||
crv: 'P-256',
|
||||
x: 'yHTDYSfjU809fkSv9MmN4wuojf5c3cnD7ZDN13n-jz4',
|
||||
y: '8Mpkn744A5KDag0DmX2YivB63srjbugYZzWc3JOpQXI',
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
async login(params: RR.LoginReq): Promise<RR.loginRes> {
|
||||
|
||||
Reference in New Issue
Block a user