@cyphras/sdk
v0.1.0
Published
TypeScript SDK for building dApps with the Cyphras multichain browser wallet extension
Maintainers
Readme
Installation
npm install @cyphras/sdkThe Cyphras extension must be installed by the user. Every method returns a typed error response when the extension is absent - no try/catch needed.
Quick Start
import { cyphras } from '@cyphras/sdk'
const { installed } = await cyphras.stellar.status()
if (!installed) {
// prompt user to install the extension
}
const result = await cyphras.stellar.connect()
if (result.error) {
console.error(result.error.message)
} else {
console.log('Connected:', result.address)
}Response Pattern
Every async method returns CyphrasResponse<T> and never throws.
type CyphrasResponse<T> =
| (T & { error?: undefined }) // success: data at top level
| { error: { code: string; message: string } } // failure
const result = await cyphras.stellar.getAccount()
if (result.error) {
console.error(result.error.code)
return
}
console.log(result.address) // TypeScript narrows automaticallyAPI Overview
All methods are accessed via cyphras.stellar.*.
| Category | Methods |
|---|---|
| Connection | status(), connect(), disconnect() |
| Account | getAccount(), getAccountInfo(), getBalance(), getAssets(), fundTestnetAccount(), watchAccountBalance() |
| Network | getNetwork() |
| Signing | sign(xdr), sign(msg, { type: 'message' }), sign(entry, { type: 'authEntry' }) |
| Transactions | submit(), signAndSubmit(), estimateFee(), getTransaction(), getTransactionHistory() |
| Assets | addAsset(), removeAsset(), addToken(), hasTrustline() |
| Builders | build.payment(), build.pathPayment(), build.manageOffer() |
| Contracts | contract.getSpec(), contract.client() |
| Federation | fetchStellarToml(), resolveFederation() |
| SEP-0007 | sep0007.parse(), sep0007.buildPayUri(), sep0007.buildTxUri() |
| SEP-0010 | sep0010.challenge(), sep0010.verify(), sep0010.authenticate() |
| SEP-0024 | sep0024.info(), sep0024.deposit(), sep0024.withdraw(), sep0024.getTransaction(), sep0024.pollTransaction() |
| SEP-0038 | sep0038.info(), sep0038.price(), sep0038.quote(), sep0038.getQuote() |
| Events | on('accountChange', cb), on('networkChange', cb), off() |
Events
const handler = (address: string | null) => console.log('Account:', address)
cyphras.stellar.on('accountChange', handler)
cyphras.stellar.off('accountChange', handler)
cyphras.stellar.on('networkChange', ({ network, networkPassphrase }) => {
console.log('Network changed to:', network)
})License
Apache 2.0. See LICENSE for details.
