Skip to content

feat(sdk-api): add v2 encrypt/decrypt using Argon2id#8495

Open
pranavjain97 wants to merge 4 commits intomasterfrom
WCN-30-v2-encrypt-decrypt
Open

feat(sdk-api): add v2 encrypt/decrypt using Argon2id#8495
pranavjain97 wants to merge 4 commits intomasterfrom
WCN-30-v2-encrypt-decrypt

Conversation

@pranavjain97
Copy link
Copy Markdown
Contributor

Add encryptV2() and decryptV2() alongside existing v1 SJCL functions. V2 uses Argon2id (m=64MiB, t=3, p=4) for KDF and WebCrypto AES-256-GCM for symmetric encryption. Self-describing JSON envelope stores all parameters for forward compatibility.

Existing v1 encrypt/decrypt is untouched. No call site changes.

@pranavjain97 pranavjain97 requested review from a team as code owners April 13, 2026 20:52
@linear
Copy link
Copy Markdown

linear bot commented Apr 13, 2026

@pranavjain97 pranavjain97 force-pushed the WCN-29-vendor-hash-wasm branch from dfae16d to 0b1a2ad Compare April 13, 2026 21:33
@pranavjain97 pranavjain97 requested review from a team as code owners April 14, 2026 17:01
@pranavjain97 pranavjain97 force-pushed the WCN-30-v2-encrypt-decrypt branch from 597e548 to c111d99 Compare April 14, 2026 17:09
Comment thread modules/sdk-api/src/bitgoAPI.ts
Comment thread modules/sdk-api/src/encrypt.ts Outdated
@pranavjain97 pranavjain97 changed the base branch from WCN-29-vendor-hash-wasm to master April 14, 2026 18:25
*/
export async function decryptAsync(password: string, ciphertext: string): Promise<string> {
try {
const envelope = JSON.parse(ciphertext);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

worth io-ts decoding?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not really, its an internal format we produce, not external input

Comment thread modules/sdk-api/src/encrypt.ts Outdated
Comment thread modules/sdk-core/src/bitgo/bitgoBase.ts
@pranavjain97 pranavjain97 force-pushed the WCN-30-v2-encrypt-decrypt branch 5 times, most recently from b816e65 to a9be0b8 Compare April 15, 2026 19:18
async function deriveKeyV2(
password: string,
salt: Uint8Array,
params: { memorySize: number; iterations: number; parallelism: number }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

m, t, and p are read from the parsed JSON envelope and passed straight into Argon2 with no caps. Because ciphertext is often untrusted, an attacker could set huge parameters and force excessive CPU/memory work on every decrypt attempt. Can we enforce maximum allowed values here?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The structure and valid values could easily be encoded in an io-ts codec.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, added io-ts codec for this

@pranavjain97 pranavjain97 force-pushed the WCN-30-v2-encrypt-decrypt branch 3 times, most recently from f05550c to 15275f9 Compare April 16, 2026 19:41
@pranavjain97 pranavjain97 requested a review from mrdanish26 April 16, 2026 20:04
Add encryptV2() and decryptV2() alongside existing v1 SJCL functions.
V2 uses Argon2id (m=64MiB, t=3, p=4) for KDF and WebCrypto AES-256-GCM
for symmetric encryption. Self-describing JSON envelope stores all
parameters for forward compatibility.

Existing v1 encrypt/decrypt is untouched. No call site changes.

WCN-30

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

TICKET: WCN-30
Add decryptAsync() that auto-detects v1 (SJCL) or v2 (Argon2id)
envelopes. This is the non-breaking migration path for clients to
move from sync decrypt() to async before the breaking release.

- decryptAsync() on encrypt.ts and BitGoAPI
- decryptAsync on BitGoBase interface
- Tests for v1 and v2 auto-detection, wrong password rejection

WCN-30

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

TICKET: WCN-30
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

TICKET: WCN-30
Replace hand-written if-checks and V2Envelope interface with a
V2EnvelopeCodec that enforces type safety, Argon2id parameter caps,
and non-empty base64 strings in a single decode step.

WCN-30

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

TICKET: WCN-30
@pranavjain97 pranavjain97 force-pushed the WCN-30-v2-encrypt-decrypt branch from 15275f9 to f4ae573 Compare April 16, 2026 21:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants