1
Instalar
npm i @meru.app/device-signer
# pubspec.yaml
dependencies:
meru_device_wallet: ^0.1.0
// Package.swift
.package(url: "https://github.com/getmeru/meru-device-wallet-swift.git", from: "0.1.0")
// build.gradle.kts
implementation("app.meru:meru-device-wallet:0.1.0")
2
Iniciar sesión (código por email o passkey)
import { createMeruAuth } from "@meru.app/device-signer/auth";
import * as SecureStore from "expo-secure-store";
const auth = createMeruAuth({
authBase: "https://stablecoin-api.getmeru.com",
companyId: "<tu company id público>",
passkeyDomain: "yourapp.com",
storage: {
getItem: (k) => SecureStore.getItemAsync(k),
setItem: (k, v) => SecureStore.setItemAsync(k, v),
removeItem: (k) => SecureStore.deleteItemAsync(k),
},
});
await auth.sendEmailCode(email);
const session = await auth.verifyEmailCode(email, code);
// usuarios que vuelven: const session = await auth.loginWithPasskey();
final auth = MeruAuth(
authBase: 'https://stablecoin-api.getmeru.com',
companyId: '<tu company id público>',
passkeyDomain: 'yourapp.com',
);
await auth.sendEmailCode(email);
final session = await auth.verifyEmailCode(email, code);
// usuarios que vuelven: final session = await auth.loginWithPasskey();
let auth = MeruAuth(
authBase: URL(string: "https://stablecoin-api.getmeru.com")!,
companyId: "<tu company id público>",
passkeyDomain: "yourapp.com"
)
_ = try await auth.sendEmailCode(email)
let session = try await auth.verifyEmailCode(email, code: code)
// usuarios que vuelven: let session = try await auth.loginWithPasskey()
val auth = MeruAuth(
context = applicationContext,
authBase = "https://stablecoin-api.getmeru.com",
companyId = "<tu company id público>",
passkeyDomain = "yourapp.com",
)
auth.sendEmailCode(email)
val session = auth.verifyEmailCode(email, code)
// usuarios que vuelven: val session = auth.loginWithPasskey(activity)
3
Ejecutar el flujo de billetera
status() le dice a cada dispositivo qué hacer exactamente — así un segundo
teléfono obtiene recuperar, nunca una billetera duplicada.import { MeruDeviceWallet } from "@meru.app/device-signer/wallet";
const wallet = new MeruDeviceWallet({
baseUrl: "https://your-app.com/api/meru",
userId: session.user.id,
getToken: async () => auth.current()?.token ?? null,
});
const { state } = await wallet.status();
if (state === "create") await wallet.enroll({ activate: true });
else if (state === "recover") await wallet.recover();
await wallet.send("GB7C…FB2Q", 5); // aprobado en el dispositivo, Meru cubre la comisión
final wallet = MeruDeviceWallet(
baseUrl: 'https://your-app.com/api/meru',
getToken: () async => auth.current?.token,
keyId: 'meru.device-key.${session.user.id}',
);
switch ((await wallet.status()).state) {
case WalletState.create: await wallet.enroll(activate: true);
case WalletState.recover: await wallet.recover();
case WalletState.ready: break;
}
await wallet.send('GB7C…FB2Q', 5);
let wallet = MeruDeviceWallet(
baseURL: URL(string: "https://your-app.com/api/meru")!,
userId: session.user.id,
getToken: { auth.current?.token }
)
switch try await wallet.status().state {
case .create: try await wallet.enroll(activate: true)
case .recover: try await wallet.recover()
case .ready: break
}
let txHash = try await wallet.send(to: "GB7C…FB2Q", amount: 5)
val wallet = MeruDeviceWallet(
baseUrl = "https://your-app.com/api/meru",
keys = DeviceKeyStore(applicationContext),
userId = session.user.id,
getToken = { auth.current?.token },
)
when (wallet.status().state) {
WalletState.CREATE -> wallet.enroll(activate = true)
WalletState.RECOVER -> wallet.recover()
WalletState.READY -> {}
}
val txHash = wallet.send("GB7C…FB2Q", 5.0)
El
authBase + companyId vienen de Meru; el backendBase
(https://your-app.com/api/meru) es tu propio servidor con el handler de Meru.
Ver Introducción.