-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #685 from xmtp/rygine/fix-encryption
Fix encryption dependency
- Loading branch information
Showing
50 changed files
with
236 additions
and
468 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@xmtp/content-type-remote-attachment": patch | ||
"@xmtp/xmtp-js": patch | ||
--- | ||
|
||
Fix encryption dependency |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions
4
shared/encryption/src/encryption.ts → ...e-attachment/src/encryption/encryption.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { ciphertext } from "@xmtp/proto"; | ||
|
||
export const AESKeySize = 32; // bytes | ||
export const KDFSaltSize = 32; // bytes | ||
// AES-GCM defaults from https://developer.mozilla.org/en-US/docs/Web/API/AesGcmParams | ||
export const AESGCMNonceSize = 12; // property iv | ||
export const AESGCMTagLength = 16; // property tagLength | ||
|
||
// Ciphertext packages the encrypted ciphertext with the salt and nonce used to produce it. | ||
// salt and nonce are not secret, and should be transmitted/stored along with the encrypted ciphertext. | ||
export default class Ciphertext implements ciphertext.Ciphertext { | ||
aes256GcmHkdfSha256: ciphertext.Ciphertext_Aes256gcmHkdfsha256 | undefined; | ||
|
||
constructor(obj: ciphertext.Ciphertext) { | ||
if (!obj.aes256GcmHkdfSha256) { | ||
throw new Error("invalid ciphertext"); | ||
} | ||
if (obj.aes256GcmHkdfSha256.payload.length < AESGCMTagLength) { | ||
throw new Error( | ||
`invalid ciphertext ciphertext length: ${obj.aes256GcmHkdfSha256.payload.length}`, | ||
); | ||
} | ||
if (obj.aes256GcmHkdfSha256.hkdfSalt.length !== KDFSaltSize) { | ||
throw new Error( | ||
`invalid ciphertext salt length: ${obj.aes256GcmHkdfSha256.hkdfSalt.length}`, | ||
); | ||
} | ||
if (obj.aes256GcmHkdfSha256.gcmNonce.length !== AESGCMNonceSize) { | ||
throw new Error( | ||
`invalid ciphertext nonce length: ${obj.aes256GcmHkdfSha256.gcmNonce.length}`, | ||
); | ||
} | ||
this.aes256GcmHkdfSha256 = obj.aes256GcmHkdfSha256; | ||
} | ||
|
||
toBytes(): Uint8Array { | ||
return ciphertext.Ciphertext.encode(this).finish(); | ||
} | ||
|
||
static fromBytes(bytes: Uint8Array): Ciphertext { | ||
return new Ciphertext(ciphertext.Ciphertext.decode(bytes)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/*********************************************************************************************** | ||
* DO NOT IMPORT THIS FILE DIRECTLY | ||
***********************************************************************************************/ | ||
const crypto = window.crypto; | ||
export default crypto; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { webcrypto } from "node:crypto"; | ||
|
||
const crypto = webcrypto; | ||
export default crypto; |
Oops, something went wrong.