CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-ledgerhq--hw-app-eth

Ledger Hardware Wallet Ethereum Application API that enables developers to integrate Ledger wallet support into Ethereum applications for address generation, transaction signing, message signing, and various Ethereum operations.

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

starkex.mddocs/

StarkEx Protocol

Complete support for StarkEx layer 2 protocol operations including public key generation, order signing, transfer signing, and quantum provisioning. The library supports both v1 and v2 StarkEx protocols with comprehensive token type support.

Capabilities

Public Key Generation

Generate StarkEx public keys for layer 2 operations.

/**
 * Get StarkEx public key for a given BIP32 path
 * @param path - BIP32 derivation path for StarkEx key
 * @param boolDisplay - Optionally display key on device screen
 * @returns StarkEx public key as Buffer
 */
starkGetPublicKey(path: string, boolDisplay?: boolean): Promise<Buffer>;

Usage Example:

// Generate StarkEx public key
const publicKey = await eth.starkGetPublicKey("44'/60'/0'/0/0");
console.log(publicKey.toString("hex")); // StarkEx public key

// Display public key on device for verification
const publicKey = await eth.starkGetPublicKey("44'/60'/0'/0/0", true);

Order Signing (v1)

Sign StarkEx orders using the original v1 protocol.

/**
 * Sign StarkEx order using v1 protocol
 * @param path - BIP32 derivation path for signing key
 * @param sourceTokenAddress - Source token contract address (undefined for ETH)
 * @param sourceQuantization - Source token quantization unit
 * @param destinationTokenAddress - Destination token contract address (undefined for ETH)
 * @param destinationQuantization - Destination token quantization unit
 * @param sourceVault - Source vault ID
 * @param destinationVault - Destination vault ID
 * @param amountSell - Amount to sell in quantized units
 * @param amountBuy - Amount to buy in quantized units
 * @param nonce - Order nonce
 * @param timestamp - Order expiration timestamp
 * @returns Order signature as Buffer or signature components
 */
starkSignOrder(
  path: string,
  sourceTokenAddress: string | undefined,
  sourceQuantization: BigNumber,
  destinationTokenAddress: string | undefined,
  destinationQuantization: BigNumber,
  sourceVault: number,
  destinationVault: number,
  amountSell: BigNumber,
  amountBuy: BigNumber,
  nonce: number,
  timestamp: number
): Promise<Buffer | {r: string; s: string}>;

Order Signing (v2)

Sign StarkEx orders using the enhanced v2 protocol with extended token type support.

/**
 * Sign StarkEx order using v2 protocol with enhanced token support
 * @param path - BIP32 derivation path for signing key
 * @param sourceTokenAddress - Source token contract address (undefined for ETH)
 * @param sourceQuantizationType - Source token type classification
 * @param sourceQuantization - Source token quantization unit (undefined for some types)
 * @param sourceMintableBlobOrTokenId - Token ID or blob for mintable tokens
 * @param destinationTokenAddress - Destination token contract address (undefined for ETH)
 * @param destinationQuantizationType - Destination token type classification
 * @param destinationQuantization - Destination token quantization unit (undefined for some types)
 * @param destinationMintableBlobOrTokenId - Token ID or blob for mintable tokens
 * @param sourceVault - Source vault ID
 * @param destinationVault - Destination vault ID
 * @param amountSell - Amount to sell in quantized units
 * @param amountBuy - Amount to buy in quantized units
 * @param nonce - Order nonce
 * @param timestamp - Order expiration timestamp
 * @returns Order signature as Buffer or signature components
 */
starkSignOrder_v2(
  path: string,
  sourceTokenAddress: string | undefined,
  sourceQuantizationType: StarkQuantizationType,
  sourceQuantization: BigNumber | undefined,
  sourceMintableBlobOrTokenId: BigNumber | undefined,
  destinationTokenAddress: string | undefined,
  destinationQuantizationType: StarkQuantizationType,
  destinationQuantization: BigNumber | undefined,
  destinationMintableBlobOrTokenId: BigNumber | undefined,
  sourceVault: number,
  destinationVault: number,
  amountSell: BigNumber,
  amountBuy: BigNumber,
  nonce: number,
  timestamp: number
): Promise<Buffer | {r: string; s: string}>;

Usage Examples:

import { BigNumber } from "bignumber.js";

