functionland / fula-archived

Client-server stack for Web3! Turn your Raspberry Pi to a BAS server in minutes and enjoy the freedom of decentralized Web with a superior user experience!
https://fx.land
MIT License
4 stars 0 forks source link

Fula-sec taged-encryption #229

Closed farhoud closed 2 years ago

farhoud commented 2 years ago

In Document and Typing of tagged encryption:

     /**
     * This function encrtps user`s CID and shared symetric keys
     * @function encrypt()
     * @property symetricKey: string, CID: string, didAudience: array
     * @returns  jwe {}
     */
    async encrypt(symetricKey: string, CID: string, didAudience: Array<string>): Promise<any> {
        return await this._did.createDagJWE({ symetricKey: symetricKey,  CID: CID}, didAudience)
    }

    /**
     * This function encrtps user`s CID and shared symetric keys
     * @function decrypt()
     * @property jwe {}
     * @returns  decrypted message {symetricKey: string, CID: string}
     */
    async decrypt(jwe: any): Promise<any>  {
        return await this._did.decryptDagJWE(jwe);
    }

symetricKey is String but in example/gallery/fula-sec/react-app

symetricKey is an object

      const tagged = new TaggedEncryption(userDID?.did)

      let plaintext = {
        symmetricKey: key,
        CID: cid
      }
      let jwe = await tagged?.encrypt(plaintext.symmetricKey, plaintext.CID, [userDID?.did?.id])
mehdibalouchi commented 2 years ago

I am also facing an issue that may be related. Here is what I do:

In the browser's log, I get this error:

encrypted photo
App.js:53 Error: failure: Failed to decrypt
    at RPCError.fromObject (index.js:34346:1)
    at index.js:34440:1
    at async DID.decryptJWE (index.js:42067:1)
    at async DID.decryptDagJWE (index.js:42075:1)
    at async TaggedEncryption.decrypt (index.js:52329:1)
    at async App.js:51:1

The line is referring to App.js:

plainObject = await tagged.decrypt(jwe)