Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Th fix ec issues #63

Merged
merged 2 commits into from
Nov 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion keeperapi/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@keeper-security/keeperapi",
"description": "Keeper API Javascript SDK",
"version": "16.0.65",
"version": "16.0.66",
"browser": "dist/index.es.js",
"main": "dist/index.cjs.js",
"types": "dist/node/index.d.ts",
45 changes: 34 additions & 11 deletions keeperapi/src/auth.ts
Original file line number Diff line number Diff line change
@@ -108,7 +108,7 @@ export type SessionParams = {

export type EncryptionKeys = {
dataKey: Uint8Array;
privateKey: Uint8Array;
privateKey?: Uint8Array;
eccPrivateKey: Uint8Array;
}

@@ -995,8 +995,12 @@ export class Auth {
}
}
if (!encryptedPrivateKey || !encryptedEccPrivateKey) {
encryptedPrivateKey = this.accountSummary?.keysInfo?.encryptedPrivateKey || undefined
encryptedEccPrivateKey = this.accountSummary?.keysInfo?.encryptedEccPrivateKey || undefined
// protobuf embeds the unit8array into the prototype of this.accountSummary.keysInfo, check for length as well
const encryptedPrivateKeyUint8 = this.accountSummary?.keysInfo?.encryptedPrivateKey || undefined
const encryptedEccPrivateKeyUint8 = this.accountSummary?.keysInfo?.encryptedEccPrivateKey || undefined
encryptedPrivateKey = encryptedPrivateKeyUint8?.length ? encryptedPrivateKeyUint8 : undefined
encryptedEccPrivateKey = encryptedEccPrivateKeyUint8?.length ? encryptedEccPrivateKeyUint8 : undefined

if (this.options.kvs) {
if (encryptedPrivateKey) {
this.options.kvs.saveValue(`${this._username}/private_key`, platform.bytesToBase64(encryptedPrivateKey))
@@ -1212,14 +1216,33 @@ export class Auth {
}
}

public getKeys(): EncryptionKeys {
if (!this.dataKey || !this.privateKey || !this.eccPrivateKey) {
throw Error('Encryption keys are missing')
}
return {
dataKey: this.dataKey,
privateKey: this.privateKey,
eccPrivateKey: this.eccPrivateKey
public getKeys(ecOnly?:boolean): EncryptionKeys {
if(ecOnly){
if (!this.dataKey || !this.eccPrivateKey) {
throw Error('Encryption keys are missing')
}

if(this.privateKey){
return {
dataKey: this.dataKey,
privateKey: this.privateKey,
eccPrivateKey: this.eccPrivateKey
}
} else {
return {
dataKey: this.dataKey,
eccPrivateKey: this.eccPrivateKey
}
}
} else {
if (!this.dataKey || !this.privateKey || !this.eccPrivateKey) {
throw Error('Encryption keys are missing')
}
return {
dataKey: this.dataKey,
privateKey: this.privateKey,
eccPrivateKey: this.eccPrivateKey
}
}
}