Wallet SDK overview
What @amadeus-protocol/wallet-sdk is, who it is for, how to install it and where each module is documented.
@amadeus-protocol/wallet-sdk is the connection layer between dApps and Amadeus wallets. It contains the typed contract of the injected browser provider, transaction and message signing, API-key tokens and Amadeus Connect, the encrypted channel between a dApp and the mobile wallet. The Amadeus mobile wallet uses this package on its side of Amadeus Connect, so a dApp that uses it runs the same code as the wallet it talks to.
The package is written in TypeScript and is MIT licensed. It is published on npm as @amadeus-protocol/wallet-sdk.
Who it is for
dApp developers use it to connect to a user's wallet, request signatures and submit transactions:
- With the Amadeus browser extension on the same device, through the injected
window.amadeusprovider. UsecreateInjectedWalletClient, or theuseWallethook in React. - With the Amadeus mobile wallet, through Amadeus Connect. The dApp shows a QR code or opens a deep link, and the two sides then exchange encrypted messages through a relay (
https://bridge.ama.oneby default).
Wallet builders use it to answer those requests. It covers parsing and approving connect requests, opening encrypted requests, rejecting expired or replayed ones, and producing signed responses.
Backend services use it to verify what a wallet produced, for example an API-key token (verifyApiKey) or a signed message (verifyMessage). Verification needs no wallet and no network access.
How it relates to the rest of Amadeus
| Component | Relationship |
|---|---|
@amadeus-protocol/sdk | Required peer dependency. The core SDK does key derivation, encoding and transaction building. Wallet SDK builds on it and adds only the dApp-to-wallet layer. Node queries, balances and amount conversion still come from the core SDK. |
| Browser extension | Injects window.amadeus. Wallet SDK describes that provider as the AmadeusProvider type and wraps it in a client. The extension does not import Wallet SDK; the types mirror what it injects. The raw provider API is described in the extension integration guide. |
| Mobile wallet | Uses Wallet SDK on the wallet side of Amadeus Connect. It accepts amadeus://v1/connect links from a QR scan, a pasted link or a deep link, and https://wallet.ama.one/v1/connect Universal Links. |
The two connection paths do not support the same requests:
| Request | Browser extension (injected) | Mobile wallet (Amadeus Connect) |
|---|---|---|
| Connect and read accounts | Yes | Yes |
| Sign a transaction | Yes | Yes |
| Generate an API key | Yes | Yes |
| Sign a message | No | Yes |
| Switch network | Yes, with the raw provider's requestSwitchNetwork | No |
| Switch account | Yes, with switchAccount | No |
Over Amadeus Connect, amadeus_switchNetwork and amadeus_switchAccount always come back as an error response in 0.2.0. See Amadeus Connect for details.
Installation
Install the package together with the core SDK:
# npm
npm install @amadeus-protocol/wallet-sdk @amadeus-protocol/sdk
# bun
bun add @amadeus-protocol/wallet-sdk @amadeus-protocol/sdk
If you use the React hook, your app also needs react.
Requirements
- Peer dependency
@amadeus-protocol/sdk^1.3.0(required). Any 1.x release from 1.3.0 on works. 1.3.0 is the first core SDK version that signs testnet transactions under their own domain tag. - Peer dependency
react>=18(optional). It is only needed for the/reactentry point. - ESM only. The package has no CommonJS build, so
require('@amadeus-protocol/wallet-sdk')does not work. Useimport. - Node.js 20 or later when you use it on a server.
Runtime dependencies are @noble/ciphers, @noble/curves, @noble/hashes and zod. The package has no Node-only imports and runs in browsers, Node.js and React Native (Hermes).
Key generation and request ids use crypto.getRandomValues. On React Native, install a polyfill such as react-native-get-random-values, as the Amadeus mobile wallet does.
Entry points
| Import path | Contents |
|---|---|
@amadeus-protocol/wallet-sdk | Everything except React: the injected client, provider types, signing, API keys, Amadeus Connect, the wallet-side handler, schemas, constants and errors. |
@amadeus-protocol/wallet-sdk/react | The useWallet hook and its types UseWalletResult and WalletStatus. |
import { createInjectedWalletClient, verifyApiKey, WalletSdkError } from '@amadeus-protocol/wallet-sdk'
import { useWallet, type UseWalletResult, type WalletStatus } from '@amadeus-protocol/wallet-sdk/react'
React lives in its own entry point, so apps without React (the mobile wallet, a Node.js verifier) never load it.
A first look
This connects to the browser extension, then signs and submits a transfer of 1.5 AMA to recipient, a Base58 address. The amount conversion comes from the core SDK:
import { toAtomicAma } from '@amadeus-protocol/sdk'
import { createInjectedWalletClient } from '@amadeus-protocol/wallet-sdk'
const wallet = createInjectedWalletClient()
if (wallet.isAvailable()) {
const account = await wallet.connect()
const { txHash } = await wallet.signAndSubmit(
{ contract: 'Coin', method: 'transfer', args: [recipient, String(toAtomicAma(1.5)), 'AMA'] },
{ nodeUrl: 'https://mainnet-rpc.ama.one/api', wait: true }
)
console.log(`${account} sent ${txHash}`)
}
The wallet only signs. signAndSubmit sends the signed bytes to the node you pass in nodeUrl, and that URL must include the /api path. The extension can inject window.amadeus after your script runs, so isAvailable() can be false on first load. Connect a dApp walks through detection, events and errors.
Module map
| Area | Main exports | Read |
|---|---|---|
| Injected client (browser extension) | createInjectedWalletClient, WalletClient, ApiKeyStore | Connect a dApp |
| React | useWallet, UseWalletResult, WalletStatus | React |
| Provider contract | AmadeusProvider, getAmadeusProvider, isProviderAvailable, AmadeusEventPayloadMap, PROVIDER_EVENTS, WALLET_WINDOW_EVENTS, WALLET_INITIALIZED_EVENT | Provider reference |
| Amadeus Connect (dApp side) | createConnectRequest, completeConnect, parseConnectResponseUri, BridgeClient, deriveConnectChannel, deriveBridgeChannels, makeRequest, sealRequest, openResponse, DEFAULT_BRIDGE_URL | Amadeus Connect (mobile) |
| Transactions | signTransaction, submitTransaction, encodeBinaryValues, decodeBinaryValues, describeBinaryValues | Signing and API keys |
| Messages | signMessage, verifyMessage | Signing and API keys |
| API keys | generateApiKey, verifyApiKey, decodeApiKey | Signing and API keys |
| Wallet side | parseConnectUri, isConnectRequestExpired, assertAllowedBridgeUrl, approveConnect, buildConnectResponseUri, openRequest, guardRequest, createMemorySeenStore, handleRequest, sealResponse, WALLET_METHODS | Build a wallet integration |
| Request validation | zod schemas such as signTransactionRequestSchema, signMessageRequestSchema, generateApiKeyRequestSchema, addressSchema | Provider reference |
| Low-level crypto | signConnect, verifyConnect, buildConnectTranscript, generateSessionKeypair, deriveSharedKey, seal, open, deriveSigner, signHashed, verifyHashed, publicKeyFromAddress, signatureFromBase58 | Used by the modules above. Most apps never call them directly. See Signing and API keys. |
| Utilities | randomId, randomBytes, concatBytes, equalBytes, utf8ToBytes, bytesToUtf8, u32be | Signing and API keys |
| Constants | Domain tags (TX_DST, MESSAGE_DST, API_KEY_DST, CONNECT_DST), byte lengths, PROTOCOL_VERSION, NETWORKS | Signing and API keys and Provider reference |
| Errors | WalletSdkError, WalletSdkErrorCode | Errors below |
signTransaction, signMessage and generateApiKey take a seed. They are what a wallet runs. A dApp asks the wallet for these results instead of calling them.
Errors
Errors raised by Wallet SDK itself are WalletSdkErrors. Each has a stable code of type WalletSdkErrorCode, so you can branch on the code without matching message text. The provider reference lists every code, which function raises it and an example.
Not every failure is a WalletSdkError:
- When the user rejects a request in the browser extension, or the request times out, the extension rejects with a plain
Error. - Network failures and the 30-second timeout in
submitTransactioncome fromfetchand pass through unchanged. - Over Amadeus Connect, the wallet's errors arrive as response objects, not thrown errors. Their
codeis a plain string and can beINTERNAL, which is not aWalletSdkErrorCode.
Versioning
The package is at 0.2.x (0.2.0 at the time of writing). Before 1.0, a new minor version (0.3.0) can contain breaking changes.
- Pin the minor version. The default range that
npm installandbun addwrite,^0.2.0, already stays within 0.2.x. Do not widen it to>=0.2.0or*. - Test your integration before you move to a new minor version.
- Keep
@amadeus-protocol/sdkon 1.3.0 or later. Older versions sign testnet transactions with the mainnet tag.
Upgrading from 0.1.x
0.2.0 aligns the provider types with what the browser extension sends. Check these points when you upgrade:
- Event
timestampfields are now typed as ISO 8601 strings (AmadeusEventTimestamp), notnumber. The extension always sent strings, so only the type changed. Code that did arithmetic on them needsDate.parse(timestamp)ornew Date(timestamp). PROVIDER_EVENTSandAmadeusProviderEventnow include'shown'. An exhaustiveswitchover event names needs a case for it.AmadeusProviderdeclares the optionalgetPendingRequests()andcancelRequest(). A provider cast that added them by hand can be removed.ensureApiKeycaches keys peraudand passesaudtoApiKeyStore.get(aud?)andset(apiKey, aud?). Stores written for 0.1.x still typecheck, and a cached key whoseauddiffers from the request is no longer returned.useWallet()keeps the last knownnetworkwhen aconnectevent carriesnetwork: null.
Next steps
- Connect a dApp to the browser extension
- Use the React hook
- Look up methods and events in the provider reference
- Connect to the mobile wallet with Amadeus Connect
- Sign transactions and messages and manage tokens in Signing and API keys
- Answer dApp requests in your own wallet: Build a wallet integration