@bounded-sh/core 0.0.42 → 0.0.44

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/dist/types.d.ts CHANGED
@@ -56,14 +56,38 @@ export interface User {
56
56
  * prompt. `false`/absent for real (email/social/wallet) logins.
57
57
  */
58
58
  isAnonymous?: boolean;
59
+ /**
60
+ * REAL onchain EVM wallet address (resolves @user.evmAddress). Present for EVM
61
+ * wallet/SIWE logins; `null`/absent for Solana-wallet and email-only logins
62
+ * that haven't linked an EVM wallet. Canonical LOWERCASE 0x-hex — the identity
63
+ * layer matches case-sensitively, so it is normalized at the boundary. Derived
64
+ * from the idToken's `custom:evmWalletAddress` claim. For EVM wallet logins
65
+ * `id === evmAddress` and `address` (the Solana wallet) is null.
66
+ */
67
+ evmAddress?: string | null;
59
68
  provider: AuthProvider;
60
69
  }
61
70
  export interface EVMTransaction {
62
- contractAddress: string;
63
- contractAbi: string | any;
64
- functionName: string;
65
- value: string;
66
- txArgs: any[];
71
+ contractAddress?: string;
72
+ contractAbi?: string | any;
73
+ functionName?: string;
74
+ txArgs?: any[];
75
+ /** Target contract (the per-chain BoundedRuntime address). */
76
+ to?: string;
77
+ /** ABI-encoded calldata (setDocuments(...)). */
78
+ data?: string;
79
+ /** Wei value to send with the call, as a decimal or 0x-hex string. Default "0". */
80
+ value?: string;
81
+ /** EIP-155 chain id the tx must execute on (used for the chain-switch guard). */
82
+ chainId?: number;
83
+ /** Optional gas limit hint (the worker's eth_estimateGas ×1.2). */
84
+ gas?: string;
85
+ /** Optional EIP-1559 max fee per gas. */
86
+ maxFeePerGas?: string;
87
+ /** Optional EIP-1559 max priority fee per gas. */
88
+ maxPriorityFeePerGas?: string;
89
+ /** Optional nonce; normally omitted so the signing wallet fills it. */
90
+ nonce?: number;
67
91
  }
