Spark Signer Interface
Complete guide to implementing and using the Spark Signer for cryptographic operations
Overview
The Spark SDK provides the SparkSigner
interface to enable flexible implementation of signing operations. This abstraction allows you to customize how cryptographic operations are performed and enables support for different signing strategies including multisig configurations, hardware wallets, and other specialized key management systems.
The SDK includes a default implementation (DefaultSparkSigner
) that handles standard single-signature operations. This can serve as a reference for implementing custom signers that support multisig, hardware wallets, or other advanced signing schemes.
Core Concepts
Key Types
- Identity Key: Primary wallet identifier used for authentication
- Signing Keys: Derived keys for specific transaction outputs
- Deposit Keys: Keys for receiving L1 Bitcoin deposits
- Static Deposit Keys: Reusable keys for deposit operations
Security Model
All private keys are derived from a master seed using BIP32 hierarchical deterministic key derivation. The signer maintains an internal mapping between public keys and their corresponding private keys, ensuring secure access control.
Interface Methods
Wallet Initialization
generateMnemonic()
Generates a new BIP39 mnemonic phrase for wallet creation.
Returns:
Promise<string>
: A 12-word BIP39 mnemonic phrase
Example:
mnemonicToSeed(mnemonic: string)
Converts a BIP39 mnemonic phrase to a cryptographic seed.
Parameters:
mnemonic
: Valid BIP39 mnemonic phrase
Returns:
Promise<Uint8Array>
: 64-byte seed derived from the mnemonic
createSparkWalletFromSeed(seed, accountNumber?)
Initializes the signer with a master seed and derives all necessary keys.
Parameters:
seed
: Master seed as bytes or hex stringaccountNumber
: (Optional, default: 0) Account index for key derivation
Returns:
Promise<string>
: Hex-encoded identity public key
Example:
Key Management
getIdentityPublicKey()
Retrieves the wallet’s identity public key.
Returns:
Promise<Uint8Array>
: The identity public key
getMasterPublicKey()
Retrieves the master public key.
Returns:
Promise<Uint8Array>
: The master public key
generatePublicKey(hash?)
Generates a new signing key pair and returns the public key.
Parameters:
hash
: (Optional) Deterministic hash for key derivation
Returns:
Promise<Uint8Array>
: The generated public key
removePublicKey(publicKey)
Removes a public key from the signer’s tracked keys.
Parameters:
publicKey
: Public key to remove
getTrackedPublicKeys()
Returns all currently tracked public keys.
Returns:
Promise<Uint8Array[]>
: Array of tracked public keys
Deposit Address Management
getDepositSigningKey()
Retrieves the deposit signing public key.
Returns:
Promise<Uint8Array>
: The deposit signing public key
generateStaticDepositKey(idx)
Generates or retrieves a static deposit key by index.
Parameters:
idx
: Index for the static deposit key
Returns:
Promise<Uint8Array>
: The static deposit public key
getStaticDepositSigningKey(idx)
Retrieves a static deposit signing key by index.
Parameters:
idx
: Index for the static deposit key
Returns:
Promise<Uint8Array>
: The static deposit signing public key
getStaticDepositSecretKey(idx)
Retrieves a static deposit private key by index.
Parameters:
idx
: Index for the static deposit key
Returns:
Promise<Uint8Array>
: The static deposit private key
Digital Signatures
signMessageWithIdentityKey(message, compact?)
Signs a message using the wallet’s identity key.
Parameters:
message
: Message to signcompact
: (Optional, default: false) Use compact signature format
Returns:
Promise<Uint8Array>
: ECDSA signature (DER or compact format)
signMessageWithPublicKey(message, publicKey, compact?)
Signs a message using a specific public key.
Parameters:
message
: Message to signpublicKey
: Public key to use for signingcompact
: (Optional, default: false) Use compact signature format
Returns:
Promise<Uint8Array>
: ECDSA signature (DER or compact format)
validateMessageWithIdentityKey(message, signature)
Validates a signature against the identity key.
Parameters:
message
: Original messagesignature
: Signature to validate
Returns:
Promise<boolean>
: True if signature is valid
Schnorr Signatures
getSchnorrPublicKey(publicKey)
Converts a secp256k1 public key to Schnorr format.
Parameters:
publicKey
: secp256k1 public key
Returns:
Promise<Uint8Array>
: Schnorr public key
signSchnorr(message, publicKey)
Creates a Schnorr signature for a message.
Parameters:
message
: Message to signpublicKey
: Public key to use for signing
Returns:
Promise<Uint8Array>
: Schnorr signature
signSchnorrWithIdentityKey(message)
Creates a Schnorr signature using the identity key.
Parameters:
message
: Message to sign
Returns:
Promise<Uint8Array>
: Schnorr signature
Advanced Cryptographic Operations
restoreSigningKeysFromLeafs(leafs)
Restores signing keys from a set of tree leaf nodes.
Parameters:
leafs
: Array of tree leaf nodes
subtractPrivateKeysGivenPublicKeys(first, second)
Performs private key subtraction and returns the resulting public key.
Parameters:
first
: First public keysecond
: Second public key
Returns:
Promise<Uint8Array>
: Resulting public key after subtraction
splitSecretWithProofs(params)
Implements Shamir’s Secret Sharing with verifiable proofs.
Parameters:
params
: Secret sharing parameters
Returns:
Promise<VerifiableSecretShare[]>
: Array of verifiable secret shares
FROST Protocol (Threshold Signatures)
getRandomSigningCommitment()
Generates a random signing commitment for FROST protocol.
Returns:
Promise<SigningCommitment>
: Random signing commitment
signFrost(params)
Performs FROST signing operation.
Parameters:
params
: FROST signing parameters
Returns:
Promise<Uint8Array>
: FROST signature share
aggregateFrost(params)
Aggregates FROST signature shares into a final signature.
Parameters:
params
: FROST aggregation parameters
Returns:
Promise<Uint8Array>
: Final aggregated signature
Encryption
encryptLeafPrivateKeyEcies(receiverPublicKey, publicKey)
Encrypts a leaf private key using ECIES.
Parameters:
receiverPublicKey
: Recipient’s public keypublicKey
: Public key whose private key to encrypt
Returns:
Promise<Uint8Array>
: Encrypted private key
decryptEcies(ciphertext)
Decrypts ECIES-encrypted data using the identity key.
Parameters:
ciphertext
: Encrypted data
Returns:
Promise<Uint8Array>
: Decrypted public key
Utility Functions
hashRandomPrivateKey()
Generates a hash of a random private key.
Returns:
Promise<Uint8Array>
: SHA256 hash of a random private key
generateAdaptorFromSignature(signature)
Generates an adaptor signature from a regular signature.
Parameters:
signature
: Original signature
Returns:
- Promise containing:
adaptorSignature
: The adaptor signatureadaptorPublicKey
: The adaptor public key