Skip to main content

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.amadeus provider. Use createInjectedWalletClient, or the useWallet hook 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.one by 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​

ComponentRelationship
@amadeus-protocol/sdkRequired 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 extensionInjects 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 walletUses 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:

RequestBrowser extension (injected)Mobile wallet (Amadeus Connect)
Connect and read accountsYesYes
Sign a transactionYesYes
Generate an API keyYesYes
Sign a messageNoYes
Switch networkYes, with the raw provider's requestSwitchNetworkNo
Switch accountYes, with switchAccountNo
note

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 /react entry point.
  • ESM only. The package has no CommonJS build, so require('@amadeus-protocol/wallet-sdk') does not work. Use import.
  • 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).

note

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 pathContents
@amadeus-protocol/wallet-sdkEverything except React: the injected client, provider types, signing, API keys, Amadeus Connect, the wallet-side handler, schemas, constants and errors.
@amadeus-protocol/wallet-sdk/reactThe 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​

AreaMain exportsRead
Injected client (browser extension)createInjectedWalletClient, WalletClient, ApiKeyStoreConnect a dApp
ReactuseWallet, UseWalletResult, WalletStatusReact
Provider contractAmadeusProvider, getAmadeusProvider, isProviderAvailable, AmadeusEventPayloadMap, PROVIDER_EVENTS, WALLET_WINDOW_EVENTS, WALLET_INITIALIZED_EVENTProvider reference
Amadeus Connect (dApp side)createConnectRequest, completeConnect, parseConnectResponseUri, BridgeClient, deriveConnectChannel, deriveBridgeChannels, makeRequest, sealRequest, openResponse, DEFAULT_BRIDGE_URLAmadeus Connect (mobile)
TransactionssignTransaction, submitTransaction, encodeBinaryValues, decodeBinaryValues, describeBinaryValuesSigning and API keys
MessagessignMessage, verifyMessageSigning and API keys
API keysgenerateApiKey, verifyApiKey, decodeApiKeySigning and API keys
Wallet sideparseConnectUri, isConnectRequestExpired, assertAllowedBridgeUrl, approveConnect, buildConnectResponseUri, openRequest, guardRequest, createMemorySeenStore, handleRequest, sealResponse, WALLET_METHODSBuild a wallet integration
Request validationzod schemas such as signTransactionRequestSchema, signMessageRequestSchema, generateApiKeyRequestSchema, addressSchemaProvider reference
Low-level cryptosignConnect, verifyConnect, buildConnectTranscript, generateSessionKeypair, deriveSharedKey, seal, open, deriveSigner, signHashed, verifyHashed, publicKeyFromAddress, signatureFromBase58Used by the modules above. Most apps never call them directly. See Signing and API keys.
UtilitiesrandomId, randomBytes, concatBytes, equalBytes, utf8ToBytes, bytesToUtf8, u32beSigning and API keys
ConstantsDomain tags (TX_DST, MESSAGE_DST, API_KEY_DST, CONNECT_DST), byte lengths, PROTOCOL_VERSION, NETWORKSSigning and API keys and Provider reference
ErrorsWalletSdkError, WalletSdkErrorCodeErrors 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 submitTransaction come from fetch and pass through unchanged.
  • Over Amadeus Connect, the wallet's errors arrive as response objects, not thrown errors. Their code is a plain string and can be INTERNAL, which is not a WalletSdkErrorCode.

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 install and bun add write, ^0.2.0, already stays within 0.2.x. Do not widen it to >=0.2.0 or *.
  • Test your integration before you move to a new minor version.
  • Keep @amadeus-protocol/sdk on 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 timestamp fields are now typed as ISO 8601 strings (AmadeusEventTimestamp), not number. The extension always sent strings, so only the type changed. Code that did arithmetic on them needs Date.parse(timestamp) or new Date(timestamp).
  • PROVIDER_EVENTS and AmadeusProviderEvent now include 'shown'. An exhaustive switch over event names needs a case for it.
  • AmadeusProvider declares the optional getPendingRequests() and cancelRequest(). A provider cast that added them by hand can be removed.
  • ensureApiKey caches keys per aud and passes aud to ApiKeyStore.get(aud?) and set(apiKey, aud?). Stores written for 0.1.x still typecheck, and a cached key whose aud differs from the request is no longer returned.
  • useWallet() keeps the last known network when a connect event carries network: null.

Next steps​

  1. Connect a dApp to the browser extension
  2. Use the React hook
  3. Look up methods and events in the provider reference
  4. Connect to the mobile wallet with Amadeus Connect
  5. Sign transactions and messages and manage tokens in Signing and API keys
  6. Answer dApp requests in your own wallet: Build a wallet integration