@@ -108,7 +108,7 @@ export type SessionParams = {
108
108
109
109
export type EncryptionKeys = {
110
110
dataKey : Uint8Array ;
111
- privateKey : Uint8Array ;
111
+ privateKey ? : Uint8Array ;
112
112
eccPrivateKey : Uint8Array ;
113
113
}
114
114
@@ -995,8 +995,12 @@ export class Auth {
995
995
}
996
996
}
997
997
if ( ! encryptedPrivateKey || ! encryptedEccPrivateKey ) {
998
- encryptedPrivateKey = this . accountSummary ?. keysInfo ?. encryptedPrivateKey || undefined
999
- encryptedEccPrivateKey = this . accountSummary ?. keysInfo ?. encryptedEccPrivateKey || undefined
998
+ // protobuf embeds the unit8array into the prototype of this.accountSummary.keysInfo, check for length as well
999
+ const encryptedPrivateKeyUint8 = this . accountSummary ?. keysInfo ?. encryptedPrivateKey || undefined
1000
+ const encryptedEccPrivateKeyUint8 = this . accountSummary ?. keysInfo ?. encryptedEccPrivateKey || undefined
1001
+ encryptedPrivateKey = encryptedPrivateKeyUint8 ?. length ? encryptedPrivateKeyUint8 : undefined
1002
+ encryptedEccPrivateKey = encryptedEccPrivateKeyUint8 ?. length ? encryptedEccPrivateKeyUint8 : undefined
1003
+
1000
1004
if ( this . options . kvs ) {
1001
1005
if ( encryptedPrivateKey ) {
1002
1006
this . options . kvs . saveValue ( `${ this . _username } /private_key` , platform . bytesToBase64 ( encryptedPrivateKey ) )
@@ -1212,14 +1216,33 @@ export class Auth {
1212
1216
}
1213
1217
}
1214
1218
1215
- public getKeys ( ) : EncryptionKeys {
1216
- if ( ! this . dataKey || ! this . privateKey || ! this . eccPrivateKey ) {
1217
- throw Error ( 'Encryption keys are missing' )
1218
- }
1219
- return {
1220
- dataKey : this . dataKey ,
1221
- privateKey : this . privateKey ,
1222
- eccPrivateKey : this . eccPrivateKey
1219
+ public getKeys ( ecOnly ?:boolean ) : EncryptionKeys {
1220
+ if ( ecOnly ) {
1221
+ if ( ! this . dataKey || ! this . eccPrivateKey ) {
1222
+ throw Error ( 'Encryption keys are missing' )
1223
+ }
1224
+
1225
+ if ( this . privateKey ) {
1226
+ return {
1227
+ dataKey : this . dataKey ,
1228
+ privateKey : this . privateKey ,
1229
+ eccPrivateKey : this . eccPrivateKey
1230
+ }
1231
+ } else {
1232
+ return {
1233
+ dataKey : this . dataKey ,
1234
+ eccPrivateKey : this . eccPrivateKey
1235
+ }
1236
+ }
1237
+ } else {
1238
+ if ( ! this . dataKey || ! this . privateKey || ! this . eccPrivateKey ) {
1239
+ throw Error ( 'Encryption keys are missing' )
1240
+ }
1241
+ return {
1242
+ dataKey : this . dataKey ,
1243
+ privateKey : this . privateKey ,
1244
+ eccPrivateKey : this . eccPrivateKey
1245
+ }
1223
1246
}
1224
1247
}
1225
1248
0 commit comments