68
92
  export interface SolTransaction {
69
93
  appId: string;
@@ -1,6 +1,15 @@
1
1
  export declare function genNonce(): Promise<any>;
2
2
  export declare function genAuthNonce(): Promise<any>;
3
- export declare function createSessionWithSignature(address: string, message: string, signature: string): Promise<any>;
3
+ /**
4
+ * Exchange a wallet signature for a Bounded session at the /session issuer.
5
+ *
6
+ * @param authMethodOverride the exact /session discriminator to send (e.g. 'siwe'
7
+ * for the SIWE/EVM path). When omitted the method is derived from config: an
8
+ * aliased method (evm-wallet → siwe) maps through SESSION_METHOD_ALIASES, a
9
+ * Solana wallet/guest method passes through verbatim, and anything else
10
+ * defaults to the canonical 'phantom' the issuer accepts for a signature.
11
+ */
12
+ export declare function createSessionWithSignature(address: string, message: string, signature: string, authMethodOverride?: string): Promise<any>;
4
13
  export declare function refreshSession(refreshToken: string, issuer?: string): Promise<any>;
5
14
  export declare class SessionRevokeError extends Error {
6
15
  readonly cause?: unknown;
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Selectors derived from the canonical BoundedRuntime signatures (BoundedTypes.sol):
3
+ *
4
+ * cast sig 'setDocuments(string,(string[],bool,(string,uint8,uint8,bytes)[])[])'
5
+ * => 0x0827b094
6
+ * cast sig 'setDocumentsAttested(string,(string[],bool,(string,uint8,uint8,bytes)[])[],(bytes32,uint256,uint256,uint8,bytes32,bytes32))'
7
+ * => 0x87b111c4
8
+ *
9
+ * Keep the signatures beside the constants: changing either Solidity tuple is an
10
+ * ABI break and must deliberately update these values and the Foundry goldens.
11
+ */
12
+ export declare const BOUNDED_RUNTIME_SET_DOCUMENTS_SELECTOR = "0x0827b094";
13
+ export declare const BOUNDED_RUNTIME_SET_DOCUMENTS_ATTESTED_SELECTOR = "0x87b111c4";
14
+ export interface EvmTransactionPolicy {
15
+ /** A single allowed chain. */
16
+ chainId?: number;
17
+ /** Runtime for `chainId` (single-chain shorthand). */
18
+ runtimeAddress?: string;
19
+ /** Per-chain runtime allowlist for a multi-chain signer. */
20
+ runtimeAddresses?: Record<string, string>;
21
+ }
22
+ /** Minimal structural transaction surface consumed by the canonical validator.
23
+ * Kept local so security-sensitive server/Worker signers do not pull the
24
+ * browser/client type graph merely to validate a prebuilt runtime write. */
25
+ export interface EvmWriteTransaction {
26
+ to?: string;
27
+ data?: string;
28
+ value?: string;
29
+ chainId?: number;
30
+ nonce?: number;
31
+ }
32
+ /**
33
+ * Fail closed unless calldata is a byte-for-byte canonical ABI encoding of one
34
+ * supported BoundedRuntime write. This is the defense used by direct signer
35
+ * surfaces; the higher-level write validator below additionally binds app/ops.
36
+ */
37
+ export declare function assertCanonicalBoundedRuntimeWriteCalldata(rawData: unknown): void;
38
+ /** Verify the untrusted 202 payload is exactly the governed write the app asked for. */
39
+ export declare function assertEvmTransactionMatchesWrite(transaction: EvmWriteTransaction, context: {
40
+ appId: string;
41
+ documents: Array<{
42
+ destinationPath: string;
43
+ document: any;
44
+ }>;
45
+ policy?: EvmTransactionPolicy | null;
46
+ }): void;
@@ -0,0 +1,40 @@
1
+ export interface SiweMessageOptions {
2
+ /**
3
+ * EIP-155 chain id the wallet is connected to. The verifier requires a
4
+ * positive safe integer; write-time chain/runtime policy is enforced
5
+ * separately before transaction signing. Defaults to 1 when unavailable.
6
+ */
7
+ chainId?: number;
8
+ /** Single-line statement (must not contain a newline). Defaults to the canonical prompt. */
9
+ statement?: string;
10
+ /** Issued-at instant. Defaults to now. */
11
+ issuedAt?: Date;
12
+ /** Expiration instant. Defaults to issuedAt + 5 min (inside the issuer's 10-min cap). */
13
+ expirationTime?: Date;
14
+ /** EIP-4361 version; the grammar fixes this at "1". */
15
+ version?: string;
16
+ }
17
+ /**
18
+ * Build the canonical EIP-4361 SIWE message the bounded-auth issuer verifies.
19
+ *
20
+ * @param address the connected EVM account (lowercased into the prompt).
21
+ * @param nonce single-use nonce from genAuthNonce().
22
+ * @param appId the target app id (bound as the sole `bounded:app:<appId>` resource).
23
+ * @param domain RFC-3986 authority of the requesting site (e.g. window.location.host).
24
+ * @param uri the requesting URI; its origin is bound to the domain and actual browser Origin.
25
+ */
26
+ export declare function genSiweMessage(address: string, nonce: string, appId: string, domain: string, uri: string, options?: SiweMessageOptions): string;
27
+ /**
28
+ * Lowercase an EVM address to the canonical identity form. EVM addresses are
29
+ * case-insensitive on-chain but the identity layer (@user.evmAddress) matches
30
+ * case-sensitively, so every boundary normalizes to lowercase. Does not validate
31
+ * shape — use normalizeEvmAddress() when the input is untrusted.
32
+ */
33
+ export declare function toLowerEvmAddress(address: string): string;
34
+ /**
35
+ * Normalize an untrusted EVM address to canonical lowercase 0x-hex, or null when
36
+ * it isn't a well-formed 20-byte hex address. Mirrors the realtime-worker's
37
+ * normalizeEvmAddress (auth.ts) EXACTLY so a client-derived @user.evmAddress and
38
+ * the server-authenticated one are byte-identical (fail-closed on malformed).
39
+ */
40
+ export declare function normalizeEvmAddress(raw: unknown): string | null;
@@ -19,12 +19,19 @@ export declare class ServerSessionManager {
19
19
  private session;
20
20
  private pendingSession;
21
21
  private readonly keypair;
22
+ private readonly sessionFactory;
22
23
  private constructor();
23
24
  /**
24
25
  * Create a session manager for a specific keypair.
25
26
  * Each instance has its own independent session cache.
26
27
  */
27
28
  static forKeypair(keypair: Keypair): ServerSessionManager;
29
+ /**
30
+ * Create an isolated server session manager for a non-Solana signer (currently
31
+ * EVM/SIWE). The factory must perform the signature exchange and return the
32
+ * canonical signer address with its tokens; no signer state becomes global.
33
+ */
34
+ static forSessionFactory(factory: () => Promise<ServerSession>): ServerSessionManager;
28
35
  private createSession;
29
36
  getSession(): Promise<ServerSession>;
30
37
  setSession(session: ServerSession): void;
@@ -11,10 +11,12 @@ export declare function getUserInfo(isServer: boolean): Promise<any>;
11
11
  export interface UserIdentity {
12
12
  /** @user.id — universal stable identity (custom:userId only). */
13
13
  id: string | null;
14
- /** @user.address — REAL wallet; null for email-only logins. */
14
+ /** @user.address — REAL Solana wallet; null for email-only / EVM-wallet logins. */
15
15
  address: string | null;
16
16
  /** @user.email — verified lowercased email; null for wallet/SIWS logins. */
17
17
  email: string | null;
18
+ /** @user.evmAddress — REAL EVM wallet, canonical lowercase 0x-hex; null when unlinked. */
19
+ evmAddress: string | null;
18
20
  }
19
21
  /**
20
22
  * Derive { id, address, email } from an idToken's claims.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bounded-sh/core",
3
- "version": "0.0.42",
3
+ "version": "0.0.44",
4
4
  "description": "Shared client, data-plane, and transport primitives for Bounded, the full-stack app builder and runtime for AI-built apps: policy-enforced operations, files, functions, and realtime.",
5
5
  "homepage": "https://bounded.sh/docs/sdk",
6
6
  "main": "./dist/index.js",
@@ -16,7 +16,7 @@
16
16
  "scripts": {
17
17
  "build": "rm -rf ./dist ./.rollup-tmp && tsc -p tsconfig.build.json --outDir .rollup-tmp --declarationDir .rollup-tmp --emitDeclarationOnly false && rollup -c && tsc -p tsconfig.build.json --emitDeclarationOnly --declarationDir dist && rm -rf ./.rollup-tmp",
18
18
  "watch": "rollup -c -w",
19
- "test": "node src/client/run-config-network-test.mjs && node src/client/run-read-principal-test.mjs && node src/client/run-principal-collision-test.mjs && node src/client/run-row-shape-test.mjs && node src/client/run-transport-test.mjs && node src/client/run-public-export-surface-test.mjs && node src/client/run-live-auth-test.mjs && node src/client/run-live-view-principal-test.mjs && node src/client/run-subscription-auth-error-test.mjs && node src/client/run-onchain-validation-test.mjs && node src/client/websocket-auth-url.test.mjs",
19
+ "test": "node src/client/run-config-network-test.mjs && node src/client/run-read-principal-test.mjs && node src/client/run-principal-collision-test.mjs && node src/client/run-row-shape-test.mjs && node src/client/run-transport-test.mjs && node src/client/run-public-export-surface-test.mjs && node src/client/run-live-auth-test.mjs && node src/client/run-live-view-principal-test.mjs && node src/client/run-subscription-auth-error-test.mjs && node src/client/run-onchain-validation-test.mjs && node src/client/run-evm-dispatch-test.mjs && node src/utils/evm/run-evm-utils-test.mjs && node src/client/websocket-auth-url.test.mjs",
20
20
  "prepare": "npm run build"
21
21
  },
22
22
  "files": [
@@ -64,4 +64,4 @@
64
64
  "publishConfig": {
65
65
  "access": "public"
66
66
  }
67
- }
67
+ }