Vana SDK - v2.2.2
    Preparing search index...

    Interface ECIESProvider

    Provides ECIES encryption and decryption operations.

    Platform-specific implementations handle the underlying cryptographic primitives while maintaining consistent data format across environments.

    interface ECIESProvider {
        encrypt(
            publicKey: Uint8Array,
            message: Uint8Array,
        ): Promise<ECIESEncrypted>;
        decrypt(
            privateKey: Uint8Array,
            encrypted: ECIESEncrypted,
        ): Promise<Uint8Array<ArrayBufferLike>>;
        normalizeToUncompressed(publicKey: Uint8Array): Uint8Array;
    }
    Index

    Methods

    • Encrypts data using ECIES with secp256k1.

      Parameters

      • publicKey: Uint8Array

        Recipient's public key (65 bytes uncompressed or 33 bytes compressed). Obtain via vana.server.getIdentity(userAddress).public_key.

      • message: Uint8Array

        Data to encrypt.

      Returns Promise<ECIESEncrypted>

      Encrypted data structure compatible with eccrypto format.

      When public key is invalid. Verify key format matches secp256k1 requirements.

      const encrypted = await provider.encrypt(
      fromHex(publicKey, 'bytes'),
      new TextEncoder().encode('sensitive data')
      );
    • Decrypts ECIES encrypted data.

      Parameters

      • privateKey: Uint8Array

        Recipient's private key (32 bytes).

      • encrypted: ECIESEncrypted

        Encrypted data structure from encrypt() or legacy eccrypto.

      Returns Promise<Uint8Array<ArrayBufferLike>>

      Decrypted message as Uint8Array.

      When MAC verification fails. Ensure the private key matches the public key used for encryption.

      const decrypted = await provider.decrypt(
      fromHex(privateKey, 'bytes'),
      encrypted
      );
      const message = new TextDecoder().decode(decrypted);
    • Normalizes a public key to uncompressed format (65 bytes with 0x04 prefix).

      Parameters

      • publicKey: Uint8Array

        Public key in compressed or uncompressed format

      Returns Uint8Array

      Normalized uncompressed public key (65 bytes with 0x04 prefix)

      Strict policy: Only accepts properly formatted compressed (33 bytes) or uncompressed (65 bytes) public keys. Does not accept 64-byte raw coordinates to ensure data integrity and prevent masking of malformed inputs.

      When public key format is invalid, including raw coordinates (64 bytes)

      When decompression of compressed key fails

      // Compressed key (33 bytes)
      const compressed = new Uint8Array(33);
      compressed[0] = 0x02;
      const uncompressed = provider.normalizeToUncompressed(compressed);
      console.log(uncompressed.length); // 65
      console.log(uncompressed[0]); // 0x04

      // Already uncompressed (65 bytes)
      const already = provider.normalizeToUncompressed(uncompressedKey);
      console.log(already === uncompressedKey); // true (returns same reference)

      // Raw coordinates rejected (64 bytes)
      const raw = new Uint8Array(64);
      provider.normalizeToUncompressed(raw); // Throws error