// Sign ETH to ERC20 order (v1)
const signature = await eth.starkSignOrder(
  "44'/60'/0'/0/0",
  undefined, // ETH (no token address)
  new BigNumber("1000000000000000000"), // 1 ETH quantization
  "0xA0b86a33E6776a9fEddac4F0c0bfB3F4a9d7d3e7", // USDC token
  new BigNumber("1000000"), // USDC quantization (6 decimals)
  12345, // Source vault
  67890, // Destination vault
  new BigNumber("1000000000000000000"), // Sell 1 ETH
  new BigNumber("3000000000"), // Buy 3000 USDC
  1, // Nonce
  Math.floor(Date.now() / 1000) + 3600 // Expires in 1 hour
);

// Sign ERC721 to ERC20 order (v2)
const signature = await eth.starkSignOrder_v2(
  "44'/60'/0'/0/0",
  "0x1234567890123456789012345678901234567890", // NFT contract
  "erc721", // Source is ERC721
  undefined, // No quantization for ERC721
  new BigNumber("42"), // Token ID
  "0xA0b86a33E6776a9fEddac4F0c0bfB3F4a9d7d3e7", // USDC token
  "erc20", // Destination is ERC20
  new BigNumber("1000000"), // USDC quantization
  undefined, // No token ID for ERC20
  111, // Source vault
  222, // Destination vault
  new BigNumber("1"), // Sell 1 NFT
  new BigNumber("500000000"), // Buy 500 USDC
  5, // Nonce
  Math.floor(Date.now() / 1000) + 7200 // Expires in 2 hours
);

Transfer Signing (v1)

Sign StarkEx transfers using the original v1 protocol.

/**
 * Sign StarkEx transfer using v1 protocol
 * @param path - BIP32 derivation path for signing key
 * @param transferTokenAddress - Token contract address (undefined for ETH)
 * @param transferQuantization - Token quantization unit
 * @param targetPublicKey - Recipient's StarkEx public key
 * @param sourceVault - Source vault ID
 * @param destinationVault - Destination vault ID
 * @param amountTransfer - Amount to transfer in quantized units
 * @param nonce - Transfer nonce
 * @param timestamp - Transfer expiration timestamp
 * @returns Transfer signature as Buffer or signature components
 */
starkSignTransfer(
  path: string,
  transferTokenAddress: string | undefined,
  transferQuantization: BigNumber,
  targetPublicKey: string,
  sourceVault: number,
  destinationVault: number,
  amountTransfer: BigNumber,
  nonce: number,
  timestamp: number
): Promise<Buffer | {r: string; s: string}>;

Transfer Signing (v2)

Sign StarkEx transfers using the enhanced v2 protocol with conditional transfer support.

/**
 * Sign StarkEx transfer using v2 protocol with enhanced features
 * @param path - BIP32 derivation path for signing key
 * @param transferTokenAddress - Token contract address (undefined for ETH)
 * @param transferQuantizationType - Token type classification
 * @param transferQuantization - Token quantization unit (undefined for some types)
 * @param transferMintableBlobOrTokenId - Token ID or blob for mintable tokens
 * @param targetPublicKey - Recipient's StarkEx public key
 * @param sourceVault - Source vault ID
 * @param destinationVault - Destination vault ID
 * @param amountTransfer - Amount to transfer in quantized units
 * @param nonce - Transfer nonce
 * @param timestamp - Transfer expiration timestamp
 * @param conditionalTransferAddress - Optional conditional transfer contract address
 * @param conditionalTransferFact - Optional conditional transfer fact
 * @returns Transfer signature as Buffer or signature components
 */
starkSignTransfer_v2(
  path: string,
  transferTokenAddress: string | undefined,
  transferQuantizationType: StarkQuantizationType,
  transferQuantization: BigNumber | undefined,
  transferMintableBlobOrTokenId: BigNumber | undefined,
  targetPublicKey: string,
  sourceVault: number,
  destinationVault: number,
  amountTransfer: BigNumber,
  nonce: number,
  timestamp: number,
  conditionalTransferAddress?: string,
  conditionalTransferFact?: BigNumber
): Promise<Buffer | {r: string; s: string}>;

Usage Examples:

