Skip to content
rhinestonewtfPublic

About

Smart wallets and multichain transactions for your application

Resources

Contributing

Security policy

Stars

14 stars

Watchers

0 watching

Forks

Latest commit

 

History

3,209 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rhinestone SDK

Smart wallets and multichain transactions for your application

Rhinestone is self-custodial stablecoin infrastructure for fintechs. Give users an account they control, help them fund it, and move value across chains, tokens, and currencies through one integration. This SDK covers two of its products:

  • Wallets — smart wallets inside your application, approved with a passkey, with session keys and recovery.
  • Transactions — payments, swaps, and contract calls funded from any supported chain, with fees you can sponsor.

Deposits have their own integration: see the docs.

Documentation

Features

  • Multichain Transactions - Execute transactions on any target chain using assets from any source chain. The orchestrator handles routing and settlement. Learn more

  • Swaps - Token exchanges via solver-based swaps or injected DEX aggregator swaps, integrated into crosschain transaction execution. Learn more

  • Passkeys - WebAuthn-based authentication for smart accounts, replacing seed phrases with device biometrics. Learn more

  • Session Keys - Onchain permissions system for scoped transaction automation, enabling one-click UX and server-side execution with granular policies. Learn more

  • Sponsorship - Subsidize gas, bridge, and swap fees for users by depositing USDC on Base. Applies across all supported chains. Learn more

Installation

npm install viem @rhinestone/sdk
bun install viem @rhinestone/sdk

Authentication

The SDK supports two authentication modes: API key and JWT.

API Key

Pass the API key from the Rhinestone dashboard:

const rhinestone = new RhinestoneSDK({
  auth: {
    mode: 'apiKey',
    apiKey: 'your-api-key',
  },
})

JWT (Experimental)

JWT authentication uses RS256-signed tokens for fine-grained access control. There are two integration patterns depending on your architecture:

Client-server (SDK runs in browser/client)

When the SDK runs on the client and a separate backend holds the signing key, fetch tokens via HTTP:

const rhinestone = new RhinestoneSDK({
  auth: {
    mode: 'experimental_jwt',
    accessToken: async () => {
      const res = await fetch('/api/auth/token')
      const { token } = await res.json()
      return token
    },
    // Only needed for sponsored intents:
    getIntentExtensionToken: async (intentInput) => {
      const res = await fetch('/api/auth/extension-token', {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({ intentInput }),
      })
      const { token } = await res.json()
      return token
    },
  },
})

Your backend is responsible for signing JWTs with the correct claims. See the JWT documentation for the required token format.

Same-host (SDK and signing key on the same server)

When the SDK runs server-side with access to the private key, use createJwtSigner to sign tokens in-process without an HTTP round-trip:

import { createJwtSigner } from '@rhinestone/sdk/jwt-server'

const signer = createJwtSigner({
  jwt: {
    privateKey: myJwk, // RS256 private key in JWK format
    integratorId: 'int_abc',
    projectId: 'proj_xyz',
    appId: 'app_prod',
    keyId: 'key_1',
  },
})

const rhinestone = new RhinestoneSDK({
  auth: { mode: 'experimental_jwt', ...signer },
})

createJwtSigner returns { accessToken, getIntentExtensionToken } — the same shape as the auth config, so you can spread it directly. It handles all claim structure, key caching, and intent digest computation internally.

To control which intents your backend sponsors, pass shouldSponsor filters. The signer checks them before signing — denied requests throw a SponsorshipDeniedError:

import { createJwtSigner } from '@rhinestone/sdk/jwt-server'

const signer = createJwtSigner({
  // ...
  shouldSponsor: {
    chain: ({ id }) => [1, 8453, 10].includes(id),
    account: async (address) => isUser(address),
  },
})

Quickstart

Solana helpers and types live in @rhinestone/sdk/solana; EVM helpers, validator addresses and EVM account types live in @rhinestone/sdk/evm.

Create a smart account:

import { RhinestoneSDK } from '@rhinestone/sdk'

const rhinestone = new RhinestoneSDK({
  auth: { mode: 'apiKey', apiKey: 'your-api-key' },
})
const evmConfig = {
  owners: {
    type: 'ecdsa' as const,
    accounts: [signer],
  },
}
const account = await rhinestone.createAccount({ evm: evmConfig })

const address = account.getAddress('evm')

Add an address-only Solana destination when you need to receive tokens there:

import { solanaAddress } from '@rhinestone/sdk/solana'

const crossVmAccount = await rhinestone.createAccount({
  evm: evmConfig,
  solana: { address: solanaAddress(existingSolanaAddress) },
})

Address-only entries cannot prepare, sign, or execute transactions. A managed Solana account names its owner, a private-key or passkey account independent of EVM. With only the owner, the SDK derives the Swig from the owner's public key, and deploy creates it:

import { solanaMainnet } from '@rhinestone/sdk/solana'

