@boundlessfi/identity-sdk 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +174 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
# @boundlessfi/identity-sdk
|
|
2
|
+
|
|
3
|
+
The **Boundless Identity SDK** provides a seamless way to integrate **Passkey-based Smart Wallets** into your application. Built on top of [Smart Account Kit](https://github.com/stellar/smart-account-kit) and [Better-Auth](https://github.com/better-auth/better-auth), it enables users to sign up with a passkey, automatically deploying a non-custodial Stellar Smart Wallet that is linked to their authenticated session.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 🔑 **Passkey-First Authentication**: Users log in and sign transactions using FaceID, TouchID, or other WebAuthn credentials.
|
|
8
|
+
- 🔗 **Session Linking**: Automatically links on-chain smart wallets to your application's user database via Better-Auth.
|
|
9
|
+
- 💳 **Smart Wallet Management**: Deploy contracts, track balances, and transfer assets (XLM & Custom Tokens).
|
|
10
|
+
- 🛡️ **Recovery**: Add multiple passkeys for account recovery.
|
|
11
|
+
- ⛽ **Gas & Fees**: Optimized wrapper for transaction submission.
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install @boundlessfi/identity-sdk
|
|
19
|
+
# or
|
|
20
|
+
pnpm add @boundlessfi/identity-sdk
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### Peer Dependencies
|
|
24
|
+
|
|
25
|
+
Ensure you have the following peer dependencies installed:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npm install better-auth smart-account-kit
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
## Backend Integration
|
|
34
|
+
|
|
35
|
+
The SDK provides a **Better-Auth Plugin** to handle linking Stellar addresses and Passkey credentials to your users.
|
|
36
|
+
|
|
37
|
+
### 1. Register the Plugin
|
|
38
|
+
|
|
39
|
+
In your Better-Auth configuration (e.g., `auth.ts`):
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
import { betterAuth } from "better-auth";
|
|
43
|
+
import { boundlessStellarPlugin } from "@boundlessfi/identity-sdk/server";
|
|
44
|
+
|
|
45
|
+
export const auth = betterAuth({
|
|
46
|
+
// ... your other config
|
|
47
|
+
plugins: [
|
|
48
|
+
boundlessStellarPlugin(), // <--- Add this
|
|
49
|
+
],
|
|
50
|
+
});
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
This plugin automatically adds `stellarAddress` and `credentialId` fields to your User schema and exposes the `/api/auth/stellar/link` endpoint.
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
## Frontend Usage
|
|
58
|
+
|
|
59
|
+
### 1. Initialize the SDK
|
|
60
|
+
|
|
61
|
+
Create an instance of `BoundlessSDK` in your application (e.g., via a React Context or global singleton).
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
import { BoundlessSDK } from "@boundlessfi/identity-sdk";
|
|
65
|
+
|
|
66
|
+
const boundless = new BoundlessSDK({
|
|
67
|
+
network: "testnet", // or "mainnet"
|
|
68
|
+
rpcUrl: "https://soroban-testnet.stellar.org", // Optional, defaults to Horizon
|
|
69
|
+
backendUrl: "http://localhost:3000", // Your Better-Auth API base URL
|
|
70
|
+
rpId: "localhost", // WebAuthn Relying Party ID (domain)
|
|
71
|
+
rpName: "My App", // App Name for Passkey Prompt
|
|
72
|
+
// relayerProxyUrl: "..." // Optional: For gas sponsorship
|
|
73
|
+
});
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### 2. Connect or Register a Wallet
|
|
77
|
+
|
|
78
|
+
#### Connect (Returning User)
|
|
79
|
+
|
|
80
|
+
Prompts the user to sign in with an existing passkey. Checks if a wallet is already deployed.
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
const result = await boundless.connect();
|
|
84
|
+
// Or force the browser prompt:
|
|
85
|
+
// const result = await boundless.connect({ prompt: true });
|
|
86
|
+
|
|
87
|
+
if (result) {
|
|
88
|
+
console.log("Connected:", result.walletAddress);
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
#### Register (New User)
|
|
93
|
+
|
|
94
|
+
Creates a new Passkey credential, deploys the Smart Wallet on-chain, and links it to the current auth session.
|
|
95
|
+
> **Note:** The user must be logged into Better-Auth before calling `register`.
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
try {
|
|
99
|
+
const result = await boundless.register("user_email_or_name");
|
|
100
|
+
console.log("New Wallet Deployed:", result.walletAddress);
|
|
101
|
+
} catch (error) {
|
|
102
|
+
console.error("Registration failed:", error);
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### 3. Check Balances
|
|
107
|
+
|
|
108
|
+
Fetch Native XLM or Custom Token balances.
|
|
109
|
+
|
|
110
|
+
```typescript
|
|
111
|
+
// Native XLM
|
|
112
|
+
const xlmBalance = await boundless.getBalance(userAddress);
|
|
113
|
+
|
|
114
|
+
// Custom Token (by Contract ID)
|
|
115
|
+
const usdcBalance = await boundless.getBalance(userAddress, "CDLZFC3SYJYDZS7K67TZIK764C4UGR2HXQ4Q47I2255W577333N3K...");
|
|
116
|
+
|
|
117
|
+
// Custom Token (by Asset Code:Issuer)
|
|
118
|
+
const tokenBalance = await boundless.getBalance(userAddress, "USDC:GBBD47IF...");
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### 4. Send Transactions
|
|
122
|
+
|
|
123
|
+
Transfer XLM or Tokens.
|
|
124
|
+
|
|
125
|
+
```typescript
|
|
126
|
+
const txResult = await boundless.transfer(
|
|
127
|
+
"G...", // Recipient Address
|
|
128
|
+
"10.5", // Amount
|
|
129
|
+
"XLM" // Asset (or Contract ID / Code:Issuer)
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
if (txResult.success) {
|
|
133
|
+
console.log("Tx Hash:", txResult.hash);
|
|
134
|
+
}
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### 5. Account Recovery
|
|
138
|
+
|
|
139
|
+
Add a secondary passkey (e.g., iCloud Keychain or YubiKey) to ensure access isn't lost.
|
|
140
|
+
|
|
141
|
+
```typescript
|
|
142
|
+
await boundless.addRecoveryKey({
|
|
143
|
+
appName: "My App",
|
|
144
|
+
userName: "user@example.com",
|
|
145
|
+
nickname: "Backup Key"
|
|
146
|
+
});
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
---
|
|
150
|
+
|
|
151
|
+
## Advanced Usage
|
|
152
|
+
|
|
153
|
+
### Accessing Internal Tools
|
|
154
|
+
|
|
155
|
+
You can access the underlying `SmartAccountKit` instance for lower-level operations.
|
|
156
|
+
|
|
157
|
+
```typescript
|
|
158
|
+
const kit = boundless.smartAccountKit;
|
|
159
|
+
// Use kit directly...
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### Events
|
|
163
|
+
|
|
164
|
+
Listen to wallet events for UI updates.
|
|
165
|
+
|
|
166
|
+
```typescript
|
|
167
|
+
const unsubscribe = boundless.onEvent("walletConnected", () => {
|
|
168
|
+
console.log("Wallet connected!");
|
|
169
|
+
});
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
## License
|
|
173
|
+
|
|
174
|
+
MIT
|