// Sign ETH transfer (v1)
const signature = await eth.starkSignTransfer(
  "44'/60'/0'/0/0",
  undefined, // ETH
  new BigNumber("1000000000000000000"), // 1 ETH quantization
  "0x1234567890abcdef...", // Recipient's StarkEx public key
  111, // Source vault
  222, // Destination vault
  new BigNumber("500000000000000000"), // Transfer 0.5 ETH
  10, // Nonce
  Math.floor(Date.now() / 1000) + 3600 // Expires in 1 hour
);

// Sign conditional ERC721 transfer (v2)
const signature = await eth.starkSignTransfer_v2(
  "44'/60'/0'/0/0",
  "0x1234567890123456789012345678901234567890", // NFT contract
  "erc721", // Token type
  undefined, // No quantization for ERC721
  new BigNumber("123"), // Token ID
  "0xabcdef1234567890...", // Recipient's public key
  333, // Source vault
  444, // Destination vault
  new BigNumber("1"), // Transfer 1 NFT
  15, // Nonce
  Math.floor(Date.now() / 1000) + 7200, // Expires in 2 hours
  "0xConditionalContract123...", // Conditional transfer contract
  new BigNumber("999") // Transfer condition fact
);

Quantum Provisioning

Provide quantum information to the hardware wallet for StarkEx operations.

/**
 * Provide quantum information for StarkEx operations (v1)
 * @param operationContract - Token contract address (undefined for ETH)
 * @param operationQuantization - Token quantization unit
 * @returns Success status
 */
starkProvideQuantum(
  operationContract: string | undefined,
  operationQuantization: BigNumber
): Promise<boolean>;

/**
 * Provide quantum information for StarkEx operations (v2)
 * @param operationContract - Token contract address (undefined for ETH)
 * @param operationQuantizationType - Token type classification
 * @param operationQuantization - Token quantization unit (undefined for some types)
 * @param operationMintableBlobOrTokenId - Token ID or blob for mintable tokens
 * @returns Success status
 */
starkProvideQuantum_v2(
  operationContract: string | undefined,
  operationQuantizationType: StarkQuantizationType,
  operationQuantization?: BigNumber,
  operationMintableBlobOrTokenId?: BigNumber
): Promise<boolean>;

Usage Examples:

// Provide ETH quantum (v1)
await eth.starkProvideQuantum(
  undefined, // ETH
  new BigNumber("1000000000000000000") // 1 ETH quantization
);

// Provide ERC721 quantum (v2)
await eth.starkProvideQuantum_v2(
  "0x1234567890123456789012345678901234567890", // NFT contract
  "erc721", // Token type
  undefined, // No quantization for ERC721
  new BigNumber("456") // Token ID
);

Unsafe Signing

Sign arbitrary StarkEx hashes for advanced use cases.

/**
 * Sign arbitrary hash using StarkEx unsafe signing (advanced use only)
 * @param path - BIP32 derivation path for signing key
 * @param hash - Hash to sign as hex string
 * @returns Signature as Buffer or signature components
 */
starkUnsafeSign(path: string, hash: string): Promise<Buffer | {r: string; s: string}>;

Usage Example:

// Advanced: Sign pre-computed hash
const hash = "0x1234567890abcdef..."; // Pre-computed StarkEx operation hash
const signature = await eth.starkUnsafeSign("44'/60'/0'/0/0", hash);

StarkEx Types

/**
 * StarkEx token quantization types for v2 protocol
 */
type StarkQuantizationType = 
  | "eth"           // Native ETH
  | "erc20"         // ERC20 fungible tokens
  | "erc721"        // ERC721 non-fungible tokens
  | "erc20mintable" // Mintable ERC20 tokens
  | "erc721mintable"; // Mintable ERC721 tokens

Protocol Compatibility

The library supports both StarkEx v1 and v2 protocols:

  • v1 Protocol: Basic token support (ETH, ERC20, simple ERC721)
  • v2 Protocol: Enhanced features including:
    • Mintable token support
    • Extended token type system
    • Conditional transfers
    • Improved token ID handling
    • Better quantization support

Migration from v1 to v2:

// v1 approach
await eth.starkSignOrder(
  path, tokenAddr, quantization, /* ... */
);

// v2 approach with equivalent functionality
await eth.starkSignOrder_v2(
  path, tokenAddr, "erc20", quantization, undefined, /* ... */
);

docs

advanced-features.md

core-operations.md

index.md

message-signing.md

services-utilities.md

starkex.md

transaction-signing.md

tile.json