const ownedAccount = await rhinestone.createAccount({
  solana: { owner: { type: 'ecdsa' as const, account: solanaSigner } },
})
await ownedAccount.deploy('solana', solanaMainnet)

The derived Swig is the same in development and production. An ECDSA owner must be a viem local account (such as privateKeyToAccount), which carries its public key. Another key as owner derives another Swig, so save ownedAccount.config.solana.swig, the derived Swig's state account (not getAddress('solana'), its wallet), to use that Swig with another key. To use an existing Swig, supply its saved state-account address with swig; the wallet PDA is derived:

const managedSolana = {
  owner: { type: 'ecdsa' as const, account: solanaSigner },
  // Existing Swig state account; the wallet PDA is derived automatically.
  swig: solanaAddress(savedStateAddress),
}

const solanaAccount = await rhinestone.createAccount({
  solana: managedSolana,
  // Optional: a receiver address, or a separately managed EVM config.
  evm: { address: evmReceiver },
})

Adding or changing evm does not change the selected Swig. Plain Solana transfers, instructions, and deliveries use only the Solana owner. An EVM receiver can default a delivery recipient but cannot spend or execute calls. Solana-to-EVM destination calls require a managed EVM account whose existing backend-compatible pair matches the explicit Swig; the Swig derived from the owner makes plain deliveries only. Account construction does not create or verify a Swig; deploy('solana', chain) creates it. Managed Solana runs on production with the default endpoint, or with useDevContracts: true and endpointUrl: 'https://dev.v1.orchestrator.rhinestone.dev'.

Deliver from Solana to EVM, capping what the Swig wallet may debit:

import { solanaDevnet } from '@rhinestone/sdk/solana'

const prepared = await solanaAccount.prepareTransaction({
  // `maxAmount` is a ceiling on the source debit; omit it for no cap.
  source: { chain: solanaDevnet, token: splMint, maxAmount: 4_000_000n },
  // No destination amount: deliver as much as the capped debit buys.
  destination: { chain: baseSepolia, token: usdc, recipient: evmReceiver },
})

Send a crosschain transaction. It spends one source token and lands on one destination; omit source.chain to spend on the destination chain:

const prepared = await account.prepareTransaction({
  source: { chain: baseSepolia, token: usdcOnBaseSepolia },
  destination: {
    chain: arbitrumSepolia,
    token: usdc,
    amount,
    calls: [
      {
        to: usdc,
        value: 0n,
        data: encodeFunctionData({
          abi: erc20Abi,
          functionName: 'transfer',
          args: [recipient, amount],
        }),
      },
    ],
  },
})

const signed = await account.signTransaction(prepared)
const transaction = await account.submitTransaction(signed)
const result = await account.waitForExecution(transaction)

Create a smart session from ABI-driven permissions:

import { toSession } from '@rhinestone/sdk/smart-sessions'

const session = toSession({
  chain: base,
  owners: {
    type: 'ecdsa',
    accounts: [sessionSigner],
  },
  permissions: [
    {
      abi: erc20Abi,
      address: usdc,
      functions: {
        transfer: {
          params: {
            recipient: { condition: 'equal', value: recipient },
            amount: { condition: 'lessThanOrEqual', value: 1000n },
          },
        },
      },
    },
  ],
  crossChainPermits: [
    {
      settlementLayers: ['ACROSS'],
      from: { chain: base, token: usdc, maxAmount: 1000n },
      to: { chain: optimism, token: usdc, recipient },
      allowRecipientNotAccount: true,
      validUntil: new Date(Date.now() + 60 * 60 * 1000),
    },
  ],
})

Unrestricted sessions default to unrestricted ERC-1271 signing. Scoped action sessions default to disabled signing; cross-chain permits install their compiled claim gates instead. Signing can be disabled, time-boxed, or scoped to exact EIP-712 domains and schemas:

const disabled = { mode: 'disabled' } as const
const timeboxed = {
  mode: 'unrestricted',
  validAfter: new Date(),
  validUntil: new Date(Date.now() + 60 * 60 * 1000),
} as const
const scoped = {
  mode: 'scoped',
  allowedContents: [
    {
      domain: {
        name: 'Permit2',
        chainId: base.id,
        verifyingContract: permit2,
      },
      types: {
        Permit: [
          { name: 'spender', type: 'address' },
          { name: 'amount', type: 'uint256' },
        ],
      },
      primaryType: 'Permit',
    },
  ],
} as const

A scoped entry constrains its domain and schema, not message values. Scoped configuration can be enabled on-chain, but this SDK intentionally rejects scoped direct signing until safe ERC-7739 signature emission is available.

For a complete walkthrough, see the Quickstart guide.

Migrating from Orchestrator SDK

To migrate from the Orchestrator SDK, replace all imports of @rhinestone/orchestrator-sdk with @rhinestone/sdk.

Let us know if you encounter any issues!

Contributing

For feature or change requests, feel free to open a PR, start a discussion or get in touch with us.

About

Smart wallets and multichain transactions for your application

Resources

Contributing

Security policy

Stars

14 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages