Skip to content

[FEATURE] : Implement Crypto Utilities Package #28

@wheval

Description

@wheval

Implement Crypto Utilities Package

Description:
Implement @ancore/crypto with key generation, mnemonic support, encryption/decryption, and transaction signing. This is security-critical — keys must never leave the device.

Context:
The package is currently a stub (CRYPTO_VERSION export only). Dependencies @noble/ed25519 and @noble/hashes are already in package.json. The wallet needs this for onboarding (mnemonic generation), key storage (encryption), and transaction signing.

Requirements:

  • Implement generateMnemonic() — BIP39 12-word mnemonic
  • Implement validateMnemonic(mnemonic) — validate BIP39 mnemonic
  • Implement deriveKeypairFromMnemonic(mnemonic, index) — derive Stellar keypair from mnemonic
  • Implement encryptSecretKey(secretKey, password) — AES-256-GCM encryption with PBKDF2 key derivation
  • Implement decryptSecretKey(encrypted, password) — decrypt stored secret key
  • Implement signTransaction(tx, keypair) — local transaction signing
  • Implement verifySignature(message, signature, publicKey)
  • Password strength validation
  • Secure random salt/IV generation per operation
  • Unit tests for all functions (100% coverage target)

Files to Create:

  • packages/crypto/src/mnemonic.ts
  • packages/crypto/src/encryption.ts
  • packages/crypto/src/signing.ts
  • packages/crypto/src/password.ts
  • packages/crypto/src/index.ts (update)
  • packages/crypto/src/__tests__/mnemonic.test.ts
  • packages/crypto/src/__tests__/encryption.test.ts
  • packages/crypto/src/__tests__/signing.test.ts

Dependencies:

  • @stellar/stellar-sdk
  • @noble/hashes
  • @noble/ed25519
  • bip39

Definition of Done:

  • All crypto functions implemented and exported
  • Encryption round-trip works (encrypt → decrypt = original)
  • Mnemonic → keypair derivation is deterministic
  • Tests pass with 100% coverage
  • No secret keys logged or transmitted

Labels: crypto, security, foundation, critical
Estimated Effort: 3–5 days
Priority: Critical — blocks account-abstraction and storage manager

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions