@opendatalabs/vana-sdk
Version:
A TypeScript library for interacting with Vana Network smart contracts.
46 lines (45 loc) • 1.9 kB
TypeScript
/**
* HKDF-based key derivation for the Vana Data Portability Protocol.
*
* @remarks
* Ported verbatim from `personal-server-ts` (`packages/core/src/keys/derive.ts`)
* to keep wire compatibility with the locked DPv1 encryption scheme. The wallet
* signature over `"vana-master-key-v1"` IS the master key material (spec §2.3),
* and per-scope keys are derived via HKDF-SHA256 with `salt="vana"` and
* `info="scope:{scope}"`.
*
* @category Cryptography
*/
/**
* Canonical message signed by the user's wallet to derive the master key.
*
* @remarks
* NOTE: kept in sync with personal-server-ts. The Vana team's encryption design
* doc references `"vana-master-encryption-v1"`; this implementation uses the
* shipping value to preserve wire compatibility.
*/
export declare const MASTER_KEY_MESSAGE = "vana-master-key-v1";
/**
* Extracts master key material from an EIP-191 signature over the master key
* message. The raw 65 signature bytes ARE the master key material.
*
* @param signature - 0x-prefixed hex string (65 bytes = 130 hex chars + 0x).
* @returns 65-byte Uint8Array containing the raw signature bytes.
*/
export declare function deriveMasterKey(signature: `0x${string}`): Uint8Array;
/**
* Recovers the server owner address from a master key signature using EIP-191
* recovery over {@link MASTER_KEY_MESSAGE}.
*/
export declare function recoverServerOwner(masterKeySignature: `0x${string}`): Promise<`0x${string}`>;
/**
* Derives a scope-specific 32-byte key via HKDF-SHA256.
*
* @remarks
* Uses `salt="vana"` and `info="scope:{scope}"` per spec §2.3.
*
* @param masterKey - 65-byte master key material from {@link deriveMasterKey}.
* @param scope - Scope identifier (e.g. `"instagram.profile"`).
* @returns 32-byte derived key suitable for symmetric encryption.
*/
export declare function deriveScopeKey(masterKey: Uint8Array, scope: string): Uint8Array;