CosmosStealthService
SIP Protocol API Reference v0.7.0
SIP Protocol API Reference / CosmosStealthService
Class: CosmosStealthService
Section titled “Class: CosmosStealthService”Defined in: @sip-protocol/sdk/dist/index-BYZbDjal.d.ts:2898
Cosmos Stealth Address Service
Provides stealth address generation and key derivation for Cosmos chains. Reuses secp256k1 logic from core stealth module, adding Cosmos-specific address formatting.
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new CosmosStealthService():
CosmosStealthService
Returns
Section titled “Returns”CosmosStealthService
Methods
Section titled “Methods”generateStealthMetaAddress()
Section titled “generateStealthMetaAddress()”generateStealthMetaAddress(
chain,label?):object
Defined in: @sip-protocol/sdk/dist/index-BYZbDjal.d.ts:2914
Generate a stealth meta-address for a Cosmos chain
Parameters
Section titled “Parameters”Cosmos chain identifier
label?
Section titled “label?”string
Optional human-readable label
Returns
Section titled “Returns”object
Stealth meta-address and private keys
metaAddress
Section titled “metaAddress”metaAddress:
StealthMetaAddress
spendingPrivateKey
Section titled “spendingPrivateKey”spendingPrivateKey:
`0x${string}`
viewingPrivateKey
Section titled “viewingPrivateKey”viewingPrivateKey:
`0x${string}`
Throws
Section titled “Throws”If chain is invalid
Example
Section titled “Example”const service = new CosmosStealthService()const { metaAddress, spendingPrivateKey, viewingPrivateKey } = service.generateStealthMetaAddress('cosmos', 'My Cosmos Wallet')generateStealthAddress()
Section titled “generateStealthAddress()”generateStealthAddress(
spendingPubKey,viewingPubKey,chain):CosmosStealthResult
Defined in: @sip-protocol/sdk/dist/index-BYZbDjal.d.ts:2939
Generate a one-time stealth address for a Cosmos chain
Parameters
Section titled “Parameters”spendingPubKey
Section titled “spendingPubKey”Uint8Array
Recipient’s spending public key (33-byte compressed)
viewingPubKey
Section titled “viewingPubKey”Uint8Array
Recipient’s viewing public key (33-byte compressed)
Cosmos chain identifier
Returns
Section titled “Returns”Cosmos stealth address with bech32 encoding
Throws
Section titled “Throws”If keys or chain are invalid
Example
Section titled “Example”const service = new CosmosStealthService()const result = service.generateStealthAddress( spendingKey, viewingKey, 'osmosis')console.log(result.stealthAddress) // "osmo1..."generateStealthAddressFromMeta()
Section titled “generateStealthAddressFromMeta()”generateStealthAddressFromMeta(
recipientMetaAddress,chain):CosmosStealthResult
Defined in: @sip-protocol/sdk/dist/index-BYZbDjal.d.ts:2956
Generate stealth address from StealthMetaAddress
Convenience method that accepts a StealthMetaAddress directly.
Parameters
Section titled “Parameters”recipientMetaAddress
Section titled “recipientMetaAddress”Recipient’s stealth meta-address
Cosmos chain identifier
Returns
Section titled “Returns”Cosmos stealth address with bech32 encoding
Throws
Section titled “Throws”If meta-address or chain are invalid
Example
Section titled “Example”const service = new CosmosStealthService()const result = service.generateStealthAddressFromMeta(metaAddress, 'cosmos')stealthKeyToCosmosAddress()
Section titled “stealthKeyToCosmosAddress()”stealthKeyToCosmosAddress(
publicKey,prefix):string
Defined in: @sip-protocol/sdk/dist/index-BYZbDjal.d.ts:2977
Convert stealth public key to Cosmos bech32 address
Algorithm:
- SHA256 hash of compressed public key
- RIPEMD160 hash of SHA256 hash
- Bech32 encode with chain prefix
Parameters
Section titled “Parameters”publicKey
Section titled “publicKey”Uint8Array
Compressed secp256k1 public key (33 bytes)
prefix
Section titled “prefix”string
Bech32 address prefix (e.g., “cosmos”, “osmo”)
Returns
Section titled “Returns”string
Bech32-encoded address
Throws
Section titled “Throws”If public key is invalid
Example
Section titled “Example”const service = new CosmosStealthService()const address = service.stealthKeyToCosmosAddress(pubKey, 'cosmos')// Returns: "cosmos1abc..."deriveStealthPrivateKey()
Section titled “deriveStealthPrivateKey()”deriveStealthPrivateKey(
stealthAddress,spendingPrivateKey,viewingPrivateKey):StealthAddressRecovery
Defined in: @sip-protocol/sdk/dist/index-BYZbDjal.d.ts:2998
Derive stealth private key for recipient to claim funds
Parameters
Section titled “Parameters”stealthAddress
Section titled “stealthAddress”The stealth address to recover (as StealthAddress)
spendingPrivateKey
Section titled “spendingPrivateKey”`0x${string}`
Recipient’s spending private key
viewingPrivateKey
Section titled “viewingPrivateKey”`0x${string}`
Recipient’s viewing private key
Returns
Section titled “Returns”Recovery data with derived private key
Throws
Section titled “Throws”If any input is invalid
Example
Section titled “Example”const service = new CosmosStealthService()const recovery = service.deriveStealthPrivateKey( stealthAddress, spendingPrivKey, viewingPrivKey)// Use recovery.privateKey to spend fundsdecodeBech32Address()
Section titled “decodeBech32Address()”decodeBech32Address(
address):object
Defined in: @sip-protocol/sdk/dist/index-BYZbDjal.d.ts:3016
Decode a Cosmos bech32 address to raw hash
Parameters
Section titled “Parameters”address
Section titled “address”string
Bech32-encoded address
Returns
Section titled “Returns”object
Decoded address hash (20 bytes)
prefix
Section titled “prefix”prefix:
string
hash:
Uint8Array
Throws
Section titled “Throws”If address is invalid
Example
Section titled “Example”const service = new CosmosStealthService()const { prefix, hash } = service.decodeBech32Address('cosmos1abc...')isValidCosmosAddress()
Section titled “isValidCosmosAddress()”isValidCosmosAddress(
address,expectedChain?):boolean
Defined in: @sip-protocol/sdk/dist/index-BYZbDjal.d.ts:3034
Validate a Cosmos bech32 address format
Parameters
Section titled “Parameters”address
Section titled “address”string
Address to validate
expectedChain?
Section titled “expectedChain?”Optional chain to validate prefix against
Returns
Section titled “Returns”boolean
true if valid, false otherwise
Example
Section titled “Example”const service = new CosmosStealthService()service.isValidCosmosAddress('cosmos1abc...', 'cosmos') // trueservice.isValidCosmosAddress('osmo1xyz...', 'cosmos') // false (wrong prefix)getChainFromAddress()
Section titled “getChainFromAddress()”getChainFromAddress(
address):CosmosChainId|null
Defined in: @sip-protocol/sdk/dist/index-BYZbDjal.d.ts:3048
Get the chain ID from a bech32 address prefix
Parameters
Section titled “Parameters”address
Section titled “address”string
Bech32-encoded address
Returns
Section titled “Returns”CosmosChainId | null
Chain ID or null if unknown prefix
Example
Section titled “Example”const service = new CosmosStealthService()service.getChainFromAddress('cosmos1abc...') // 'cosmos'service.getChainFromAddress('osmo1xyz...') // 'osmosis'