Closed gz1992 closed 1 year ago
@gz1992 Hello again! Will check this!
@gz1992 Can you share imports and Ehtree initilize line?
Off course @rstp-god ... assuming I have no problem initializing my EThree (as it is in my case), the flow is as follow:
import {EThree} from '@virgilsecurity/e3kit-native';
import AsyncStorage from '@react-native-async-storage/async-storage';
import {ICard} from 'virgil-sdk';
class ClassExample {
userPublicKey: ICard | null;
recipientPublicKey: ICard | null;
eThree: undefined | EThree;
myuserid: string | undefined;
receiveruserid: string | undefined;
constructor() {
this.userPublicKey = null;
this.recipientPublicKey = null;
}
initialize = async (myuserid: string) => {
const initializeFunction = () => getJwtVirgilTokenOnMyBackend(myuserid);
const eThree = await EThree.initialize(initializeFunction, {AsyncStorage});
this.eThree = eThree;
};
getEThree = () => {
if (!this.eThree) {
throw new Error('eThree not initialized ');
}
return this.eThree;
};
}
const instanced = new ClassExample();
await instanced.initialize();
const eThree = await instanced.getEthree();
const hasLocalPrivateKey = await eThree.hasLocalPrivateKey();
Hello @gz1992 ! Can not reproduce this, can you send more info about public key initialization and some test case ?
Hey @rstp-god , thanks for your time. While I look into, can you show me how should I be doing?
@gz1992
Hello again, some solutions here:
Thanks, @rstp-god , i was using the url above as example, in my code i tryed 2 things:
1- On registering, like alice and bob example, i got this error:
import {EThree} from '@virgilsecurity/e3kit-native';
import AsyncStorage from '@react-native-async-storage/async-storage';
const initializeFunction = () => getJwtVirgilTokenOnMyBackend(myuserid);
const alice = await EThree.initialize(initializeFunction, {AsyncStorage});
console.log('Alice registering');
await alice.register();
LOG Alice registering
LOG ERROR ENCRYPT [IdentityAlreadyExistsError: This identity is already registered on Virgil Cloud. To load private key use EThree.restorePrivateKey or EThree.rotatePrivateKey]
2- So I tryed removing and rotating my privateKey, as it is as test, i can remove...
import {EThree} from '@virgilsecurity/e3kit-native';
import AsyncStorage from '@react-native-async-storage/async-storage';
const initializeFunction = () => getJwtVirgilTokenOnMyBackend(myuserid);
const alice = await EThree.initialize(initializeFunction, {AsyncStorage});
console.log('Alice cleaningup');
await alice.cleanup();
console.log('Alice registers...');
await alice.rotatePrivateKey();
the result
LOG Alice cleaningup
LOG Alice registers...
LOG Alice creates private key backup...
LOG ERROR ENCRYPT [Error: Exception in HostFunction: com.virgilsecurity.crypto.pythia.PythiaException: Underlying pythia library returns -1.]
If I ignore this error, i am going to the same of the issue title [TypeError: Argument "virgilPublicKey" must be a VirgilPublicKey object], the backup also keeps breaking...
Does it helps?
@gz1992
Hello, does you try to push publicKey.publicKey inside encrypt function?
Hey, @rstp-god , as you can see In my response above, I get problems registering my Alice key. But if I ignore the registers error above and go through the process using the findUser that returns my necessary publicKey, I get:
import {EThree} from '@virgilsecurity/e3kit-native';
import AsyncStorage from '@react-native-async-storage/async-storage';
const initializeFunction = () => getJwtVirgilTokenOnMyBackend(myuserid);
const alice = await EThree.initialize(initializeFunction, {AsyncStorage});
await alice.register();
const publicKey = await alice.findUsers(bob.identity);
alice.encrypt(text, publicKey);
On encrypt I get this log:
LOG [TypeError: Argument "virgilPublicKey" must be a VirgilPublicKey object]
If it show better:
import {EThree} from '@virgilsecurity/e3kit-native';
import AsyncStorage from '@react-native-async-storage/async-storage';
const initializeFunction = () => getMyJWTTOken(aliceUserId);
const alice = await EThree.initialize(initializeFunction, {
AsyncStorage,
});
console.log('Alice registering');
// await alice.register(); // AS MY REGISTER WAS GIVING AN ERROR, I CLEANUP AND ROTATEPRIVATEKEY
console.log('Alice cleaningup');
await alice.cleanup();
console.log('Alice registers...');
await alice.rotatePrivateKey();
console.log("Alice searches for Bob's card...");
const bobCard = await alice.findUsers(bobUserId);
const encryptedForBob = await alice.encrypt(
text,
bobCard,
);
My log is here:
LOG Alice registering
LOG Alice cleaningup
LOG Alice registers...
LOG Alice searches for Bob's card...
LOG ERROR ENCRYPT [TypeError: Argument "virgilPublicKey" must be a VirgilPublicKey object]
If it helps, my decrypt function is working fine
alice.decrypt(text, senderPublicKey);
@rstp-god , hey man.. i've been testing, and i've brought some things that might help you reproduce in your enviroment my problem..
1- we developed this project, in 2019, or 2020, and we used as package.json:
"react": "16.11.0",
"react-native": "0.62.3",
"@react-native-community/async-storage": "^1.12.1",
"@virgilsecurity/e3kit": "^0.7.0-beta.2",
"@virgilsecurity/key-storage-rn": "^0.2.1",
"react-native-virgil-crypto": "^0.6.1",
In this 2023 version, i get this packages
"react": "18.1.0",
"react-native": "0.70.6",
"@react-native-async-storage/async-storage": "^1.17.11",
"@virgilsecurity/e3kit-native": "^2.5.3",
"@virgilsecurity/key-storage-rn": "^1.0.0",
"react-native-virgil-crypto": "^0.6.2",
async-storage has changed to a different package, so i am not sure if it is a problem...
2- As you can see, I updated all packages from virgil, maybe you could create this interaction with the old one and trying to reuse it on the new and updated virgil
3- Our (bob and alice, as the example shows) identity is a "fixed" valued, but if we restore all privatekeys this will be a big problem, eheheh.
4- What is this VirgilPublicKey object? because in the bobCard example, i get this card:
{"contentSnapshot": "{\"identity\":\"something\",\"created_at\":1580172985,\"version\":\"5.0\",\"public_key\":\"my_public_key\"}", "createdAt": 2020-01-28T00:56:25.000Z, "id": "my_id", "identity": "my_identity", "isOutdated": false, "previousCardId": undefined, "publicKey": {"identifier": [Object], "value": "my_public_key"}, "signatures": [{"extraFields": [Object], "signature": "a_signature", "signer": "self", "snapshot": undefined}, {"extraFields": [Object], "signature": "another_signature", "signer": "virgil", "snapshot": undefined}], "version": "5.0"}
is it a wrong type?
Thanks again for the support!
@gz1992 Hello! Did your prev version working fine? As i see bob card is fine in your comment, like in example i think. I will try to reproduce with this information, and send you some feedback with result!
@rstp-god , hey!!! Yep, in previous version i have no problema encrypting and decrypting... But the new one i cant encrypt msgs
@gz1992 Hello! I think i have some answer, for you! I'am again check your bob card, and bob card from node example and my bobcard do not have value inside, may be some update issues, i will check it, and relese patch if it needed!
NICE!!! Very good news @rstp-god
hey @rstp-god , is everything all right? Do you need anything?
@gz1992 Hello! relese 2.5.3 on npm just today. try this for errors if still having this issue, will check again )
more good news!!!
@gz1992 How this goes? Working fine ?
@rstp-god , finishing all tests, for now seems awesome
@rstp-god , all good!!!!! If I have anything, I will create another issue!
Describe the bug Hey guys, me again, kkkk. In my program, we send and receive msgs. This msgs are encrypted by virgil. I can easily decrypt those already encrypted msgs (using my publickey), but when I try to send a new one and encrypt i get this error on the title.
To Reproduce Steps to reproduce the behavior, using my encrypt function as example:
1- If I have a text = 'Virgil is awesome' 2- My publickey is: publickey = {"contentSnapshot": "{\"identity\":\"something\",\"created_at\":1635275449,\"version\":\"5.0\",\"public_key\":\"something2\"}", "createdAt": 2021-10-26T19:10:49.000Z, "id": "something3", "identity": "something", "isOutdated": false, "previousCardId": undefined, "publicKey": {"identifier": [Object], "value": "something4"}, "signatures": [{"extraFields": [Object], "signature": "something5", "signer": "self", "snapshot": undefined}, {"extraFields": [Object], "signature": "something6", "signer": "virgil", "snapshot": undefined}], "version": "5.0"} 3- Calling my encryptText(text, publickey) 4- I get the title error [TypeError: Argument "virgilPublicKey" must be a VirgilPublicKey object]
Expected behavior I would get my response from return encryptedText; with my text encrypted in it
Smartphone (please complete the following information):
Additional context My package.json: