@boundlessfi/identity-sdk 0.1.1

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.
@@ -0,0 +1,37 @@
1
+ export const NETWORK_CONFIGS = {
2
+ testnet: {
3
+ networkPassphrase: "Test SDF Network ; September 2015",
4
+ defaultRpcUrl: "https://soroban-testnet.stellar.org",
5
+ accountWasmHash:
6
+ "a12e8fa9621efd20315753bd4007d974390e31fbcb4a7ddc4dd0a0dec728bf2e",
7
+ webauthnVerifierAddress:
8
+ "CBSHV66WG7UV6FQVUTB67P3DZUEJ2KJ5X6JKQH5MFRAAFNFJUAJVXJYV",
9
+ ed25519VerifierAddress:
10
+ "CDGMOL3BP6Y6LYOXXTRNXBNJ2SLNTQ47BGG3LOS2OBBE657E3NYCN54B",
11
+ nativeTokenContract:
12
+ "CDLZFC3SYJYDZT7K67VZ75HPJVIEUVNIXF47ZG2FB2RMQQVU2HHGCYSC",
13
+ policies: {
14
+ threshold: "CCT4MMN5MJ6O2OU6LXPYTCVORQ2QVTBMDJ7MYBZQ2ULSYQVUIYP4IFYD",
15
+ spendingLimit: "CBMMWY54XOV6JJHSWCMKWWPXVRXASR5U26UJMLZDN4SP6CFFTVZARPTY",
16
+ weightedThreshold:
17
+ "CBYDQ5XUBP7G24FI3LLGLW56QZCIEUSVRPX7FVOUCKHJQQ6DTF6BQGBZ",
18
+ },
19
+ relayerUrl: "",
20
+ },
21
+ mainnet: {
22
+ networkPassphrase: "Public Global Stellar Network ; September 2015",
23
+ defaultRpcUrl: "https://soroban-rpc.mainnet.stellar.org",
24
+ accountWasmHash: "REPLACE_WITH_MAINNET_WASM_HASH",
25
+ webauthnVerifierAddress: "REPLACE_WITH_MAINNET_VERIFIER",
26
+ ed25519VerifierAddress: "REPLACE_WITH_MAINNET_VERIFIER",
27
+ nativeTokenContract: "REPLACE_WITH_MAINNET_CONTRACT",
28
+ policies: {
29
+ threshold: "REPLACE_WITH_MAINNET_POLICY",
30
+ spendingLimit: "REPLACE_WITH_MAINNET_POLICY",
31
+ weightedThreshold: "REPLACE_WITH_MAINNET_POLICY",
32
+ },
33
+ relayerUrl: "",
34
+ },
35
+ } as const;
36
+
37
+ export type NetworkName = keyof typeof NETWORK_CONFIGS;
package/src/errors.ts ADDED
@@ -0,0 +1,18 @@
1
+ import { SmartAccountError } from "smart-account-kit";
2
+
3
+ export class BoundlessAuthError extends SmartAccountError {
4
+ constructor(message: string) {
5
+ super(message, "BOUNDLESS_AUTH" as any);
6
+ this.name = "BoundlessAuthError";
7
+ }
8
+ }
9
+
10
+ export class BoundlessLinkError extends SmartAccountError {
11
+ constructor(
12
+ message: string,
13
+ public statusCode?: number,
14
+ ) {
15
+ super(message, "BOUNDLESS_LINK" as any);
16
+ this.name = "BoundlessLinkError";
17
+ }
18
+ }
package/src/index.ts ADDED
@@ -0,0 +1,17 @@
1
+ export * from "./boundless-sdk";
2
+ export * from "./types";
3
+ export * from "./errors";
4
+ export * from "./constants";
5
+ export * from "./utils";
6
+ export {
7
+ SmartAccountError,
8
+ WalletNotConnectedError,
9
+ CredentialNotFoundError,
10
+ SignerNotFoundError,
11
+ SimulationError,
12
+ SubmissionError,
13
+ ValidationError,
14
+ WebAuthnError,
15
+ SessionError,
16
+ wrapError,
17
+ } from "smart-account-kit";
@@ -0,0 +1 @@
1
+ export { boundlessStellarPlugin } from "./stellar-plugin";
@@ -0,0 +1,66 @@
1
+ import type { BetterAuthPlugin } from "better-auth";
2
+
3
+ export const boundlessStellarPlugin = (): BetterAuthPlugin =>
4
+ ({
5
+ id: "boundless-stellar",
6
+
7
+ schema: {
8
+ user: {
9
+ fields: {
10
+ stellarAddress: {
11
+ type: "string",
12
+ required: false,
13
+ unique: true,
14
+ },
15
+ credentialId: {
16
+ type: "string",
17
+ required: false,
18
+ },
19
+ },
20
+ },
21
+ },
22
+
23
+ endpoints: {
24
+ linkStellar: {
25
+ path: "/stellar/link",
26
+ method: ["POST"],
27
+ handler: async (ctx: any) => {
28
+ // ctx is the Better-Auth handler context.
29
+ // ctx.request.body contains the parsed JSON.
30
+ // ctx.context.db is the database adapter.
31
+ // ctx.context.session.user is the authenticated user (or null).
32
+
33
+ const session = await ctx.context.auth.getSession(ctx.request);
34
+ if (!session?.user) {
35
+ return ctx.json({ error: "Unauthorized" }, { status: 401 });
36
+ }
37
+
38
+ const body = ctx.request.body as { stellarAddress?: unknown };
39
+ const { stellarAddress } = body;
40
+
41
+ // Validate C-address format
42
+ if (
43
+ typeof stellarAddress !== "string" ||
44
+ stellarAddress.length !== 56 ||
45
+ !stellarAddress.startsWith("C")
46
+ ) {
47
+ return ctx.json(
48
+ {
49
+ error:
50
+ "Invalid stellarAddress. Must be a 56-char Soroban contract ID starting with C.",
51
+ },
52
+ { status: 400 },
53
+ );
54
+ }
55
+
56
+ // Persist
57
+ await ctx.context.db.update("user", {
58
+ where: { id: session.user.id },
59
+ update: { stellarAddress },
60
+ });
61
+
62
+ return ctx.json({ success: true });
63
+ },
64
+ },
65
+ },
66
+ }) as any;
package/src/types.ts ADDED
@@ -0,0 +1,75 @@
1
+ // Re-export upstream types the consuming app will need.
2
+ // Declare Boundless-specific types below.
3
+
4
+ // ── re-exports from smart-account-kit ──────────────────────────
5
+
6
+ export type {
7
+ StorageAdapter,
8
+ StoredCredential,
9
+ StoredSession,
10
+ CreateWalletResult,
11
+ ConnectWalletResult,
12
+ TransactionResult,
13
+ AssembledTransaction,
14
+ ExternalWalletAdapter,
15
+ SelectedSigner,
16
+ ContractSigner,
17
+ ContextRule,
18
+ ContextRuleType,
19
+ } from "smart-account-kit";
20
+
21
+ // ── Boundless SDK config ────────────────────────────────────────
22
+
23
+ export interface BoundlessSdkConfig {
24
+ network: "mainnet" | "testnet";
25
+ rpcUrl?: string;
26
+ rpId: string;
27
+ rpName: string;
28
+ backendUrl: string;
29
+ relayerProxyUrl?: string;
30
+ storage?: import("smart-account-kit").StorageAdapter;
31
+ }
32
+
33
+ // ── connect / register results ──────────────────────────────────
34
+
35
+ export interface ConnectOptions {
36
+ prompt?: boolean;
37
+ }
38
+
39
+ export interface ConnectResult {
40
+ walletAddress: string; // C… contract ID
41
+ credentialId: string;
42
+ isNew: boolean;
43
+ }
44
+
45
+ // ── signAndSubmit result ────────────────────────────────────────
46
+
47
+ export interface SignAndSubmitResult {
48
+ hash: string;
49
+ success: boolean;
50
+ }
51
+
52
+ // ── recovery key ────────────────────────────────────────────────
53
+
54
+ export interface AddRecoveryKeyOptions {
55
+ appName: string;
56
+ userName: string;
57
+ nickname?: string;
58
+ }
59
+
60
+ export interface RecoveryKeyResult {
61
+ credentialId: string;
62
+ }
63
+
64
+ // ── events ──────────────────────────────────────────────────────
65
+
66
+ export type BoundlessEventName =
67
+ | "walletConnected"
68
+ | "walletDisconnected"
69
+ | "credentialCreated"
70
+ | "credentialDeleted"
71
+ | "sessionExpired"
72
+ | "transactionSigned"
73
+ | "transactionSubmitted";
74
+
75
+ export type BoundlessEventHandler = (...args: unknown[]) => void;
package/src/utils.ts ADDED
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Validate that a string looks like a Soroban contract address.
3
+ * Soroban contract IDs start with 'C' and are 56 characters (StrKey).
4
+ */
5
+ export function isValidContractAddress(addr: string): boolean {
6
+ return typeof addr === "string" && addr.length === 56 && addr.startsWith("C");
7
+ }
8
+
9
+ /**
10
+ * Validate that a string looks like a Stellar account address (G…).
11
+ */
12
+ export function isValidStellarAddress(addr: string): boolean {
13
+ return typeof addr === "string" && addr.length === 56 && addr.startsWith("G");
14
+ }
15
+
16
+ /**
17
+ * Sleep for N milliseconds. Useful in retry loops.
18
+ */
19
+ export function sleep(ms: number): Promise<void> {
20
+ return new Promise((resolve) => setTimeout(resolve, ms));
21
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "ESNext",
5
+ "moduleResolution": "bundler",
6
+ "strict": true,
7
+ "noImplicitAny": true,
8
+ "strictNullChecks": true,
9
+ "declaration": true,
10
+ "declarationMap": true,
11
+ "sourceMap": true,
12
+ "outDir": "./dist",
13
+ "rootDir": "./src",
14
+ "esModuleInterop": true,
15
+ "skipLibCheck": true,
16
+ "forceConsistentCasingInFileNames": true
17
+ },
18
+ "include": ["src/**/*"],
19
+ "exclude": ["node_modules", "dist"]
20
+ }