@avalabs/crypto-sdk
v1.0.2
Published
Cross-platform crypto SDK facade. Re-exports a unified address-derivation API backed by @avalabs/crypto-nitro on React Native and @avalabs/crypto-wasm everywhere else. Consumers install only this package; the bundler picks the right backend via package.js
Downloads
3,578
Readme
@avalabs/crypto-sdk
Cross-platform crypto SDK facade. Exposes a single unified API for batched
address derivation; the bundler picks the right backend per platform via
package.json exports conditions — no Platform.OS checks in consumer code.
- React Native → routes to
@avalabs/crypto-nitro(native C++ via Nitro Modules) - Web / extension / Node → routes to
@avalabs/crypto-wasm(Emscripten WASM)
Install
You must install the wrapper for your target platform alongside this
package. The wrappers are declared as optional peer dependencies, so
npm/pnpm won't warn if you forget — but import from this package will
fail at runtime when the missing wrapper can't be resolved.
# React Native (iOS + Android)
pnpm add @avalabs/crypto-sdk @avalabs/crypto-nitro
# Browser / Chrome extension / Node
pnpm add @avalabs/crypto-sdk @avalabs/crypto-wasmCross-platform libraries that consume this SDK should re-declare the wrappers as optional peer deps so the choice propagates to the final app.
Usage
import {
init,
deriveAddressesFromXpubs,
deriveAddressesForEvm,
deriveAddressesForBtc,
deriveAddressesForSvm,
deriveAddressesForAvalanche,
} from '@avalabs/crypto-sdk';
// Required once before any derive*() call on the wasm backend.
// A no-op on the nitro backend, but always safe to call.
await init();
// Xpub-driven flow (Ledger / watch-only).
const rows = await deriveAddressesFromXpubs(
evmXpub,
avalancheXpubs,
/*isTestnet=*/ false,
/*accountIndices=*/ [0, 1, 2, 3, 4],
);
// Per-chain encoders — feed already-derived pubkeys.
const evmAddresses = await deriveAddressesForEvm(evmPubkeys);
const btcAddresses = await deriveAddressesForBtc(evmPubkeys, /*isTestnet=*/ false);
const svmAddresses = await deriveAddressesForSvm(ed25519Pubkeys);
const avaxBundles = await deriveAddressesForAvalanche(avaxPubkeys, evmPubkeys, false);See src/contract.ts for the full CryptoApi interface.
API surface
| Function | Input shape | Returns |
| ------------------------------------------------------------------------------ | ------------------------------------ | -------------------------------------- |
| init() | — | Promise<void> |
| deriveAddressesFromXpubs(evmXpub, avalancheXpubs, isTestnet, accountIndices) | strings + index array | Promise<DerivedSecp256k1Addresses[]> |
| deriveAddressesForEvm(publicKeys) | 33-byte compressed secp256k1 pubkeys | Promise<string[]> (EIP-55 hex) |
| deriveAddressesForBtc(publicKeys, isTestnet) | 33-byte compressed secp256k1 pubkeys | Promise<string[]> (bech32 P2WPKH) |
| deriveAddressesForSvm(publicKeys) | 32-byte Ed25519 pubkeys | Promise<string[]> (base58) |
| deriveAddressesForAvalanche(avaxPks, evmPks, isTestnet) | parallel pubkey arrays | Promise<DerivedAvalancheAddresses[]> |
All batched calls cap at 1024 elements per invocation and validate per-element pubkey length / SEC1 prefix at the boundary.
What's not in the facade
Lower-level primitives — sign, verify, signSchnorr, verifySchnorr,
getPublicKey*, getExtendedPublicKey, pointAddScalar — currently exist
only in @avalabs/crypto-nitro. To use them on React Native, import them
directly from the nitro package:
import { sign, verify, getExtendedPublicKey } from '@avalabs/crypto-nitro';Adding the equivalents to @avalabs/crypto-wasm is what would let those
operations move into this facade.
