better-near-auth 1.6.3 → 1.6.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/dist/client.js CHANGED
@@ -49,7 +49,8 @@ z.object({
49
49
  message: z.string(),
50
50
  recipient: z.string(),
51
51
  nonce: z.string(),
52
- accountId: AccountIdSchema
52
+ accountId: AccountIdSchema,
53
+ callbackUrl: z.string().optional()
53
54
  });
54
55
  z.object({
55
56
  accountId: AccountIdSchema,
@@ -64,7 +65,8 @@ z.object({
64
65
  message: z.string(),
65
66
  recipient: z.string(),
66
67
  nonce: z.string(),
67
- accountId: AccountIdSchema
68
+ accountId: AccountIdSchema,
69
+ callbackUrl: z.string().optional()
68
70
  });
69
71
  z.object({ payload: z.string() });
70
72
  z.object({
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","names":[],"sources":["../src/types.ts","../src/client.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { AccountIdSchema, type AccountId } from \"near-kit/schemas\";\nimport type { AccountState } from \"near-kit\";\n\nexport type { AccountId };\n\nexport interface NearAccount {\n\tid: string;\n\tuserId: string;\n\taccountId: string;\n\tnetwork: \"mainnet\" | \"testnet\";\n\tpublicKey: string;\n\tisPrimary: boolean;\n\tcreatedAt: Date;\n}\n\nexport interface ListedNearAccount extends NearAccount {\n\tproviderId: \"siwn\";\n\tisActive: boolean;\n\tisAvailable: boolean;\n}\n\nexport interface ListAccountsResponseT {\n\taccounts: ListedNearAccount[];\n\tactiveAccount: ListedNearAccount | null;\n\tavailableAccounts: ListedNearAccount[];\n}\n\nexport interface SetPrimaryAccountResponseT extends ListAccountsResponseT {\n\tsuccess: boolean;\n\taccountId: string;\n\tnetwork: \"mainnet\" | \"testnet\";\n\tmessage: string;\n}\n\nexport const socialImageSchema = z.object({\n\turl: z.string().optional(),\n\tipfs_cid: z.string().optional(),\n});\n\nexport const profileSchema = z.object({\n\tname: z.string().optional(),\n\tdescription: z.string().optional(),\n\timage: socialImageSchema.optional(),\n\tbackgroundImage: socialImageSchema.optional(),\n\tlinktree: z.record(z.string(), z.string()).optional(),\n});\n\nexport type SocialImage = z.infer<typeof socialImageSchema>;\nexport type Profile = z.infer<typeof profileSchema>;\n\nconst signedMessageSchema = z.object({\n\taccountId: z.string(),\n\tpublicKey: z.string(),\n\tsignature: z.string(),\n\tstate: z.string().optional(),\n});\n\nexport const LinkAccountRequest = z.object({\n\tsignedMessage: signedMessageSchema,\n\tmessage: z.string(),\n\trecipient: z.string(),\n\tnonce: z.string(),\n\taccountId: AccountIdSchema,\n});\n\nexport const SetPrimaryAccountRequest = z.object({\n\taccountId: AccountIdSchema,\n\tnetwork: z.enum([\"mainnet\", \"testnet\"]).optional(),\n});\n\nexport const NonceRequest = z.object({\n\taccountId: AccountIdSchema,\n\tnetworkId: z.union([z.literal(\"mainnet\"), z.literal(\"testnet\")])\n});\n\nexport const VerifyRequest = z.object({\n\tsignedMessage: signedMessageSchema,\n\tmessage: z.string(),\n\trecipient: z.string(),\n\tnonce: z.string(),\n\taccountId: AccountIdSchema,\n});\n\nexport const RelayRequest = z.object({\n\tpayload: z.string(),\n});\nexport type RelayRequestT = z.infer<typeof RelayRequest>;\n\nexport const RelayResponse = z.object({\n\ttxHash: z.string(),\n\tstatus: z.enum([\"pending\", \"completed\", \"failed\"]),\n});\nexport type RelayResponseT = z.infer<typeof RelayResponse>;\n\nexport const RelayStatusResponse = z.object({\n\tstatus: z.enum([\"pending\", \"completed\", \"failed\"]),\n\tgasUsed: z.string().optional(),\n\toutcome: z.unknown().optional(),\n});\nexport type RelayStatusResponseT = z.infer<typeof RelayStatusResponse>;\n\nexport const ViewContractRequest = z.object({\n\tcontractId: z.string(),\n\tmethodName: z.string(),\n\targs: z.record(z.string(), z.any()).optional(),\n});\nexport type ViewContractRequestT = z.infer<typeof ViewContractRequest>;\n\nexport const NonceResponse = z.object({ nonce: z.string() });\nexport const VerifyResponse = z.object({\n\ttoken: z.string(),\n\tsuccess: z.literal(true),\n\tuser: z.object({\n\t\tid: z.string(),\n\t\taccountId: AccountIdSchema,\n\t\tnetwork: z.union([z.literal(\"mainnet\"), z.literal(\"testnet\")]),\n\t}),\n});\nexport const ProfileResponse = profileSchema.nullable();\nexport const ViewContractResponse = z.object({ result: z.unknown() });\n\nexport const ProfileRequest = z.object({\n\taccountId: AccountIdSchema.optional(),\n});\nexport type ProfileRequestT = z.infer<typeof ProfileRequest>;\n\nexport type NonceRequestT = z.infer<typeof NonceRequest>;\nexport type NonceResponseT = z.infer<typeof NonceResponse>;\nexport type SetPrimaryAccountRequestT = z.infer<typeof SetPrimaryAccountRequest>;\nexport type VerifyRequestT = z.infer<typeof VerifyRequest>;\nexport type VerifyResponseT = z.infer<typeof VerifyResponse>;\nexport type ProfileResponseT = z.infer<typeof ProfileResponse>;\nexport type ViewContractResponseT = z.infer<typeof ViewContractResponse>;\n\nexport const RelayedTransactionSchema = z.object({\n\tid: z.string(),\n\tuserId: z.string(),\n\ttxHash: z.string(),\n\tsenderId: z.string(),\n\treceiverId: z.string(),\n\tnetwork: z.string(),\n\tstatus: z.string(),\n\tgasUsed: z.string().optional(),\n\tcreatedAt: z.string(),\n\tupdatedAt: z.string().optional(),\n});\nexport type RelayedTransactionT = z.infer<typeof RelayedTransactionSchema>;\n\nexport const RelayHistoryResponse = z.object({\n\ttransactions: z.array(RelayedTransactionSchema),\n});\nexport type RelayHistoryResponseT = z.infer<typeof RelayHistoryResponse>;\n\nexport interface RelayedTransactionRecord {\n\tid: string;\n\tuserId: string;\n\ttxHash: string;\n\tsenderId: string;\n\treceiverId: string;\n\tnetwork: \"mainnet\" | \"testnet\";\n\tstatus: string;\n\tgasUsed?: string;\n\tcreatedAt: Date;\n\tupdatedAt: Date;\n}\n\nexport interface RelayerInfo extends AccountState {\n\taccountId: string;\n\tmode: \"ephemeral\" | \"explicit\";\n\tnetwork: \"mainnet\" | \"testnet\";\n\tpublicKey: string;\n\thasKey: boolean;\n\tcreatedAt?: Date;\n\tlastUsedAt?: Date;\n\tparentAccount?: string;\n\tsubAccountAvailable?: boolean;\n}\n\nexport interface DualNetworkConfig<T> {\n\tmainnet: T;\n\ttestnet: T;\n}\n\nexport const GetRelayerInfoRequest = z.object({\n\tnetwork: z.enum([\"mainnet\", \"testnet\"]).optional(),\n});\nexport type GetRelayerInfoRequestT = z.infer<typeof GetRelayerInfoRequest>;\n\nexport interface SubAccountRelayerFCAKConfig {\n\treceiverId: string;\n\tmethodNames?: string[];\n\tallowance?: string;\n}\n\nexport interface SubAccountConfig {\n\tparentAccount?: string;\n\tparentKey?: string;\n\tminDeposit?: string;\n\taddRelayerFCAK?: boolean;\n\trelayerFCAK?: SubAccountRelayerFCAKConfig;\n}\n\nexport const CreateSubAccountRequest = z.object({\n\tsubAccountName: z.string().regex(/^[a-z0-9]+$/, \"Must be lowercase alphanumeric characters only\"),\n\tnetwork: z.enum([\"mainnet\", \"testnet\"]).optional(),\n\tpublicKey: z.string(),\n});\nexport type CreateSubAccountRequestT = z.infer<typeof CreateSubAccountRequest>;\n\nexport const CreateSubAccountResponse = z.object({\n\tsuccess: z.literal(true),\n\taccountId: z.string(),\n\tnetwork: z.enum([\"mainnet\", \"testnet\"]),\n\tpublicKey: z.string(),\n\tmessage: z.string(),\n});\nexport type CreateSubAccountResponseT = z.infer<typeof CreateSubAccountResponse>;\n\nexport const CheckSubAccountAvailabilityRequest = z.object({\n\tsubAccountName: z.string().regex(/^[a-z0-9]+$/),\n\tnetwork: z.enum([\"mainnet\", \"testnet\"]).optional(),\n});\nexport type CheckSubAccountAvailabilityRequestT = z.infer<typeof CheckSubAccountAvailabilityRequest>;\n\nexport const CheckSubAccountAvailabilityResponse = z.object({\n\tavailable: z.boolean(),\n\taccountId: z.string(),\n});\nexport type CheckSubAccountAvailabilityResponseT = z.infer<typeof CheckSubAccountAvailabilityResponse>;\n","import { Near, fromNearConnect, generateNonce, TransactionBuilder } from \"near-kit\";\nimport type { Near as NearType, SignedMessage } from \"near-kit\";\nimport type { EventMap } from \"@hot-labs/near-connect\";\nimport { hex } from \"@scure/base\";\nimport type { BetterAuthClientPlugin, BetterAuthClientOptions, BetterFetch, BetterFetchOption, BetterFetchResponse, ClientStore } from \"better-auth/client\";\nimport { atom } from \"nanostores\";\nimport type { siwn } from \"./index.js\";\nimport { type AccountId, type DualNetworkConfig, type NonceRequestT, type NonceResponseT, type ProfileResponseT, type VerifyRequestT, type VerifyResponseT, type RelayResponseT, type RelayStatusResponseT, type NearAccount, type ListAccountsResponseT, type SetPrimaryAccountRequestT, type SetPrimaryAccountResponseT, type ViewContractRequestT, type ViewContractResponseT, type RelayerInfo, type RelayHistoryResponseT, type GetRelayerInfoRequestT, type CreateSubAccountRequestT, type CreateSubAccountResponseT, type CheckSubAccountAvailabilityRequestT, type CheckSubAccountAvailabilityResponseT } from \"./types.js\";\n\nexport interface AuthCallbacks {\n\tonSuccess?: () => void;\n\tonError?: (error: Error & { status?: number; code?: string }) => void;\n}\n\nexport interface SIWNClientConfig {\n\trecipient?: string;\n\trecipients?: DualNetworkConfig<string>;\n\tnetworkId?: \"mainnet\" | \"testnet\";\n\tcspNonce?: string;\n}\n\ninterface SignWithWalletResult {\n\tsignedMessage: SignedMessage;\n\taccountId: string;\n\tpublicKey: string;\n\tnonceHex: string;\n}\n\nexport interface SIWNClientActions {\n\tnear: {\n\t\tnonce: (params: NonceRequestT) => Promise<BetterFetchResponse<NonceResponseT>>;\n\t\tverify: (params: VerifyRequestT) => Promise<BetterFetchResponse<VerifyResponseT>>;\n\t\tgetProfile: (accountId?: AccountId) => Promise<BetterFetchResponse<ProfileResponseT>>;\n\t\tview: (params: ViewContractRequestT) => Promise<BetterFetchResponse<ViewContractResponseT>>;\n\t\tgetAccountId: () => string | null;\n\t\tgetState: () => { accountId: string | null; publicKey: string | null; networkId: string } | null;\n\t\tisWalletConnected: () => boolean;\n\t\tensureConnected: () => Promise<boolean>;\n\t\tdisconnect: () => Promise<void>;\n\t\tlink: (callbacks?: AuthCallbacks) => Promise<void>;\n\t\tunlink: (params: { accountId: string; network?: \"mainnet\" | \"testnet\" }) => Promise<BetterFetchResponse<{ success: boolean; message: string }>>;\n\t\tlistAccounts: () => Promise<BetterFetchResponse<ListAccountsResponseT>>;\n\t\tsetPrimaryAccount: (params: SetPrimaryAccountRequestT) => Promise<BetterFetchResponse<SetPrimaryAccountResponseT>>;\n\t\tbuildSignedDelegateAction: (receiverId: string, buildActions: (builder: TransactionBuilder, receiverId: string) => TransactionBuilder) => Promise<string>;\n\t\trelayTransaction: (params: { payload: string }) => Promise<BetterFetchResponse<RelayResponseT>>;\n\t\tgetRelayStatus: (txHash: string) => Promise<BetterFetchResponse<RelayStatusResponseT>>;\n\t\tgetRelayerInfo: (params?: GetRelayerInfoRequestT) => Promise<BetterFetchResponse<RelayerInfo & { enabled: boolean }>>;\n\t\trelayHistory: () => Promise<BetterFetchResponse<RelayHistoryResponseT>>;\n\t\tcreateSubAccount: (params: CreateSubAccountRequestT) => Promise<BetterFetchResponse<CreateSubAccountResponseT>>;\n\t\tcheckSubAccountAvailability: (params: CheckSubAccountAvailabilityRequestT) => Promise<BetterFetchResponse<CheckSubAccountAvailabilityResponseT>>;\n\t\tsetNetwork: (network: \"mainnet\" | \"testnet\") => void;\n\t\tgetNetwork: () => \"mainnet\" | \"testnet\";\n\t\tgetSupportedNetworks: () => (\"mainnet\" | \"testnet\")[];\n\t\tgetRecipient: (network?: \"mainnet\" | \"testnet\") => string;\n\t\tclient: NearType;\n\t};\n\tsignIn: {\n\t\tnear: (callbacks?: AuthCallbacks) => Promise<void>;\n\t};\n}\n\nexport interface SIWNClientPlugin extends BetterAuthClientPlugin {\n\tid: \"siwn\";\n\t$InferServerPlugin: ReturnType<typeof siwn>;\n\tgetAtoms: ($fetch: BetterFetch) => {\n\t\tnearState: ReturnType<typeof atom<NearState>>;\n\t\twalletConnected: ReturnType<typeof atom<boolean>>;\n\t\tactiveNetwork: ReturnType<typeof atom<\"mainnet\" | \"testnet\">>;\n\t};\n\tgetActions: ($fetch: BetterFetch, $store: ClientStore, options: BetterAuthClientOptions | undefined) => SIWNClientActions;\n}\n\ntype NearState = { accountId: string | null; publicKey: string | null; networkId: string } | null;\n\nexport const siwnClient = (config: SIWNClientConfig): SIWNClientPlugin => {\n\tconst nearState = atom<NearState>(null);\n\tconst walletConnected = atom<boolean>(false);\n\tconst activeNetwork = atom<\"mainnet\" | \"testnet\">(config.networkId || \"mainnet\");\n\n\tconst getRecipient = (network?: \"mainnet\" | \"testnet\"): string => {\n\t\tconst net = network || activeNetwork.get();\n\t\tif (config.recipients) return config.recipients[net];\n\t\treturn config.recipient ?? \"\";\n\t};\n\n\tconst getSupportedNetworks = (): (\"mainnet\" | \"testnet\")[] => {\n\t\tif (config.recipients) return [\"mainnet\", \"testnet\"];\n\t\tif (config.recipient) return [config.recipient.endsWith(\".testnet\") ? \"testnet\" : \"mainnet\"];\n\t\treturn [\"mainnet\"];\n\t};\n\n\tlet connectors = new Map<\"mainnet\" | \"testnet\", InstanceType<typeof import(\"@hot-labs/near-connect\").NearConnector>>();\n\tlet nearClients = new Map<\"mainnet\" | \"testnet\", Near>();\n\tlet initializedNetworks = new Set<\"mainnet\" | \"testnet\">();\n\tlet connectorModulePromise: Promise<typeof import(\"@hot-labs/near-connect\")> | null = null;\n\tlet initPromises = new Map<\"mainnet\" | \"testnet\", Promise<boolean>>();\n\n\tconst loadConnector = async () => {\n\t\tconnectorModulePromise ??= import(\"@hot-labs/near-connect\");\n\t\tconst { NearConnector } = await connectorModulePromise;\n\t\treturn NearConnector;\n\t};\n\n\tconst handleAccountConnection = async (accountId: string, publicKey?: string | null, network?: \"mainnet\" | \"testnet\") => {\n\t\tif (!accountId) return;\n\t\tconst net = network || activeNetwork.get();\n\t\tnearState.set({\n\t\t\taccountId,\n\t\t\tpublicKey: publicKey || null,\n\t\t\tnetworkId: net,\n\t\t});\n\t\twalletConnected.set(true);\n\t};\n\n\tconst initClientForNetwork = async (network: \"mainnet\" | \"testnet\", $fetch?: BetterFetch): Promise<boolean> => {\n\t\tif (initializedNetworks.has(network)) return true;\n\t\tif (initPromises.has(network)) return initPromises.get(network)!;\n\t\tif (typeof (globalThis as any).window === \"undefined\") return false;\n\n\t\tconst initPromise = (async () => {\n\t\t\tconst NearConnector = await loadConnector();\n\t\t\tconst connector = new NearConnector({ network, cspNonce: config.cspNonce });\n\t\t\tconnectors.set(network, connector);\n\n\t\t\tconst near = new Near({\n\t\t\t\tnetwork,\n\t\t\t\twallet: fromNearConnect(connector),\n\t\t\t});\n\t\t\tnearClients.set(network, near);\n\n\t\t\tconnector.on(\"wallet:signIn\", async (data: EventMap[\"wallet:signIn\"]) => {\n\t\t\t\tconst accountId = data.accounts?.[0]?.accountId;\n\t\t\t\tconst publicKey = data.accounts?.[0]?.publicKey;\n\t\t\t\tif (accountId) {\n\t\t\t\t\tawait handleAccountConnection(accountId, publicKey, network);\n\t\t\t\t}\n\t\t\t});\n\n\t\t\tconnector.on(\"wallet:signOut\", () => {\n\t\t\t\twalletConnected.set(false);\n\t\t\t\tconst state = nearState.get();\n\t\t\t\tif (state) {\n\t\t\t\t\tnearState.set({ accountId: state.accountId, publicKey: null, networkId: state.networkId });\n\t\t\t\t}\n\t\t\t});\n\n\t\t\tvoid connector.getConnectedWallet().then(({ accounts }) => {\n\t\t\t\tconst account = accounts?.[0];\n\t\t\t\tconst net = activeNetwork.get();\n\t\t\t\tif (account?.accountId && !nearState.get()) {\n\t\t\t\t\tnearState.set({\n\t\t\t\t\t\taccountId: account.accountId,\n\t\t\t\t\t\tpublicKey: account.publicKey ?? null,\n\t\t\t\t\t\tnetworkId: net,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tif (account?.accountId) {\n\t\t\t\t\twalletConnected.set(true);\n\t\t\t\t}\n\t\t\t}).catch(() => {});\n\n\t\t\tinitializedNetworks.add(network);\n\n\t\t\tif ($fetch) {\n\t\t\t\tvoid restoreFromSession($fetch);\n\t\t\t}\n\n\t\t\treturn true;\n\t\t})();\n\n\t\tinitPromises.set(network, initPromise);\n\n\t\ttry {\n\t\t\treturn await initPromise;\n\t\t} finally {\n\t\t\tinitPromises.delete(network);\n\t\t}\n\t};\n\n\tconst initClient = async ($fetch?: BetterFetch): Promise<boolean> => {\n\t\tconst network = activeNetwork.get();\n\t\treturn initClientForNetwork(network, $fetch);\n\t};\n\n\tlet sessionRestored = false;\n\n\tconst restoreFromSession = async ($fetch: BetterFetch) => {\n\t\tif (sessionRestored) return;\n\t\tconst state = nearState.get();\n\t\tif (state?.accountId) {\n\t\t\tsessionRestored = true;\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tconst res = await $fetch<ListAccountsResponseT>(\"/near/list-accounts\", { method: \"GET\" });\n\t\t\tconst accounts = res.data?.accounts;\n\t\t\tif (accounts?.length) {\n\t\t\t\tconst primary = res.data?.activeAccount || accounts.find((a: NearAccount) => a.isPrimary) || accounts[0];\n\t\t\t\tif (primary) {\n\t\t\t\t\tnearState.set({\n\t\t\t\t\t\taccountId: primary.accountId,\n\t\t\t\t\t\tpublicKey: primary.publicKey ?? null,\n\t\t\t\t\t\tnetworkId: primary.network,\n\t\t\t\t\t});\n\t\t\t\t\tactiveNetwork.set(primary.network);\n\t\t\t\t}\n\t\t\t}\n\t\t} catch {}\n\t\tsessionRestored = true;\n\t};\n\n\tconst requireConnector = async (network?: \"mainnet\" | \"testnet\") => {\n\t\tconst net = network || activeNetwork.get();\n\t\tawait initClientForNetwork(net);\n\t\tconst connector = connectors.get(net);\n\t\tif (!connector) throw new Error(`Wallet not initialized for ${net} — this operation requires a browser environment`);\n\t\treturn connector;\n\t};\n\n\tconst requireNear = (network?: \"mainnet\" | \"testnet\"): Near => {\n\t\tconst net = network || activeNetwork.get();\n\t\tconst client = nearClients.get(net);\n\t\tif (!client) throw new Error(`Wallet not initialized for ${net} — this operation requires a browser environment`);\n\t\treturn client;\n\t};\n\n\tconst ensureWalletConnected = async (network?: \"mainnet\" | \"testnet\"): Promise<boolean> => {\n\t\tconst net = network || activeNetwork.get();\n\t\tconst conn = await requireConnector(net);\n\t\tif (walletConnected.get()) {\n\t\t\ttry {\n\t\t\t\tconst { accounts } = await conn.getConnectedWallet();\n\t\t\t\tif (accounts?.length) return true;\n\t\t\t} catch {}\n\t\t}\n\n\t\treturn new Promise<boolean>((resolve) => {\n\t\t\tconst signInHandler = (data: EventMap[\"wallet:signIn\"]) => {\n\t\t\t\tconst accountId = data.accounts?.[0]?.accountId;\n\t\t\t\tconst publicKey = data.accounts?.[0]?.publicKey;\n\t\t\t\tif (accountId) {\n\t\t\t\t\thandleAccountConnection(accountId, publicKey, net);\n\t\t\t\t\tresolve(true);\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tconn.on(\"wallet:signIn\", signInHandler);\n\n\t\t\tconn.connect().catch(() => {}).finally(() => {\n\t\t\t\tconn.off(\"wallet:signIn\", signInHandler);\n\t\t\t\tif (!walletConnected.get()) {\n\t\t\t\t\tresolve(false);\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\t};\n\n\tconst signWithWallet = async (): Promise<SignWithWalletResult> => {\n\t\tconst net = activeNetwork.get();\n\t\tconst conn = await requireConnector(net);\n\t\tconst nearClient = requireNear(net);\n\t\tconst recipient = getRecipient(net);\n\n\t\tconst nonceBytes = generateNonce();\n\t\tconst nonceHex = hex.encode(nonceBytes);\n\t\tconst message = `Sign in to ${recipient}`;\n\n\t\tlet connectedWallet: Awaited<ReturnType<typeof conn.getConnectedWallet>> | null = null;\n\t\ttry {\n\t\t\tconnectedWallet = await conn.getConnectedWallet();\n\t\t} catch {}\n\n\t\tif (connectedWallet?.accounts?.length) {\n\t\t\tconst accountId: string = connectedWallet.accounts[0]!.accountId;\n\t\t\tconst isTestnetAccount = accountId.endsWith(\".testnet\");\n\t\t\tconst isExpectedNetwork = (net === \"testnet\") === isTestnetAccount;\n\t\t\tif (!isExpectedNetwork) {\n\t\t\t\tconnectedWallet = null;\n\t\t\t}\n\t\t}\n\n\t\tif (connectedWallet?.accounts?.length) {\n\t\t\tconst signedMessage = await nearClient.signMessage({\n\t\t\t\tmessage,\n\t\t\t\trecipient,\n\t\t\t\tnonce: nonceBytes,\n\t\t\t});\n\n\t\t\tif (!signedMessage?.accountId) {\n\t\t\t\tthrow new Error(\"Wallet sign-in was cancelled or failed\");\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tsignedMessage,\n\t\t\t\taccountId: signedMessage.accountId,\n\t\t\t\tpublicKey: signedMessage.publicKey,\n\t\t\t\tnonceHex,\n\t\t\t};\n\t\t}\n\n\t\tconst result: { value: { signedMessage: SignedMessage; accountId: string; publicKey: string } | null } = { value: null };\n\t\tconst handler = (data: EventMap[\"wallet:signInAndSignMessage\"]) => {\n\t\t\tconst account = data.accounts?.[0];\n\t\t\tif (account?.signedMessage) {\n\t\t\t\tresult.value = {\n\t\t\t\t\tsignedMessage: account.signedMessage,\n\t\t\t\t\taccountId: account.accountId,\n\t\t\t\t\tpublicKey: account.signedMessage.publicKey,\n\t\t\t\t};\n\t\t\t}\n\t\t};\n\n\t\tconn.on(\"wallet:signInAndSignMessage\", handler);\n\n\t\ttry {\n\t\t\tawait conn.connect({\n\t\t\t\tsignMessageParams: {\n\t\t\t\t\tmessage,\n\t\t\t\t\trecipient,\n\t\t\t\t\tnonce: nonceBytes,\n\t\t\t\t},\n\t\t\t});\n\t\t} finally {\n\t\t\tconn.off(\"wallet:signInAndSignMessage\", handler);\n\t\t}\n\n\t\tif (!result.value) {\n\t\t\tthrow new Error(\"Wallet sign-in was cancelled or failed\");\n\t\t}\n\n\t\treturn {\n\t\t\tsignedMessage: result.value.signedMessage,\n\t\t\taccountId: result.value.accountId,\n\t\t\tpublicKey: result.value.publicKey,\n\t\t\tnonceHex,\n\t\t};\n\t};\n\n\tconst buildSignedDelegateActionInternal = async (\n\t\treceiverId: string,\n\t\tbuildActions: (builder: TransactionBuilder, receiverId: string) => TransactionBuilder,\n\t): Promise<string> => {\n\t\tconst net = activeNetwork.get();\n\t\tconst state = nearState.get();\n\t\tif (!state?.accountId) {\n\t\t\tthrow new Error(\"No NEAR account found — please sign in with your NEAR wallet\");\n\t\t}\n\n\t\tif (!walletConnected.get()) {\n\t\t\tconst reconnected = await ensureWalletConnected(net);\n\t\t\tif (!reconnected) {\n\t\t\t\tthrow new Error(\"Wallet connection required — please approve the connection to sign\");\n\t\t\t}\n\t\t}\n\n\t\tconst nearClient = requireNear(net);\n\t\tconst builder = buildActions(nearClient.transaction(state.accountId), receiverId);\n\n\t\tconst { payload } = await builder.delegate();\n\t\treturn payload;\n\t};\n\n\tconst plugin: SIWNClientPlugin = {\n\t\tid: \"siwn\",\n\t\t$InferServerPlugin: {} as ReturnType<typeof siwn>,\n\n\t\tgetAtoms: (_$fetch) => ({\n\t\t\tnearState,\n\t\t\twalletConnected,\n\t\t\tactiveNetwork,\n\t\t}),\n\n\t\tgetActions: ($fetch: BetterFetch, _$store: ClientStore, _options: BetterAuthClientOptions | undefined): SIWNClientActions => {\n\t\t\tvoid initClient($fetch);\n\n\t\t\treturn {\n\t\t\t\tnear: {\n\t\t\t\t\tnonce: async (params: NonceRequestT, fetchOptions?: BetterFetchOption) => {\n\t\t\t\t\t\treturn await $fetch(\"/near/nonce\", {\n\t\t\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\t\t\tbody: params,\n\t\t\t\t\t\t\t...fetchOptions\n\t\t\t\t\t\t});\n\t\t\t\t\t},\n\t\t\t\t\tverify: async (params: VerifyRequestT, fetchOptions?: BetterFetchOption) => {\n\t\t\t\t\t\treturn await $fetch(\"/near/verify\", {\n\t\t\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\t\t\tbody: params,\n\t\t\t\t\t\t\t...fetchOptions\n\t\t\t\t\t\t});\n\t\t\t\t\t},\n\t\t\t\t\tgetProfile: async (accountId?: AccountId, fetchOptions?: BetterFetchOption) => {\n\t\t\t\t\t\treturn await $fetch(\"/near/profile\", {\n\t\t\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\t\t\tbody: { accountId },\n\t\t\t\t\t\t\t...fetchOptions\n\t\t\t\t\t\t});\n\t\t\t\t\t},\n\t\t\t\t\tview: async (params: ViewContractRequestT, fetchOptions?: BetterFetchOption) => {\n\t\t\t\t\t\treturn await $fetch(\"/near/view\", {\n\t\t\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\t\t\tbody: params,\n\t\t\t\t\t\t\t...fetchOptions\n\t\t\t\t\t\t});\n\t\t\t\t\t},\n\t\t\t\t\tgetAccountId: () => {\n\t\t\t\t\t\tconst state = nearState.get();\n\t\t\t\t\t\treturn state?.accountId || null;\n\t\t\t\t\t},\n\t\t\t\t\tgetState: () => nearState.get(),\n\t\t\t\t\tisWalletConnected: () => walletConnected.get(),\n\t\t\t\t\tensureConnected: async () => {\n\t\t\t\t\t\tconst net = activeNetwork.get();\n\t\t\t\t\t\tif (!initializedNetworks.has(net)) {\n\t\t\t\t\t\t\tif (!(await initClientForNetwork(net))) return false;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (walletConnected.get()) {\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tconst conn = connectors.get(net);\n\t\t\t\t\t\t\t\tif (conn) {\n\t\t\t\t\t\t\t\t\tconst { accounts } = await conn.getConnectedWallet();\n\t\t\t\t\t\t\t\t\tif (accounts?.length) return true;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} catch (err) {\n\t\t\t\t\t\t\t\tconsole.error(\"[siwn] restoreFromSession failed:\", err instanceof Error ? err.message : err);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn ensureWalletConnected(net);\n\t\t\t\t\t},\n\t\t\t\t\tdisconnect: async () => {\n\t\t\t\t\t\tfor (const [_net, conn] of connectors) {\n\t\t\t\t\t\t\tif (conn) {\n\t\t\t\t\t\t\t\ttry { await conn.disconnect(); } catch {}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\twalletConnected.set(false);\n\t\t\t\t\t\tnearState.set(null);\n\t\t\t\t\t},\n\t\t\t\t\tlink: async (callbacks?: AuthCallbacks) => {\n\t\t\t\t\t\tconst net = activeNetwork.get();\n\t\t\t\t\t\tconst recipient = getRecipient(net);\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tconst { signedMessage, accountId, nonceHex } = await signWithWallet();\n\t\t\t\t\t\t\tconst message = `Sign in to ${recipient}`;\n\n\t\t\t\t\t\t\tawait handleAccountConnection(accountId, signedMessage.publicKey, net);\n\n\t\t\t\t\t\t\tconst linkResponse = await $fetch<{ success: boolean; accountId: string; network: string; message: string }>(\"/near/link-account\", {\n\t\t\t\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\t\tsignedMessage,\n\t\t\t\t\t\t\t\t\tmessage,\n\t\t\t\t\t\t\t\t\trecipient,\n\t\t\t\t\t\t\t\t\tnonce: nonceHex,\n\t\t\t\t\t\t\t\t\taccountId,\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\tif (linkResponse.error) {\n\t\t\t\t\t\t\t\tthrow new Error(linkResponse.error.message || \"Failed to link NEAR account\");\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tif (!linkResponse?.data?.success) {\n\t\t\t\t\t\t\t\tthrow new Error(\"Account linking failed\");\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tcallbacks?.onSuccess?.();\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\tconst err = error instanceof Error ? error : new Error(String(error));\n\t\t\t\t\t\t\tcallbacks?.onError?.(err);\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t\tunlink: async (\n\t\t\t\t\t\tparams: { accountId: string; network?: \"mainnet\" | \"testnet\" },\n\t\t\t\t\t\tfetchOptions?: BetterFetchOption\n\t\t\t\t\t) => {\n\t\t\t\t\t\treturn await $fetch(\"/near/unlink-account\", {\n\t\t\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\t\t\tbody: params,\n\t\t\t\t\t\t\t...fetchOptions\n\t\t\t\t\t\t});\n\t\t\t\t\t},\n\t\t\t\t\tlistAccounts: async (): Promise<BetterFetchResponse<ListAccountsResponseT>> => {\n\t\t\t\t\t\treturn await $fetch(\"/near/list-accounts\", { method: \"GET\" });\n\t\t\t\t\t},\n\t\t\t\t\tsetPrimaryAccount: async (params: SetPrimaryAccountRequestT) => {\n\t\t\t\t\t\tconst response = await $fetch<SetPrimaryAccountResponseT>(\"/near/set-primary-account\", {\n\t\t\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\t\t\tbody: params,\n\t\t\t\t\t\t});\n\t\t\t\t\t\tconst activeAccount = response.data?.activeAccount;\n\t\t\t\t\t\tif (activeAccount) {\n\t\t\t\t\t\t\tnearState.set({\n\t\t\t\t\t\t\t\taccountId: activeAccount.accountId,\n\t\t\t\t\t\t\t\tpublicKey: activeAccount.publicKey ?? null,\n\t\t\t\t\t\t\t\tnetworkId: activeAccount.network,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\tactiveNetwork.set(activeAccount.network);\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn response;\n\t\t\t\t\t},\n\t\t\t\t\tbuildSignedDelegateAction: async (\n\t\t\t\t\t\treceiverId: string,\n\t\t\t\t\t\tbuildActions: (builder: TransactionBuilder, receiverId: string) => TransactionBuilder,\n\t\t\t\t\t): Promise<string> => {\n\t\t\t\t\t\treturn buildSignedDelegateActionInternal(receiverId, buildActions);\n\t\t\t\t\t},\n\t\t\t\t\trelayTransaction: async (params: { payload: string }) => {\n\t\t\t\t\t\treturn await $fetch(\"/near/relay\", {\n\t\t\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\t\t\tbody: params,\n\t\t\t\t\t\t});\n\t\t\t\t\t},\n\t\t\t\t\tgetRelayStatus: async (txHash: string) => {\n\t\t\t\t\t\treturn await $fetch(`/near/relay-status/${txHash}`, {\n\t\t\t\t\t\t\tmethod: \"GET\",\n\t\t\t\t\t\t});\n\t\t\t\t\t},\n\t\t\t\t\tgetRelayerInfo: async (params?: GetRelayerInfoRequestT) => {\n\t\t\t\t\t\treturn await $fetch(\"/near/relayer-info\", {\n\t\t\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\t\t\tbody: params ?? {},\n\t\t\t\t\t\t});\n\t\t\t\t\t},\n\t\t\t\t\trelayHistory: async () => {\n\t\t\t\t\t\treturn await $fetch(\"/near/relay-history\", {\n\t\t\t\t\t\t\tmethod: \"GET\",\n\t\t\t\t\t\t});\n\t\t\t\t\t},\n\t\t\t\t\tcreateSubAccount: async (params: CreateSubAccountRequestT) => {\n\t\t\t\t\t\treturn await $fetch(\"/near/create-sub-account\", {\n\t\t\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\t\t\tbody: params,\n\t\t\t\t\t\t});\n\t\t\t\t\t},\n\t\t\t\t\tcheckSubAccountAvailability: async (params: CheckSubAccountAvailabilityRequestT) => {\n\t\t\t\t\t\treturn await $fetch(\"/near/check-sub-account-availability\", {\n\t\t\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\t\t\tbody: params,\n\t\t\t\t\t\t});\n\t\t\t\t\t},\n\t\t\t\t\tsetNetwork: (network: \"mainnet\" | \"testnet\") => {\n\t\t\t\t\t\tconst prev = activeNetwork.get();\n\t\t\t\t\t\tif (prev !== network) {\n\t\t\t\t\t\t\tconst oldConn = connectors.get(prev);\n\t\t\t\t\t\t\tif (oldConn) {\n\t\t\t\t\t\t\t\tvoid oldConn.disconnect().catch(() => {});\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\twalletConnected.set(false);\n\t\t\t\t\t\t\tnearState.set(null);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tactiveNetwork.set(network);\n\t\t\t\t\t\tvoid initClientForNetwork(network);\n\t\t\t\t\t},\n\t\t\t\t\tgetNetwork: () => activeNetwork.get(),\n\t\t\t\t\tgetSupportedNetworks: () => getSupportedNetworks(),\n\t\t\t\t\tgetRecipient: (network?: \"mainnet\" | \"testnet\") => getRecipient(network),\n\t\t\t\t\tget client(): NearType {\n\t\t\t\t\t\tconst net = activeNetwork.get();\n\t\t\t\t\t\tconst client = nearClients.get(net);\n\t\t\t\t\t\tif (!client) throw new Error(`Wallet not initialized for ${net} — this operation requires a browser environment`);\n\t\t\t\t\t\treturn client;\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tsignIn: {\n\t\t\t\t\tnear: async (callbacks?: AuthCallbacks) => {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tconst { signedMessage, accountId, nonceHex } = await signWithWallet();\n\t\t\t\t\t\t\tconst net = activeNetwork.get();\n\t\t\t\t\t\t\tconst recipient = getRecipient(net);\n\t\t\t\t\t\t\tconst message = `Sign in to ${recipient}`;\n\n\t\t\t\t\t\t\tawait handleAccountConnection(accountId, signedMessage.publicKey, net);\n\n\t\t\t\t\t\t\tconst verifyResponse: BetterFetchResponse<VerifyResponseT> = await $fetch(\"/near/verify\", {\n\t\t\t\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\t\tsignedMessage,\n\t\t\t\t\t\t\t\t\tmessage,\n\t\t\t\t\t\t\t\t\trecipient,\n\t\t\t\t\t\t\t\t\tnonce: nonceHex,\n\t\t\t\t\t\t\t\t\taccountId,\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\tif (verifyResponse.error) {\n\t\t\t\t\t\t\t\tthrow new Error(verifyResponse.error.message || \"Failed to verify signature\");\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tif (!verifyResponse?.data?.success) {\n\t\t\t\t\t\t\t\tthrow new Error(\"Authentication verification failed\");\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tcallbacks?.onSuccess?.();\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\tconst err = error instanceof Error ? error : new Error(String(error));\n\t\t\t\t\t\t\tcallbacks?.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KAC1C,IAAI;MACH,MAAM,EAAE,eAAe,WAAW,aAAa,MAAM,eAAe;MACpE,MAAM,MAAM,cAAc,IAAI;MAC9B,MAAM,YAAY,aAAa,GAAG;MAClC,MAAM,UAAU,cAAc;MAE9B,MAAM,wBAAwB,WAAW,cAAc,WAAW,GAAG;MAErE,MAAM,iBAAuD,MAAM,OAAO,gBAAgB;OACzF,QAAQ;OACR,MAAM;QACL;QACA;QACA;QACA,OAAO;QACP;OACD;MACD,CAAC;MAED,IAAI,eAAe,OAClB,MAAM,IAAI,MAAM,eAAe,MAAM,WAAW,4BAA4B;MAG7E,IAAI,CAAC,gBAAgB,MAAM,SAC1B,MAAM,IAAI,MAAM,oCAAoC;MAGrD,WAAW,YAAY;KACxB,SAAS,OAAO;MACf,MAAM,MAAM,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,KAAK,CAAC;MACpE,WAAW,UAAU,GAAG;KACzB;IACD,EACD;GACD;EACD;CAGW;AACb"}
1
+ {"version":3,"file":"client.js","names":[],"sources":["../src/types.ts","../src/client.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { AccountIdSchema, type AccountId } from \"near-kit/schemas\";\nimport type { AccountState } from \"near-kit\";\n\nexport type { AccountId };\n\nexport interface NearAccount {\n\tid: string;\n\tuserId: string;\n\taccountId: string;\n\tnetwork: \"mainnet\" | \"testnet\";\n\tpublicKey: string;\n\tisPrimary: boolean;\n\tcreatedAt: Date;\n}\n\nexport interface ListedNearAccount extends NearAccount {\n\tproviderId: \"siwn\";\n\tisActive: boolean;\n\tisAvailable: boolean;\n}\n\nexport interface ListAccountsResponseT {\n\taccounts: ListedNearAccount[];\n\tactiveAccount: ListedNearAccount | null;\n\tavailableAccounts: ListedNearAccount[];\n}\n\nexport interface SetPrimaryAccountResponseT extends ListAccountsResponseT {\n\tsuccess: boolean;\n\taccountId: string;\n\tnetwork: \"mainnet\" | \"testnet\";\n\tmessage: string;\n}\n\nexport const socialImageSchema = z.object({\n\turl: z.string().optional(),\n\tipfs_cid: z.string().optional(),\n});\n\nexport const profileSchema = z.object({\n\tname: z.string().optional(),\n\tdescription: z.string().optional(),\n\timage: socialImageSchema.optional(),\n\tbackgroundImage: socialImageSchema.optional(),\n\tlinktree: z.record(z.string(), z.string()).optional(),\n});\n\nexport type SocialImage = z.infer<typeof socialImageSchema>;\nexport type Profile = z.infer<typeof profileSchema>;\n\nconst signedMessageSchema = z.object({\n\taccountId: z.string(),\n\tpublicKey: z.string(),\n\tsignature: z.string(),\n\tstate: z.string().optional(),\n});\n\nexport const LinkAccountRequest = z.object({\n\tsignedMessage: signedMessageSchema,\n\tmessage: z.string(),\n\trecipient: z.string(),\n\tnonce: z.string(),\n\taccountId: AccountIdSchema,\n\tcallbackUrl: z.string().optional(),\n});\n\nexport const SetPrimaryAccountRequest = z.object({\n\taccountId: AccountIdSchema,\n\tnetwork: z.enum([\"mainnet\", \"testnet\"]).optional(),\n});\n\nexport const NonceRequest = z.object({\n\taccountId: AccountIdSchema,\n\tnetworkId: z.union([z.literal(\"mainnet\"), z.literal(\"testnet\")])\n});\n\nexport const VerifyRequest = z.object({\n\tsignedMessage: signedMessageSchema,\n\tmessage: z.string(),\n\trecipient: z.string(),\n\tnonce: z.string(),\n\taccountId: AccountIdSchema,\n\tcallbackUrl: z.string().optional(),\n});\n\nexport const RelayRequest = z.object({\n\tpayload: z.string(),\n});\nexport type RelayRequestT = z.infer<typeof RelayRequest>;\n\nexport const RelayResponse = z.object({\n\ttxHash: z.string(),\n\tstatus: z.enum([\"pending\", \"completed\", \"failed\"]),\n});\nexport type RelayResponseT = z.infer<typeof RelayResponse>;\n\nexport const RelayStatusResponse = z.object({\n\tstatus: z.enum([\"pending\", \"completed\", \"failed\"]),\n\tgasUsed: z.string().optional(),\n\toutcome: z.unknown().optional(),\n});\nexport type RelayStatusResponseT = z.infer<typeof RelayStatusResponse>;\n\nexport const ViewContractRequest = z.object({\n\tcontractId: z.string(),\n\tmethodName: z.string(),\n\targs: z.record(z.string(), z.any()).optional(),\n});\nexport type ViewContractRequestT = z.infer<typeof ViewContractRequest>;\n\nexport const NonceResponse = z.object({ nonce: z.string() });\nexport const VerifyResponse = z.object({\n\ttoken: z.string(),\n\tsuccess: z.literal(true),\n\tuser: z.object({\n\t\tid: z.string(),\n\t\taccountId: AccountIdSchema,\n\t\tnetwork: z.union([z.literal(\"mainnet\"), z.literal(\"testnet\")]),\n\t}),\n});\nexport const ProfileResponse = profileSchema.nullable();\nexport const ViewContractResponse = z.object({ result: z.unknown() });\n\nexport const ProfileRequest = z.object({\n\taccountId: AccountIdSchema.optional(),\n});\nexport type ProfileRequestT = z.infer<typeof ProfileRequest>;\n\nexport type NonceRequestT = z.infer<typeof NonceRequest>;\nexport type NonceResponseT = z.infer<typeof NonceResponse>;\nexport type SetPrimaryAccountRequestT = z.infer<typeof SetPrimaryAccountRequest>;\nexport type VerifyRequestT = z.infer<typeof VerifyRequest>;\nexport type VerifyResponseT = z.infer<typeof VerifyResponse>;\nexport type ProfileResponseT = z.infer<typeof ProfileResponse>;\nexport type ViewContractResponseT = z.infer<typeof ViewContractResponse>;\n\nexport const RelayedTransactionSchema = z.object({\n\tid: z.string(),\n\tuserId: z.string(),\n\ttxHash: z.string(),\n\tsenderId: z.string(),\n\treceiverId: z.string(),\n\tnetwork: z.string(),\n\tstatus: z.string(),\n\tgasUsed: z.string().optional(),\n\tcreatedAt: z.string(),\n\tupdatedAt: z.string().optional(),\n});\nexport type RelayedTransactionT = z.infer<typeof RelayedTransactionSchema>;\n\nexport const RelayHistoryResponse = z.object({\n\ttransactions: z.array(RelayedTransactionSchema),\n});\nexport type RelayHistoryResponseT = z.infer<typeof RelayHistoryResponse>;\n\nexport interface RelayedTransactionRecord {\n\tid: string;\n\tuserId: string;\n\ttxHash: string;\n\tsenderId: string;\n\treceiverId: string;\n\tnetwork: \"mainnet\" | \"testnet\";\n\tstatus: string;\n\tgasUsed?: string;\n\tcreatedAt: Date;\n\tupdatedAt: Date;\n}\n\nexport interface RelayerInfo extends AccountState {\n\taccountId: string;\n\tmode: \"ephemeral\" | \"explicit\";\n\tnetwork: \"mainnet\" | \"testnet\";\n\tpublicKey: string;\n\thasKey: boolean;\n\tcreatedAt?: Date;\n\tlastUsedAt?: Date;\n\tparentAccount?: string;\n\tsubAccountAvailable?: boolean;\n}\n\nexport interface DualNetworkConfig<T> {\n\tmainnet: T;\n\ttestnet: T;\n}\n\nexport const GetRelayerInfoRequest = z.object({\n\tnetwork: z.enum([\"mainnet\", \"testnet\"]).optional(),\n});\nexport type GetRelayerInfoRequestT = z.infer<typeof GetRelayerInfoRequest>;\n\nexport interface SubAccountRelayerFCAKConfig {\n\treceiverId: string;\n\tmethodNames?: string[];\n\tallowance?: string;\n}\n\nexport interface SubAccountConfig {\n\tparentAccount?: string;\n\tparentKey?: string;\n\tminDeposit?: string;\n\taddRelayerFCAK?: boolean;\n\trelayerFCAK?: SubAccountRelayerFCAKConfig;\n}\n\nexport const CreateSubAccountRequest = z.object({\n\tsubAccountName: z.string().regex(/^[a-z0-9]+$/, \"Must be lowercase alphanumeric characters only\"),\n\tnetwork: z.enum([\"mainnet\", \"testnet\"]).optional(),\n\tpublicKey: z.string(),\n});\nexport type CreateSubAccountRequestT = z.infer<typeof CreateSubAccountRequest>;\n\nexport const CreateSubAccountResponse = z.object({\n\tsuccess: z.literal(true),\n\taccountId: z.string(),\n\tnetwork: z.enum([\"mainnet\", \"testnet\"]),\n\tpublicKey: z.string(),\n\tmessage: z.string(),\n});\nexport type CreateSubAccountResponseT = z.infer<typeof CreateSubAccountResponse>;\n\nexport const CheckSubAccountAvailabilityRequest = z.object({\n\tsubAccountName: z.string().regex(/^[a-z0-9]+$/),\n\tnetwork: z.enum([\"mainnet\", \"testnet\"]).optional(),\n});\nexport type CheckSubAccountAvailabilityRequestT = z.infer<typeof CheckSubAccountAvailabilityRequest>;\n\nexport const CheckSubAccountAvailabilityResponse = z.object({\n\tavailable: z.boolean(),\n\taccountId: z.string(),\n});\nexport type CheckSubAccountAvailabilityResponseT = z.infer<typeof CheckSubAccountAvailabilityResponse>;\n","import { Near, fromNearConnect, generateNonce, TransactionBuilder } from \"near-kit\";\nimport type { Near as NearType, SignedMessage } from \"near-kit\";\nimport type { EventMap } from \"@hot-labs/near-connect\";\nimport { hex } from \"@scure/base\";\nimport type { BetterAuthClientPlugin, BetterAuthClientOptions, BetterFetch, BetterFetchOption, BetterFetchResponse, ClientStore } from \"better-auth/client\";\nimport { atom } from \"nanostores\";\nimport type { siwn } from \"./index.js\";\nimport { type AccountId, type DualNetworkConfig, type NonceRequestT, type NonceResponseT, type ProfileResponseT, type VerifyRequestT, type VerifyResponseT, type RelayResponseT, type RelayStatusResponseT, type NearAccount, type ListAccountsResponseT, type SetPrimaryAccountRequestT, type SetPrimaryAccountResponseT, type ViewContractRequestT, type ViewContractResponseT, type RelayerInfo, type RelayHistoryResponseT, type GetRelayerInfoRequestT, type CreateSubAccountRequestT, type CreateSubAccountResponseT, type CheckSubAccountAvailabilityRequestT, type CheckSubAccountAvailabilityResponseT } from \"./types.js\";\n\nexport interface AuthCallbacks {\n\tonSuccess?: () => void;\n\tonError?: (error: Error & { status?: number; code?: string }) => void;\n}\n\nexport interface SIWNClientConfig {\n\trecipient?: string;\n\trecipients?: DualNetworkConfig<string>;\n\tnetworkId?: \"mainnet\" | \"testnet\";\n\tcspNonce?: string;\n}\n\ninterface SignWithWalletResult {\n\tsignedMessage: SignedMessage;\n\taccountId: string;\n\tpublicKey: string;\n\tnonceHex: string;\n}\n\nexport interface SIWNClientActions {\n\tnear: {\n\t\tnonce: (params: NonceRequestT) => Promise<BetterFetchResponse<NonceResponseT>>;\n\t\tverify: (params: VerifyRequestT) => Promise<BetterFetchResponse<VerifyResponseT>>;\n\t\tgetProfile: (accountId?: AccountId) => Promise<BetterFetchResponse<ProfileResponseT>>;\n\t\tview: (params: ViewContractRequestT) => Promise<BetterFetchResponse<ViewContractResponseT>>;\n\t\tgetAccountId: () => string | null;\n\t\tgetState: () => { accountId: string | null; publicKey: string | null; networkId: string } | null;\n\t\tisWalletConnected: () => boolean;\n\t\tensureConnected: () => Promise<boolean>;\n\t\tdisconnect: () => Promise<void>;\n\t\tlink: (callbacks?: AuthCallbacks) => Promise<void>;\n\t\tunlink: (params: { accountId: string; network?: \"mainnet\" | \"testnet\" }) => Promise<BetterFetchResponse<{ success: boolean; message: string }>>;\n\t\tlistAccounts: () => Promise<BetterFetchResponse<ListAccountsResponseT>>;\n\t\tsetPrimaryAccount: (params: SetPrimaryAccountRequestT) => Promise<BetterFetchResponse<SetPrimaryAccountResponseT>>;\n\t\tbuildSignedDelegateAction: (receiverId: string, buildActions: (builder: TransactionBuilder, receiverId: string) => TransactionBuilder) => Promise<string>;\n\t\trelayTransaction: (params: { payload: string }) => Promise<BetterFetchResponse<RelayResponseT>>;\n\t\tgetRelayStatus: (txHash: string) => Promise<BetterFetchResponse<RelayStatusResponseT>>;\n\t\tgetRelayerInfo: (params?: GetRelayerInfoRequestT) => Promise<BetterFetchResponse<RelayerInfo & { enabled: boolean }>>;\n\t\trelayHistory: () => Promise<BetterFetchResponse<RelayHistoryResponseT>>;\n\t\tcreateSubAccount: (params: CreateSubAccountRequestT) => Promise<BetterFetchResponse<CreateSubAccountResponseT>>;\n\t\tcheckSubAccountAvailability: (params: CheckSubAccountAvailabilityRequestT) => Promise<BetterFetchResponse<CheckSubAccountAvailabilityResponseT>>;\n\t\tsetNetwork: (network: \"mainnet\" | \"testnet\") => void;\n\t\tgetNetwork: () => \"mainnet\" | \"testnet\";\n\t\tgetSupportedNetworks: () => (\"mainnet\" | \"testnet\")[];\n\t\tgetRecipient: (network?: \"mainnet\" | \"testnet\") => string;\n\t\tclient: NearType;\n\t};\n\tsignIn: {\n\t\tnear: (callbacks?: AuthCallbacks) => Promise<void>;\n\t};\n}\n\nexport interface SIWNClientPlugin extends BetterAuthClientPlugin {\n\tid: \"siwn\";\n\t$InferServerPlugin: ReturnType<typeof siwn>;\n\tgetAtoms: ($fetch: BetterFetch) => {\n\t\tnearState: ReturnType<typeof atom<NearState>>;\n\t\twalletConnected: ReturnType<typeof atom<boolean>>;\n\t\tactiveNetwork: ReturnType<typeof atom<\"mainnet\" | \"testnet\">>;\n\t};\n\tgetActions: ($fetch: BetterFetch, $store: ClientStore, options: BetterAuthClientOptions | undefined) => SIWNClientActions;\n}\n\ntype NearState = { accountId: string | null; publicKey: string | null; networkId: string } | null;\n\nexport const siwnClient = (config: SIWNClientConfig): SIWNClientPlugin => {\n\tconst nearState = atom<NearState>(null);\n\tconst walletConnected = atom<boolean>(false);\n\tconst activeNetwork = atom<\"mainnet\" | \"testnet\">(config.networkId || \"mainnet\");\n\n\tconst getRecipient = (network?: \"mainnet\" | \"testnet\"): string => {\n\t\tconst net = network || activeNetwork.get();\n\t\tif (config.recipients) return config.recipients[net];\n\t\treturn config.recipient ?? \"\";\n\t};\n\n\tconst getSupportedNetworks = (): (\"mainnet\" | \"testnet\")[] => {\n\t\tif (config.recipients) return [\"mainnet\", \"testnet\"];\n\t\tif (config.recipient) return [config.recipient.endsWith(\".testnet\") ? \"testnet\" : \"mainnet\"];\n\t\treturn [\"mainnet\"];\n\t};\n\n\tlet connectors = new Map<\"mainnet\" | \"testnet\", InstanceType<typeof import(\"@hot-labs/near-connect\").NearConnector>>();\n\tlet nearClients = new Map<\"mainnet\" | \"testnet\", Near>();\n\tlet initializedNetworks = new Set<\"mainnet\" | \"testnet\">();\n\tlet connectorModulePromise: Promise<typeof import(\"@hot-labs/near-connect\")> | null = null;\n\tlet initPromises = new Map<\"mainnet\" | \"testnet\", Promise<boolean>>();\n\n\tconst loadConnector = async () => {\n\t\tconnectorModulePromise ??= import(\"@hot-labs/near-connect\");\n\t\tconst { NearConnector } = await connectorModulePromise;\n\t\treturn NearConnector;\n\t};\n\n\tconst handleAccountConnection = async (accountId: string, publicKey?: string | null, network?: \"mainnet\" | \"testnet\") => {\n\t\tif (!accountId) return;\n\t\tconst net = network || activeNetwork.get();\n\t\tnearState.set({\n\t\t\taccountId,\n\t\t\tpublicKey: publicKey || null,\n\t\t\tnetworkId: net,\n\t\t});\n\t\twalletConnected.set(true);\n\t};\n\n\tconst initClientForNetwork = async (network: \"mainnet\" | \"testnet\", $fetch?: BetterFetch): Promise<boolean> => {\n\t\tif (initializedNetworks.has(network)) return true;\n\t\tif (initPromises.has(network)) return initPromises.get(network)!;\n\t\tif (typeof (globalThis as any).window === \"undefined\") return false;\n\n\t\tconst initPromise = (async () => {\n\t\t\tconst NearConnector = await loadConnector();\n\t\t\tconst connector = new NearConnector({ network, cspNonce: config.cspNonce });\n\t\t\tconnectors.set(network, connector);\n\n\t\t\tconst near = new Near({\n\t\t\t\tnetwork,\n\t\t\t\twallet: fromNearConnect(connector),\n\t\t\t});\n\t\t\tnearClients.set(network, near);\n\n\t\t\tconnector.on(\"wallet:signIn\", async (data: EventMap[\"wallet:signIn\"]) => {\n\t\t\t\tconst accountId = data.accounts?.[0]?.accountId;\n\t\t\t\tconst publicKey = data.accounts?.[0]?.publicKey;\n\t\t\t\tif (accountId) {\n\t\t\t\t\tawait handleAccountConnection(accountId, publicKey, network);\n\t\t\t\t}\n\t\t\t});\n\n\t\t\tconnector.on(\"wallet:signOut\", () => {\n\t\t\t\twalletConnected.set(false);\n\t\t\t\tconst state = nearState.get();\n\t\t\t\tif (state) {\n\t\t\t\t\tnearState.set({ accountId: state.accountId, publicKey: null, networkId: state.networkId });\n\t\t\t\t}\n\t\t\t});\n\n\t\t\tvoid connector.getConnectedWallet().then(({ accounts }) => {\n\t\t\t\tconst account = accounts?.[0];\n\t\t\t\tconst net = activeNetwork.get();\n\t\t\t\tif (account?.accountId && !nearState.get()) {\n\t\t\t\t\tnearState.set({\n\t\t\t\t\t\taccountId: account.accountId,\n\t\t\t\t\t\tpublicKey: account.publicKey ?? null,\n\t\t\t\t\t\tnetworkId: net,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tif (account?.accountId) {\n\t\t\t\t\twalletConnected.set(true);\n\t\t\t\t}\n\t\t\t}).catch(() => {});\n\n\t\t\tinitializedNetworks.add(network);\n\n\t\t\tif ($fetch) {\n\t\t\t\tvoid restoreFromSession($fetch);\n\t\t\t}\n\n\t\t\treturn true;\n\t\t})();\n\n\t\tinitPromises.set(network, initPromise);\n\n\t\ttry {\n\t\t\treturn await initPromise;\n\t\t} finally {\n\t\t\tinitPromises.delete(network);\n\t\t}\n\t};\n\n\tconst initClient = async ($fetch?: BetterFetch): Promise<boolean> => {\n\t\tconst network = activeNetwork.get();\n\t\treturn initClientForNetwork(network, $fetch);\n\t};\n\n\tlet sessionRestored = false;\n\n\tconst restoreFromSession = async ($fetch: BetterFetch) => {\n\t\tif (sessionRestored) return;\n\t\tconst state = nearState.get();\n\t\tif (state?.accountId) {\n\t\t\tsessionRestored = true;\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tconst res = await $fetch<ListAccountsResponseT>(\"/near/list-accounts\", { method: \"GET\" });\n\t\t\tconst accounts = res.data?.accounts;\n\t\t\tif (accounts?.length) {\n\t\t\t\tconst primary = res.data?.activeAccount || accounts.find((a: NearAccount) => a.isPrimary) || accounts[0];\n\t\t\t\tif (primary) {\n\t\t\t\t\tnearState.set({\n\t\t\t\t\t\taccountId: primary.accountId,\n\t\t\t\t\t\tpublicKey: primary.publicKey ?? null,\n\t\t\t\t\t\tnetworkId: primary.network,\n\t\t\t\t\t});\n\t\t\t\t\tactiveNetwork.set(primary.network);\n\t\t\t\t}\n\t\t\t}\n\t\t} catch {}\n\t\tsessionRestored = true;\n\t};\n\n\tconst requireConnector = async (network?: \"mainnet\" | \"testnet\") => {\n\t\tconst net = network || activeNetwork.get();\n\t\tawait initClientForNetwork(net);\n\t\tconst connector = connectors.get(net);\n\t\tif (!connector) throw new Error(`Wallet not initialized for ${net} — this operation requires a browser environment`);\n\t\treturn connector;\n\t};\n\n\tconst requireNear = (network?: \"mainnet\" | \"testnet\"): Near => {\n\t\tconst net = network || activeNetwork.get();\n\t\tconst client = nearClients.get(net);\n\t\tif (!client) throw new Error(`Wallet not initialized for ${net} — this operation requires a browser environment`);\n\t\treturn client;\n\t};\n\n\tconst ensureWalletConnected = async (network?: \"mainnet\" | \"testnet\"): Promise<boolean> => {\n\t\tconst net = network || activeNetwork.get();\n\t\tconst conn = await requireConnector(net);\n\t\tif (walletConnected.get()) {\n\t\t\ttry {\n\t\t\t\tconst { accounts } = await conn.getConnectedWallet();\n\t\t\t\tif (accounts?.length) return true;\n\t\t\t} catch {}\n\t\t}\n\n\t\treturn new Promise<boolean>((resolve) => {\n\t\t\tconst signInHandler = (data: EventMap[\"wallet:signIn\"]) => {\n\t\t\t\tconst accountId = data.accounts?.[0]?.accountId;\n\t\t\t\tconst publicKey = data.accounts?.[0]?.publicKey;\n\t\t\t\tif (accountId) {\n\t\t\t\t\thandleAccountConnection(accountId, publicKey, net);\n\t\t\t\t\tresolve(true);\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tconn.on(\"wallet:signIn\", signInHandler);\n\n\t\t\tconn.connect().catch(() => {}).finally(() => {\n\t\t\t\tconn.off(\"wallet:signIn\", signInHandler);\n\t\t\t\tif (!walletConnected.get()) {\n\t\t\t\t\tresolve(false);\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\t};\n\n\tconst signWithWallet = async (): Promise<SignWithWalletResult> => {\n\t\tconst net = activeNetwork.get();\n\t\tconst conn = await requireConnector(net);\n\t\tconst nearClient = requireNear(net);\n\t\tconst recipient = getRecipient(net);\n\n\t\tconst nonceBytes = generateNonce();\n\t\tconst nonceHex = hex.encode(nonceBytes);\n\t\tconst message = `Sign in to ${recipient}`;\n\n\t\tlet connectedWallet: Awaited<ReturnType<typeof conn.getConnectedWallet>> | null = null;\n\t\ttry {\n\t\t\tconnectedWallet = await conn.getConnectedWallet();\n\t\t} catch {}\n\n\t\tif (connectedWallet?.accounts?.length) {\n\t\t\tconst accountId: string = connectedWallet.accounts[0]!.accountId;\n\t\t\tconst isTestnetAccount = accountId.endsWith(\".testnet\");\n\t\t\tconst isExpectedNetwork = (net === \"testnet\") === isTestnetAccount;\n\t\t\tif (!isExpectedNetwork) {\n\t\t\t\tconnectedWallet = null;\n\t\t\t}\n\t\t}\n\n\t\tif (connectedWallet?.accounts?.length) {\n\t\t\tconst signedMessage = await nearClient.signMessage({\n\t\t\t\tmessage,\n\t\t\t\trecipient,\n\t\t\t\tnonce: nonceBytes,\n\t\t\t});\n\n\t\t\tif (!signedMessage?.accountId) {\n\t\t\t\tthrow new Error(\"Wallet sign-in was cancelled or failed\");\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tsignedMessage,\n\t\t\t\taccountId: signedMessage.accountId,\n\t\t\t\tpublicKey: signedMessage.publicKey,\n\t\t\t\tnonceHex,\n\t\t\t};\n\t\t}\n\n\t\tconst result: { value: { signedMessage: SignedMessage; accountId: string; publicKey: string } | null } = { value: null };\n\t\tconst handler = (data: EventMap[\"wallet:signInAndSignMessage\"]) => {\n\t\t\tconst account = data.accounts?.[0];\n\t\t\tif (account?.signedMessage) {\n\t\t\t\tresult.value = {\n\t\t\t\t\tsignedMessage: account.signedMessage,\n\t\t\t\t\taccountId: account.accountId,\n\t\t\t\t\tpublicKey: account.signedMessage.publicKey,\n\t\t\t\t};\n\t\t\t}\n\t\t};\n\n\t\tconn.on(\"wallet:signInAndSignMessage\", handler);\n\n\t\ttry {\n\t\t\tawait conn.connect({\n\t\t\t\tsignMessageParams: {\n\t\t\t\t\tmessage,\n\t\t\t\t\trecipient,\n\t\t\t\t\tnonce: nonceBytes,\n\t\t\t\t},\n\t\t\t});\n\t\t} finally {\n\t\t\tconn.off(\"wallet:signInAndSignMessage\", handler);\n\t\t}\n\n\t\tif (!result.value) {\n\t\t\tthrow new Error(\"Wallet sign-in was cancelled or failed\");\n\t\t}\n\n\t\treturn {\n\t\t\tsignedMessage: result.value.signedMessage,\n\t\t\taccountId: result.value.accountId,\n\t\t\tpublicKey: result.value.publicKey,\n\t\t\tnonceHex,\n\t\t};\n\t};\n\n\tconst buildSignedDelegateActionInternal = async (\n\t\treceiverId: string,\n\t\tbuildActions: (builder: TransactionBuilder, receiverId: string) => TransactionBuilder,\n\t): Promise<string> => {\n\t\tconst net = activeNetwork.get();\n\t\tconst state = nearState.get();\n\t\tif (!state?.accountId) {\n\t\t\tthrow new Error(\"No NEAR account found — please sign in with your NEAR wallet\");\n\t\t}\n\n\t\tif (!walletConnected.get()) {\n\t\t\tconst reconnected = await ensureWalletConnected(net);\n\t\t\tif (!reconnected) {\n\t\t\t\tthrow new Error(\"Wallet connection required — please approve the connection to sign\");\n\t\t\t}\n\t\t}\n\n\t\tconst nearClient = requireNear(net);\n\t\tconst builder = buildActions(nearClient.transaction(state.accountId), receiverId);\n\n\t\tconst { payload } = await builder.delegate();\n\t\treturn payload;\n\t};\n\n\tconst plugin: SIWNClientPlugin = {\n\t\tid: \"siwn\",\n\t\t$InferServerPlugin: {} as ReturnType<typeof siwn>,\n\n\t\tgetAtoms: (_$fetch) => ({\n\t\t\tnearState,\n\t\t\twalletConnected,\n\t\t\tactiveNetwork,\n\t\t}),\n\n\t\tgetActions: ($fetch: BetterFetch, _$store: ClientStore, _options: BetterAuthClientOptions | undefined): SIWNClientActions => {\n\t\t\tvoid initClient($fetch);\n\n\t\t\treturn {\n\t\t\t\tnear: {\n\t\t\t\t\tnonce: async (params: NonceRequestT, fetchOptions?: BetterFetchOption) => {\n\t\t\t\t\t\treturn await $fetch(\"/near/nonce\", {\n\t\t\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\t\t\tbody: params,\n\t\t\t\t\t\t\t...fetchOptions\n\t\t\t\t\t\t});\n\t\t\t\t\t},\n\t\t\t\t\tverify: async (params: VerifyRequestT, fetchOptions?: BetterFetchOption) => {\n\t\t\t\t\t\treturn await $fetch(\"/near/verify\", {\n\t\t\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\t\t\tbody: params,\n\t\t\t\t\t\t\t...fetchOptions\n\t\t\t\t\t\t});\n\t\t\t\t\t},\n\t\t\t\t\tgetProfile: async (accountId?: AccountId, fetchOptions?: BetterFetchOption) => {\n\t\t\t\t\t\treturn await $fetch(\"/near/profile\", {\n\t\t\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\t\t\tbody: { accountId },\n\t\t\t\t\t\t\t...fetchOptions\n\t\t\t\t\t\t});\n\t\t\t\t\t},\n\t\t\t\t\tview: async (params: ViewContractRequestT, fetchOptions?: BetterFetchOption) => {\n\t\t\t\t\t\treturn await $fetch(\"/near/view\", {\n\t\t\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\t\t\tbody: params,\n\t\t\t\t\t\t\t...fetchOptions\n\t\t\t\t\t\t});\n\t\t\t\t\t},\n\t\t\t\t\tgetAccountId: () => {\n\t\t\t\t\t\tconst state = nearState.get();\n\t\t\t\t\t\treturn state?.accountId || null;\n\t\t\t\t\t},\n\t\t\t\t\tgetState: () => nearState.get(),\n\t\t\t\t\tisWalletConnected: () => walletConnected.get(),\n\t\t\t\t\tensureConnected: async () => {\n\t\t\t\t\t\tconst net = activeNetwork.get();\n\t\t\t\t\t\tif (!initializedNetworks.has(net)) {\n\t\t\t\t\t\t\tif (!(await initClientForNetwork(net))) return false;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (walletConnected.get()) {\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tconst conn = connectors.get(net);\n\t\t\t\t\t\t\t\tif (conn) {\n\t\t\t\t\t\t\t\t\tconst { accounts } = await conn.getConnectedWallet();\n\t\t\t\t\t\t\t\t\tif (accounts?.length) return true;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} catch (err) {\n\t\t\t\t\t\t\t\tconsole.error(\"[siwn] restoreFromSession failed:\", err instanceof Error ? err.message : err);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn ensureWalletConnected(net);\n\t\t\t\t\t},\n\t\t\t\t\tdisconnect: async () => {\n\t\t\t\t\t\tfor (const [_net, conn] of connectors) {\n\t\t\t\t\t\t\tif (conn) {\n\t\t\t\t\t\t\t\ttry { await conn.disconnect(); } catch {}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\twalletConnected.set(false);\n\t\t\t\t\t\tnearState.set(null);\n\t\t\t\t\t},\n\t\t\t\t\tlink: async (callbacks?: AuthCallbacks) => {\n\t\t\t\t\t\tconst net = activeNetwork.get();\n\t\t\t\t\t\tconst recipient = getRecipient(net);\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tconst { signedMessage, accountId, nonceHex } = await signWithWallet();\n\t\t\t\t\t\t\tconst message = `Sign in to ${recipient}`;\n\n\t\t\t\t\t\t\tawait handleAccountConnection(accountId, signedMessage.publicKey, net);\n\n\t\t\t\t\t\t\tconst linkResponse = await $fetch<{ success: boolean; accountId: string; network: string; message: string }>(\"/near/link-account\", {\n\t\t\t\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\t\tsignedMessage,\n\t\t\t\t\t\t\t\t\tmessage,\n\t\t\t\t\t\t\t\t\trecipient,\n\t\t\t\t\t\t\t\t\tnonce: nonceHex,\n\t\t\t\t\t\t\t\t\taccountId,\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\tif (linkResponse.error) {\n\t\t\t\t\t\t\t\tthrow new Error(linkResponse.error.message || \"Failed to link NEAR account\");\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tif (!linkResponse?.data?.success) {\n\t\t\t\t\t\t\t\tthrow new Error(\"Account linking failed\");\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tcallbacks?.onSuccess?.();\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\tconst err = error instanceof Error ? error : new Error(String(error));\n\t\t\t\t\t\t\tcallbacks?.onError?.(err);\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t\tunlink: async (\n\t\t\t\t\t\tparams: { accountId: string; network?: \"mainnet\" | \"testnet\" },\n\t\t\t\t\t\tfetchOptions?: BetterFetchOption\n\t\t\t\t\t) => {\n\t\t\t\t\t\treturn await $fetch(\"/near/unlink-account\", {\n\t\t\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\t\t\tbody: params,\n\t\t\t\t\t\t\t...fetchOptions\n\t\t\t\t\t\t});\n\t\t\t\t\t},\n\t\t\t\t\tlistAccounts: async (): Promise<BetterFetchResponse<ListAccountsResponseT>> => {\n\t\t\t\t\t\treturn await $fetch(\"/near/list-accounts\", { method: \"GET\" });\n\t\t\t\t\t},\n\t\t\t\t\tsetPrimaryAccount: async (params: SetPrimaryAccountRequestT) => {\n\t\t\t\t\t\tconst response = await $fetch<SetPrimaryAccountResponseT>(\"/near/set-primary-account\", {\n\t\t\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\t\t\tbody: params,\n\t\t\t\t\t\t});\n\t\t\t\t\t\tconst activeAccount = response.data?.activeAccount;\n\t\t\t\t\t\tif (activeAccount) {\n\t\t\t\t\t\t\tnearState.set({\n\t\t\t\t\t\t\t\taccountId: activeAccount.accountId,\n\t\t\t\t\t\t\t\tpublicKey: activeAccount.publicKey ?? null,\n\t\t\t\t\t\t\t\tnetworkId: activeAccount.network,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\tactiveNetwork.set(activeAccount.network);\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn response;\n\t\t\t\t\t},\n\t\t\t\t\tbuildSignedDelegateAction: async (\n\t\t\t\t\t\treceiverId: string,\n\t\t\t\t\t\tbuildActions: (builder: TransactionBuilder, receiverId: string) => TransactionBuilder,\n\t\t\t\t\t): Promise<string> => {\n\t\t\t\t\t\treturn buildSignedDelegateActionInternal(receiverId, buildActions);\n\t\t\t\t\t},\n\t\t\t\t\trelayTransaction: async (params: { payload: string }) => {\n\t\t\t\t\t\treturn await $fetch(\"/near/relay\", {\n\t\t\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\t\t\tbody: params,\n\t\t\t\t\t\t});\n\t\t\t\t\t},\n\t\t\t\t\tgetRelayStatus: async (txHash: string) => {\n\t\t\t\t\t\treturn await $fetch(`/near/relay-status/${txHash}`, {\n\t\t\t\t\t\t\tmethod: \"GET\",\n\t\t\t\t\t\t});\n\t\t\t\t\t},\n\t\t\t\t\tgetRelayerInfo: async (params?: GetRelayerInfoRequestT) => {\n\t\t\t\t\t\treturn await $fetch(\"/near/relayer-info\", {\n\t\t\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\t\t\tbody: params ?? {},\n\t\t\t\t\t\t});\n\t\t\t\t\t},\n\t\t\t\t\trelayHistory: async () => {\n\t\t\t\t\t\treturn await $fetch(\"/near/relay-history\", {\n\t\t\t\t\t\t\tmethod: \"GET\",\n\t\t\t\t\t\t});\n\t\t\t\t\t},\n\t\t\t\t\tcreateSubAccount: async (params: CreateSubAccountRequestT) => {\n\t\t\t\t\t\treturn await $fetch(\"/near/create-sub-account\", {\n\t\t\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\t\t\tbody: params,\n\t\t\t\t\t\t});\n\t\t\t\t\t},\n\t\t\t\t\tcheckSubAccountAvailability: async (params: CheckSubAccountAvailabilityRequestT) => {\n\t\t\t\t\t\treturn await $fetch(\"/near/check-sub-account-availability\", {\n\t\t\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\t\t\tbody: params,\n\t\t\t\t\t\t});\n\t\t\t\t\t},\n\t\t\t\t\tsetNetwork: (network: \"mainnet\" | \"testnet\") => {\n\t\t\t\t\t\tconst prev = activeNetwork.get();\n\t\t\t\t\t\tif (prev !== network) {\n\t\t\t\t\t\t\tconst oldConn = connectors.get(prev);\n\t\t\t\t\t\t\tif (oldConn) {\n\t\t\t\t\t\t\t\tvoid oldConn.disconnect().catch(() => {});\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\twalletConnected.set(false);\n\t\t\t\t\t\t\tnearState.set(null);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tactiveNetwork.set(network);\n\t\t\t\t\t\tvoid initClientForNetwork(network);\n\t\t\t\t\t},\n\t\t\t\t\tgetNetwork: () => activeNetwork.get(),\n\t\t\t\t\tgetSupportedNetworks: () => getSupportedNetworks(),\n\t\t\t\t\tgetRecipient: (network?: \"mainnet\" | \"testnet\") => getRecipient(network),\n\t\t\t\t\tget client(): NearType {\n\t\t\t\t\t\tconst net = activeNetwork.get();\n\t\t\t\t\t\tconst client = nearClients.get(net);\n\t\t\t\t\t\tif (!client) throw new Error(`Wallet not initialized for ${net} — this operation requires a browser environment`);\n\t\t\t\t\t\treturn client;\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tsignIn: {\n\t\t\t\t\tnear: async (callbacks?: AuthCallbacks) => {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tconst { signedMessage, accountId, nonceHex } = await signWithWallet();\n\t\t\t\t\t\t\tconst net = activeNetwork.get();\n\t\t\t\t\t\t\tconst recipient = getRecipient(net);\n\t\t\t\t\t\t\tconst message = `Sign in to ${recipient}`;\n\n\t\t\t\t\t\t\tawait handleAccountConnection(accountId, signedMessage.publicKey, net);\n\n\t\t\t\t\t\t\tconst verifyResponse: BetterFetchResponse<VerifyResponseT> = await $fetch(\"/near/verify\", {\n\t\t\t\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\t\tsignedMessage,\n\t\t\t\t\t\t\t\t\tmessage,\n\t\t\t\t\t\t\t\t\trecipient,\n\t\t\t\t\t\t\t\t\tnonce: nonceHex,\n\t\t\t\t\t\t\t\t\taccountId,\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\tif (verifyResponse.error) {\n\t\t\t\t\t\t\t\tthrow new Error(verifyResponse.error.message || \"Failed to verify signature\");\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tif (!verifyResponse?.data?.success) {\n\t\t\t\t\t\t\t\tthrow new Error(\"Authentication verification failed\");\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tcallbacks?.onSuccess?.();\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\tconst err = error instanceof Error ? error : new Error(String(error));\n\t\t\t\t\t\t\tcallbacks?.onError?.(err);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t};\n\t\t}\n\t};\n\n\treturn plugin;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCA,MAAa,oBAAoB,EAAE,OAAO;CACzC,KAAK,EAAE,OAAO,EAAE,SAAS;CACzB,UAAU,EAAE,OAAO,EAAE,SAAS;AAC/B,CAAC;AAED,MAAa,gBAAgB,EAAE,OAAO;CACrC,MAAM,EAAE,OAAO,EAAE,SAAS;CAC1B,aAAa,EAAE,OAAO,EAAE,SAAS;CACjC,OAAO,kBAAkB,SAAS;CAClC,iBAAiB,kBAAkB,SAAS;CAC5C,UAAU,EAAE,OAAO,EAAE,OAAO,GAAG,EAAE,OAAO,CAAC,EAAE,SAAS;AACrD,CAAC;AAKD,MAAM,sBAAsB,EAAE,OAAO;CACpC,WAAW,EAAE,OAAO;CACpB,WAAW,EAAE,OAAO;CACpB,WAAW,EAAE,OAAO;CACpB,OAAO,EAAE,OAAO,EAAE,SAAS;AAC5B,CAAC;AAEiC,EAAE,OAAO;CAC1C,eAAe;CACf,SAAS,EAAE,OAAO;CAClB,WAAW,EAAE,OAAO;CACpB,OAAO,EAAE,OAAO;CAChB,WAAW;CACX,aAAa,EAAE,OAAO,EAAE,SAAS;AAClC,CAAC;AAEuC,EAAE,OAAO;CAChD,WAAW;CACX,SAAS,EAAE,KAAK,CAAC,WAAW,SAAS,CAAC,EAAE,SAAS;AAClD,CAAC;AAE2B,EAAE,OAAO;CACpC,WAAW;CACX,WAAW,EAAE,MAAM,CAAC,EAAE,QAAQ,SAAS,GAAG,EAAE,QAAQ,SAAS,CAAC,CAAC;AAChE,CAAC;AAE4B,EAAE,OAAO;CACrC,eA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,OAAO;KACvE,IAAI,SAAmB;MACtB,MAAM,MAAM,cAAc,IAAI;MAC9B,MAAM,SAAS,YAAY,IAAI,GAAG;MAClC,IAAI,CAAC,QAAQ,MAAM,IAAI,MAAM,8BAA8B,IAAI,iDAAiD;MAChH,OAAO;KACR;IACD;IACA,QAAQ,EACP,MAAM,OAAO,cAA8B;KAC1C,IAAI;MACH,MAAM,EAAE,eAAe,WAAW,aAAa,MAAM,eAAe;MACpE,MAAM,MAAM,cAAc,IAAI;MAC9B,MAAM,YAAY,aAAa,GAAG;MAClC,MAAM,UAAU,cAAc;MAE9B,MAAM,wBAAwB,WAAW,cAAc,WAAW,GAAG;MAErE,MAAM,iBAAuD,MAAM,OAAO,gBAAgB;OACzF,QAAQ;OACR,MAAM;QACL;QACA;QACA;QACA,OAAO;QACP;OACD;MACD,CAAC;MAED,IAAI,eAAe,OAClB,MAAM,IAAI,MAAM,eAAe,MAAM,WAAW,4BAA4B;MAG7E,IAAI,CAAC,gBAAgB,MAAM,SAC1B,MAAM,IAAI,MAAM,oCAAoC;MAGrD,WAAW,YAAY;KACxB,SAAS,OAAO;MACf,MAAM,MAAM,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,KAAK,CAAC;MACpE,WAAW,UAAU,GAAG;KACzB;IACD,EACD;GACD;EACD;CAGW;AACb"}
package/dist/index.d.ts CHANGED
@@ -287,6 +287,7 @@ export declare const siwn: (options: SIWNPluginOptions) => {
287
287
  recipient: z.ZodString;
288
288
  nonce: z.ZodString;
289
289
  accountId: z.ZodString;
290
+ callbackUrl: z.ZodOptional<z.ZodString>;
290
291
  }, z.z.core.$strip>;
291
292
  use: ((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
292
293
  session: {
@@ -486,6 +487,7 @@ export declare const siwn: (options: SIWNPluginOptions) => {
486
487
  recipient: z.ZodString;
487
488
  nonce: z.ZodString;
488
489
  accountId: z.ZodString;
490
+ callbackUrl: z.ZodOptional<z.ZodString>;
489
491
  }, z.z.core.$strip>;
490
492
  requireRequest: true;
491
493
  }, {
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAiB,SAAS,EAAE,MAAM,mBAAmB,CAAC;AASlE,OAAO,CAAC,MAAM,KAAK,CAAC;AAGpB,OAAO,EACN,KAAK,SAAS,EACd,KAAK,iBAAiB,EACtB,KAAK,qBAAqB,EAC1B,KAAK,iBAAiB,EAEtB,KAAK,OAAO,EAGZ,KAAK,gBAAgB,EAmBrB,MAAM,YAAY,CAAC;AACpB,cAAc,YAAY,CAAC;AA2D3B,MAAM,WAAW,aAAa;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAC;IAChC,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,wBAAwB,CAAC,EAAE,MAAM,CAAC;CAClC;AA2LD,MAAM,WAAW,iBAAiB;IACjC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,iBAAiB,CAAC,MAAM,CAAC,CAAC;IACvC,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,QAAQ,CAAC,EAAE,MAAM,OAAO,CAAC,UAAU,CAAC,CAAC;IACrC,UAAU,CAAC,EAAE,CAAC,SAAS,EAAE,SAAS,KAAK,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC;IAC/D,wBAAwB,CAAC,EAAE,CAAC,IAAI,EAAE;QACjC,SAAS,EAAE,SAAS,CAAC;QACrB,SAAS,EAAE,MAAM,CAAC;QAClB,SAAS,CAAC,EAAE,MAAM,CAAC;KACnB,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CA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4BAeV,CAAC;;;;;;;;;;;;;;;;;;;mCAgBO,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iCA7OJ,CAAC;iCAGV,CAAC;;;;;;;;;6BAMsC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iCAT/B,CAAC;iCAGV,CAAC;;;;;;;;;6BAMsC,CAAC;;;;;;;;;;;;;;;;;;;;;iCAT/B,CAAC;iCAGV,CAAC;;;;;;;;;6BAMsC,CAAC;;;;;;;;;;;;;;;;;;;;;;;iCAT/B,CAAC;iCAGV,CAAC;;;;;;;;;6BAMsC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iCAT/B,CAAC;iCAGV,CAAC;;;;;;;;;6BAMsC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iCAT/B,CAAC;iCAGV,CAAC;;;;;;;;;6BAMsC,CAAC;;;;;;;;;;;;;;;;;;;iCAT/B,CAAC;iCAGV,CAAC;;;;;;;;;6BAMsC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;iCAT/B,CAAC;iCAGV,CAAC;;;;;;;;;6BAMsC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iCAT/B,CAAC;iCAGV,CAAC;;;;;;;;;6BAMsC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iCAT/B,CAAC;iCAGV,CAAC;;;;;;;;;6BAMsC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;iCAT/B,CAAC;iCAGV,CAAC;;;;;;;;;6BAMsC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;CA25CvC,CAAC"}
package/dist/index.js CHANGED
@@ -179,7 +179,8 @@ const LinkAccountRequest = z.object({
179
179
  message: z.string(),
180
180
  recipient: z.string(),
181
181
  nonce: z.string(),
182
- accountId: AccountIdSchema
182
+ accountId: AccountIdSchema,
183
+ callbackUrl: z.string().optional()
183
184
  });
184
185
  const SetPrimaryAccountRequest = z.object({
185
186
  accountId: AccountIdSchema,
@@ -194,7 +195,8 @@ const VerifyRequest = z.object({
194
195
  message: z.string(),
195
196
  recipient: z.string(),
196
197
  nonce: z.string(),
197
- accountId: AccountIdSchema
198
+ accountId: AccountIdSchema,
199
+ callbackUrl: z.string().optional()
198
200
  });
199
201
  const RelayRequest = z.object({ payload: z.string() });
200
202
  const RelayResponse = z.object({
@@ -316,9 +318,12 @@ async function hashNonce(nonce) {
316
318
  const hashBuffer = await crypto.subtle.digest("SHA-256", data);
317
319
  return hex.encode(new Uint8Array(hashBuffer));
318
320
  }
319
- function deriveEmail(accountId) {
320
- if (accountId.endsWith(".near")) return `${accountId.slice(0, -5)}@near.email`;
321
- return null;
321
+ function deriveEmail(accountId, recipient) {
322
+ if (accountId.endsWith(".near")) {
323
+ const localPart = accountId.slice(0, -5);
324
+ if (!localPart.includes(".")) return `${localPart}@near.email`;
325
+ }
326
+ return `temp-${crypto.randomUUID().slice(0, 8)}@${recipient}`;
322
327
  }
323
328
  function nearAccountKey(account) {
324
329
  return `${account.accountId}:${account.network}`;
@@ -565,7 +570,7 @@ const siwn = (options) => {
565
570
  use: [sessionMiddleware],
566
571
  requireRequest: true
567
572
  }, async (ctx) => {
568
- const { signedMessage, message, recipient, nonce, accountId } = ctx.body;
573
+ const { signedMessage, message, recipient, nonce, accountId, callbackUrl } = ctx.body;
569
574
  const network = getNetworkFromAccountId(accountId);
570
575
  const session = ctx.context.session;
571
576
  if (!session) throw new APIError("UNAUTHORIZED", {
@@ -577,7 +582,8 @@ const siwn = (options) => {
577
582
  if (!await verifyNep413Signature(signedMessage, {
578
583
  message,
579
584
  recipient,
580
- nonce: hex.decode(nonce)
585
+ nonce: hex.decode(nonce),
586
+ callbackUrl
581
587
  }, {
582
588
  near,
583
589
  maxAge: 900 * 1e3
@@ -923,7 +929,7 @@ const siwn = (options) => {
923
929
  body: VerifyRequest,
924
930
  requireRequest: true
925
931
  }, async (ctx) => {
926
- const { signedMessage, message, recipient, nonce, accountId } = ctx.body;
932
+ const { signedMessage, message, recipient, nonce, accountId, callbackUrl } = ctx.body;
927
933
  const network = getNetworkFromAccountId(accountId);
928
934
  try {
929
935
  const near = getNear(network);
@@ -931,7 +937,8 @@ const siwn = (options) => {
931
937
  if (!await verifyNep413Signature(signedMessage, {
932
938
  message,
933
939
  recipient,
934
- nonce: nonceBytes
940
+ nonce: nonceBytes,
941
+ callbackUrl
935
942
  }, {
936
943
  near,
937
944
  maxAge: 900 * 1e3
@@ -1005,7 +1012,7 @@ const siwn = (options) => {
1005
1012
  });
1006
1013
  }
1007
1014
  if (!user) {
1008
- const userEmail = deriveEmail(accountId) ?? "";
1015
+ const userEmail = deriveEmail(accountId, getRecipient(network));
1009
1016
  const profile = await (options.getProfile || ((id) => defaultGetProfile(id, apiKey)))(accountId);
1010
1017
  user = await ctx.context.internalAdapter.createUser({
1011
1018
  name: profile?.name ?? accountId,
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["z"],"sources":["../src/profile.ts","../src/schema.ts","../src/types.ts","../src/utils.ts","../src/index.ts"],"sourcesContent":["import type { AccountId, Profile, SocialImage } from \"./types.js\";\n\nconst FALLBACK_URL =\n\t\"https://ipfs.near.social/ipfs/bafkreidn5fb2oygegqaldx7ycdmhu4owcrmoxd7ekbzfmeakkobz2ja7qy\";\n\nfunction getNetworkFromAccountId(accountId: string): \"mainnet\" | \"testnet\" {\n\treturn accountId.endsWith('.testnet') ? 'testnet' : 'mainnet';\n}\n\nfunction getImageUrl(\n\timage: SocialImage | undefined,\n\tfallback?: string,\n): string {\n\tif (image?.url) return image.url;\n\tif (image?.ipfs_cid) return `https://ipfs.near.social/ipfs/${image.ipfs_cid}`;\n\treturn fallback || FALLBACK_URL;\n}\n\ninterface SocialApiResponse {\n\t[accountId: string]: {\n\t\tprofile?: Profile;\n\t};\n}\n\ninterface KvEntry {\n\tvalue: Record<string, unknown> | string;\n\tblock_height?: number;\n\tblock_hash?: string;\n\ttimestamp_nanosec?: string;\n}\n\ninterface KvResponse {\n\tentries: KvEntry[];\n}\n\nasync function defaultGetProfile(accountId: AccountId, apiKey?: string): Promise<Profile | null> {\n\tconst network = getNetworkFromAccountId(accountId);\n\n\ttry {\n\t\tconst kvUrl = network === \"testnet\"\n\t\t\t? \"https://kv.test.fastnear.com\"\n\t\t\t: \"https://kv.main.fastnear.com\";\n\n\t\tconst effectiveApiKey = apiKey || process.env.FASTNEAR_API_KEY;\n\t\tconst headers: Record<string, string> = { \"Content-Type\": \"application/json\" };\n\t\tif (effectiveApiKey) {\n\t\t\theaders[\"Authorization\"] = `Bearer ${effectiveApiKey}`;\n\t\t}\n\n\t\tconst response = await fetch(\n\t\t\t`${kvUrl}/v0/latest/social.near/${accountId}/profile/**`,\n\t\t\t{ headers },\n\t\t);\n\n\t\tif (response.ok) {\n\t\t\tconst data = await response.json() as KvResponse;\n\t\t\tconst entry = data?.entries?.[0];\n\t\t\tif (entry?.value) {\n\t\t\t\ttry {\n\t\t\t\t\tconst profile = typeof entry.value === \"string\"\n\t\t\t\t\t\t? JSON.parse(entry.value)\n\t\t\t\t\t\t: entry.value;\n\t\t\t\t\tif (profile?.name || profile?.description || profile?.image) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tname: profile.name,\n\t\t\t\t\t\t\tdescription: profile.description,\n\t\t\t\t\t\t\timage: profile.image,\n\t\t\t\t\t\t\tbackgroundImage: profile.backgroundImage,\n\t\t\t\t\t\t\tlinktree: profile.linktree,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t} catch {}\n\t\t\t}\n\t\t}\n\n\t\tconst apiBase = {\n\t\t\tmainnet: \"https://api.near.social\",\n\t\t\ttestnet: \"https://test.api.near.social\",\n\t\t}[network];\n\n\t\tconst keys = [`${accountId}/profile/**`];\n\n\t\tconst fallbackResponse = await fetch(`${apiBase}/get`, {\n\t\t\tmethod: \"POST\",\n\t\t\theaders: { \"Content-Type\": \"application/json\" },\n\t\t\tbody: JSON.stringify({ keys })\n\t\t});\n\n\t\tif (!fallbackResponse.ok) {\n\t\t\tthrow new Error(`HTTP error! status: ${fallbackResponse.status}`);\n\t\t}\n\n\t\tconst fallbackData = await fallbackResponse.json() as SocialApiResponse;\n\t\tconst profile: Profile | undefined = fallbackData?.[accountId]?.profile;\n\n\t\tif (profile) {\n\t\t\treturn {\n\t\t\t\tname: profile.name,\n\t\t\t\tdescription: profile.description,\n\t\t\t\timage: profile.image,\n\t\t\t\tbackgroundImage: profile.backgroundImage,\n\t\t\t\tlinktree: profile.linktree\n\t\t\t};\n\t\t}\n\t\treturn null;\n\t} catch (error) {\n\t\treturn null;\n\t}\n}\n\nexport { defaultGetProfile, getImageUrl, getNetworkFromAccountId };\n","import type { BetterAuthPluginDBSchema } from \"better-auth/db\";\n\nexport const schema = {\n\tnearAccount: {\n\t\tfields: {\n\t\t\tuserId: {\n\t\t\t\ttype: \"string\",\n\t\t\t\treferences: {\n\t\t\t\t\tmodel: \"user\",\n\t\t\t\t\tfield: \"id\",\n\t\t\t\t},\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t\taccountId: {\n\t\t\t\ttype: \"string\",\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t\tnetwork: {\n\t\t\t\ttype: \"string\",\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t\tpublicKey: {\n\t\t\t\ttype: \"string\",\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t\tisPrimary: {\n\t\t\t\ttype: \"boolean\",\n\t\t\t\tdefaultValue: false,\n\t\t\t},\n\t\t\tcreatedAt: {\n\t\t\t\ttype: \"date\",\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t},\n\t},\n\trelayedTransaction: {\n\t\tfields: {\n\t\t\tuserId: {\n\t\t\t\ttype: \"string\",\n\t\t\t\treferences: {\n\t\t\t\t\tmodel: \"user\",\n\t\t\t\t\tfield: \"id\",\n\t\t\t\t},\n\t\t\t},\n\t\t\ttxHash: {\n\t\t\t\ttype: \"string\",\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t\tsenderId: {\n\t\t\t\ttype: \"string\",\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t\treceiverId: {\n\t\t\t\ttype: \"string\",\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t\tnetwork: {\n\t\t\t\ttype: \"string\",\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t\tstatus: {\n\t\t\t\ttype: \"string\",\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t\tgasUsed: {\n\t\t\t\ttype: \"string\",\n\t\t\t},\n\t\t\tcreatedAt: {\n\t\t\t\ttype: \"date\",\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t\tupdatedAt: {\n\t\t\t\ttype: \"date\",\n\t\t\t},\n\t\t},\n\t},\n\trelayerKey: {\n\t\tfields: {\n\t\t\taccountId: {\n\t\t\t\ttype: \"string\",\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t\tencryptedPrivateKey: {\n\t\t\t\ttype: \"string\",\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t\tiv: {\n\t\t\t\ttype: \"string\",\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t\tpublicKey: {\n\t\t\t\ttype: \"string\",\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t\tnetwork: {\n\t\t\t\ttype: \"string\",\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t\tcreatedAt: {\n\t\t\t\ttype: \"date\",\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t\tlastUsedAt: {\n\t\t\t\ttype: \"date\",\n\t\t\t},\n\t\t},\n\t},\n} satisfies BetterAuthPluginDBSchema;\n","import { z } from \"zod\";\nimport { AccountIdSchema, type AccountId } from \"near-kit/schemas\";\nimport type { AccountState } from \"near-kit\";\n\nexport type { AccountId };\n\nexport interface NearAccount {\n\tid: string;\n\tuserId: string;\n\taccountId: string;\n\tnetwork: \"mainnet\" | \"testnet\";\n\tpublicKey: string;\n\tisPrimary: boolean;\n\tcreatedAt: Date;\n}\n\nexport interface ListedNearAccount extends NearAccount {\n\tproviderId: \"siwn\";\n\tisActive: boolean;\n\tisAvailable: boolean;\n}\n\nexport interface ListAccountsResponseT {\n\taccounts: ListedNearAccount[];\n\tactiveAccount: ListedNearAccount | null;\n\tavailableAccounts: ListedNearAccount[];\n}\n\nexport interface SetPrimaryAccountResponseT extends ListAccountsResponseT {\n\tsuccess: boolean;\n\taccountId: string;\n\tnetwork: \"mainnet\" | \"testnet\";\n\tmessage: string;\n}\n\nexport const socialImageSchema = z.object({\n\turl: z.string().optional(),\n\tipfs_cid: z.string().optional(),\n});\n\nexport const profileSchema = z.object({\n\tname: z.string().optional(),\n\tdescription: z.string().optional(),\n\timage: socialImageSchema.optional(),\n\tbackgroundImage: socialImageSchema.optional(),\n\tlinktree: z.record(z.string(), z.string()).optional(),\n});\n\nexport type SocialImage = z.infer<typeof socialImageSchema>;\nexport type Profile = z.infer<typeof profileSchema>;\n\nconst signedMessageSchema = z.object({\n\taccountId: z.string(),\n\tpublicKey: z.string(),\n\tsignature: z.string(),\n\tstate: z.string().optional(),\n});\n\nexport const LinkAccountRequest = z.object({\n\tsignedMessage: signedMessageSchema,\n\tmessage: z.string(),\n\trecipient: z.string(),\n\tnonce: z.string(),\n\taccountId: AccountIdSchema,\n});\n\nexport const SetPrimaryAccountRequest = z.object({\n\taccountId: AccountIdSchema,\n\tnetwork: z.enum([\"mainnet\", \"testnet\"]).optional(),\n});\n\nexport const NonceRequest = z.object({\n\taccountId: AccountIdSchema,\n\tnetworkId: z.union([z.literal(\"mainnet\"), z.literal(\"testnet\")])\n});\n\nexport const VerifyRequest = z.object({\n\tsignedMessage: signedMessageSchema,\n\tmessage: z.string(),\n\trecipient: z.string(),\n\tnonce: z.string(),\n\taccountId: AccountIdSchema,\n});\n\nexport const RelayRequest = z.object({\n\tpayload: z.string(),\n});\nexport type RelayRequestT = z.infer<typeof RelayRequest>;\n\nexport const RelayResponse = z.object({\n\ttxHash: z.string(),\n\tstatus: z.enum([\"pending\", \"completed\", \"failed\"]),\n});\nexport type RelayResponseT = z.infer<typeof RelayResponse>;\n\nexport const RelayStatusResponse = z.object({\n\tstatus: z.enum([\"pending\", \"completed\", \"failed\"]),\n\tgasUsed: z.string().optional(),\n\toutcome: z.unknown().optional(),\n});\nexport type RelayStatusResponseT = z.infer<typeof RelayStatusResponse>;\n\nexport const ViewContractRequest = z.object({\n\tcontractId: z.string(),\n\tmethodName: z.string(),\n\targs: z.record(z.string(), z.any()).optional(),\n});\nexport type ViewContractRequestT = z.infer<typeof ViewContractRequest>;\n\nexport const NonceResponse = z.object({ nonce: z.string() });\nexport const VerifyResponse = z.object({\n\ttoken: z.string(),\n\tsuccess: z.literal(true),\n\tuser: z.object({\n\t\tid: z.string(),\n\t\taccountId: AccountIdSchema,\n\t\tnetwork: z.union([z.literal(\"mainnet\"), z.literal(\"testnet\")]),\n\t}),\n});\nexport const ProfileResponse = profileSchema.nullable();\nexport const ViewContractResponse = z.object({ result: z.unknown() });\n\nexport const ProfileRequest = z.object({\n\taccountId: AccountIdSchema.optional(),\n});\nexport type ProfileRequestT = z.infer<typeof ProfileRequest>;\n\nexport type NonceRequestT = z.infer<typeof NonceRequest>;\nexport type NonceResponseT = z.infer<typeof NonceResponse>;\nexport type SetPrimaryAccountRequestT = z.infer<typeof SetPrimaryAccountRequest>;\nexport type VerifyRequestT = z.infer<typeof VerifyRequest>;\nexport type VerifyResponseT = z.infer<typeof VerifyResponse>;\nexport type ProfileResponseT = z.infer<typeof ProfileResponse>;\nexport type ViewContractResponseT = z.infer<typeof ViewContractResponse>;\n\nexport const RelayedTransactionSchema = z.object({\n\tid: z.string(),\n\tuserId: z.string(),\n\ttxHash: z.string(),\n\tsenderId: z.string(),\n\treceiverId: z.string(),\n\tnetwork: z.string(),\n\tstatus: z.string(),\n\tgasUsed: z.string().optional(),\n\tcreatedAt: z.string(),\n\tupdatedAt: z.string().optional(),\n});\nexport type RelayedTransactionT = z.infer<typeof RelayedTransactionSchema>;\n\nexport const RelayHistoryResponse = z.object({\n\ttransactions: z.array(RelayedTransactionSchema),\n});\nexport type RelayHistoryResponseT = z.infer<typeof RelayHistoryResponse>;\n\nexport interface RelayedTransactionRecord {\n\tid: string;\n\tuserId: string;\n\ttxHash: string;\n\tsenderId: string;\n\treceiverId: string;\n\tnetwork: \"mainnet\" | \"testnet\";\n\tstatus: string;\n\tgasUsed?: string;\n\tcreatedAt: Date;\n\tupdatedAt: Date;\n}\n\nexport interface RelayerInfo extends AccountState {\n\taccountId: string;\n\tmode: \"ephemeral\" | \"explicit\";\n\tnetwork: \"mainnet\" | \"testnet\";\n\tpublicKey: string;\n\thasKey: boolean;\n\tcreatedAt?: Date;\n\tlastUsedAt?: Date;\n\tparentAccount?: string;\n\tsubAccountAvailable?: boolean;\n}\n\nexport interface DualNetworkConfig<T> {\n\tmainnet: T;\n\ttestnet: T;\n}\n\nexport const GetRelayerInfoRequest = z.object({\n\tnetwork: z.enum([\"mainnet\", \"testnet\"]).optional(),\n});\nexport type GetRelayerInfoRequestT = z.infer<typeof GetRelayerInfoRequest>;\n\nexport interface SubAccountRelayerFCAKConfig {\n\treceiverId: string;\n\tmethodNames?: string[];\n\tallowance?: string;\n}\n\nexport interface SubAccountConfig {\n\tparentAccount?: string;\n\tparentKey?: string;\n\tminDeposit?: string;\n\taddRelayerFCAK?: boolean;\n\trelayerFCAK?: SubAccountRelayerFCAKConfig;\n}\n\nexport const CreateSubAccountRequest = z.object({\n\tsubAccountName: z.string().regex(/^[a-z0-9]+$/, \"Must be lowercase alphanumeric characters only\"),\n\tnetwork: z.enum([\"mainnet\", \"testnet\"]).optional(),\n\tpublicKey: z.string(),\n});\nexport type CreateSubAccountRequestT = z.infer<typeof CreateSubAccountRequest>;\n\nexport const CreateSubAccountResponse = z.object({\n\tsuccess: z.literal(true),\n\taccountId: z.string(),\n\tnetwork: z.enum([\"mainnet\", \"testnet\"]),\n\tpublicKey: z.string(),\n\tmessage: z.string(),\n});\nexport type CreateSubAccountResponseT = z.infer<typeof CreateSubAccountResponse>;\n\nexport const CheckSubAccountAvailabilityRequest = z.object({\n\tsubAccountName: z.string().regex(/^[a-z0-9]+$/),\n\tnetwork: z.enum([\"mainnet\", \"testnet\"]).optional(),\n});\nexport type CheckSubAccountAvailabilityRequestT = z.infer<typeof CheckSubAccountAvailabilityRequest>;\n\nexport const CheckSubAccountAvailabilityResponse = z.object({\n\tavailable: z.boolean(),\n\taccountId: z.string(),\n});\nexport type CheckSubAccountAvailabilityResponseT = z.infer<typeof CheckSubAccountAvailabilityResponse>;\n","export function bytesToBase64(bytes: Uint8Array): string {\n\treturn btoa(String.fromCharCode(...bytes));\n}\n\nfunction base64ToBytes(base64: string): Uint8Array {\n\treturn Uint8Array.from(atob(base64), c => c.charCodeAt(0));\n}\n\nexport function bytesToHex(bytes: Uint8Array): string {\n\treturn Array.from(bytes).map(b => b.toString(16).padStart(2, \"0\")).join(\"\");\n}\n\nexport function hexToBytes(hex: string): Uint8Array {\n\tconst bytes = new Uint8Array(hex.length / 2);\n\tfor (let i = 0; i < hex.length; i += 2) {\n\t\tbytes[i / 2] = parseInt(hex.substring(i, i + 2), 16);\n\t}\n\treturn bytes;\n}\n\nasync function deriveAesKey(secret: string): Promise<CryptoKey> {\n\tconst keyMaterial = await crypto.subtle.importKey(\n\t\t\"raw\",\n\t\tnew TextEncoder().encode(secret),\n\t\t{ name: \"HKDF\" },\n\t\tfalse,\n\t\t[\"deriveKey\"],\n\t);\n\treturn crypto.subtle.deriveKey(\n\t\t{\n\t\t\tname: \"HKDF\",\n\t\t\thash: \"SHA-256\",\n\t\t\tsalt: new TextEncoder().encode(\"better-near-auth-relayer\"),\n\t\t\tinfo: new Uint8Array(0),\n\t\t},\n\t\tkeyMaterial,\n\t\t{ name: \"AES-GCM\", length: 256 },\n\t\tfalse,\n\t\t[\"encrypt\", \"decrypt\"],\n\t);\n}\n\nexport async function encryptPrivateKey(\n\tprivateKey: Uint8Array,\n\tsecret: string,\n): Promise<{ encrypted: string; iv: string }> {\n\tconst aesKey = await deriveAesKey(secret);\n\tconst iv = crypto.getRandomValues(new Uint8Array(12));\n\tconst encrypted = await crypto.subtle.encrypt(\n\t\t{ name: \"AES-GCM\", iv },\n\t\taesKey,\n\t\tprivateKey as Uint8Array<ArrayBuffer>,\n\t);\n\treturn {\n\t\tencrypted: bytesToBase64(new Uint8Array(encrypted)),\n\t\tiv: bytesToBase64(iv),\n\t};\n}\n\nexport async function decryptPrivateKey(\n\tencrypted: string,\n\tiv: string,\n\tsecret: string,\n): Promise<Uint8Array> {\n\tconst aesKey = await deriveAesKey(secret);\n\tconst decrypted = await crypto.subtle.decrypt(\n\t\t{ name: \"AES-GCM\", iv: base64ToBytes(iv) as Uint8Array<ArrayBuffer> },\n\t\taesKey,\n\t\tbase64ToBytes(encrypted) as Uint8Array<ArrayBuffer>,\n\t);\n\treturn new Uint8Array(decrypted);\n}\n","import { APIError, createAuthEndpoint, createAuthMiddleware, sessionMiddleware } from \"better-auth/api\";\nimport { setSessionCookie } from \"better-auth/cookies\";\nimport type { Account, User, DBAdapter } from \"better-auth/types\";\n// Explicit type imports for declaration emit\nimport type {} from \"@better-auth/core/env\";\nimport type {} from \"@better-auth/core/oauth2\";\nimport type {} from \"better-call\";\n\nimport { Near, generateNonce, generateKey, parseKey, verifyNep413Signature, decodeSignedDelegateAction, InMemoryKeyStore, RotatingKeyStore } from \"near-kit\";\nimport type { SignedDelegateAction, PrivateKey } from \"near-kit\";\nimport { hex, base58 } from \"@scure/base\";\nimport z from \"zod\";\nimport { defaultGetProfile, getImageUrl, getNetworkFromAccountId } from \"./profile.js\";\nimport { schema } from \"./schema.js\";\nimport {\n\ttype AccountId,\n\ttype DualNetworkConfig,\n\ttype ListAccountsResponseT,\n\ttype ListedNearAccount,\n\ttype NearAccount,\n\ttype Profile,\n\ttype RelayerInfo,\n\ttype RelayedTransactionRecord,\n\ttype SubAccountConfig,\n\tLinkAccountRequest,\n\tNonceRequest,\n\tNonceResponse,\n\tProfileRequest,\n\tProfileResponse,\n\tVerifyRequest,\n\tVerifyResponse,\n\tRelayRequest,\n\tRelayResponse,\n\tRelayStatusResponse,\n\tSetPrimaryAccountRequest,\n\tViewContractRequest,\n\tViewContractResponse,\n\tGetRelayerInfoRequest,\n\tCreateSubAccountRequest,\n\tCreateSubAccountResponse,\n\tCheckSubAccountAvailabilityRequest,\n\tCheckSubAccountAvailabilityResponse,\n} from \"./types.js\";\nexport * from \"./types.js\";\nimport {\n\tbytesToHex,\n\tencryptPrivateKey,\n\tdecryptPrivateKey,\n} from \"./utils.js\";\n\nasync function hashNonce(nonce: Uint8Array): Promise<string> {\n\tconst data = new TextEncoder().encode(hex.encode(nonce));\n\tconst hashBuffer = await crypto.subtle.digest('SHA-256', data);\n\treturn hex.encode(new Uint8Array(hashBuffer));\n}\n\nfunction deriveEmail(accountId: string): string | null {\n\tif (accountId.endsWith(\".near\")) {\n\t\tconst localPart = accountId.slice(0, -5);\n\t\treturn `${localPart}@near.email`;\n\t}\n\treturn null;\n}\n\nfunction nearAccountKey(account: Pick<NearAccount, \"accountId\" | \"network\">): string {\n\treturn `${account.accountId}:${account.network}`;\n}\n\nfunction getCreatedAtTime(account: NearAccount): number {\n\treturn account.createdAt instanceof Date\n\t\t? account.createdAt.getTime()\n\t\t: new Date(account.createdAt).getTime();\n}\n\nfunction buildListAccountsResponse(nearAccounts: NearAccount[]): ListAccountsResponseT {\n\tconst activeAccount = nearAccounts.find((account) => account.isPrimary) ?? nearAccounts[0] ?? null;\n\tconst activeKey = activeAccount ? nearAccountKey(activeAccount) : null;\n\tconst accounts: ListedNearAccount[] = nearAccounts\n\t\t.map((account) => {\n\t\t\tconst isActive = activeKey === nearAccountKey(account);\n\t\t\treturn {\n\t\t\t\t...account,\n\t\t\t\tproviderId: \"siwn\" as const,\n\t\t\t\tisActive,\n\t\t\t\tisAvailable: !isActive,\n\t\t\t};\n\t\t})\n\t\t.sort((a, b) => {\n\t\t\tif (a.isActive !== b.isActive) return a.isActive ? -1 : 1;\n\t\t\treturn getCreatedAtTime(a) - getCreatedAtTime(b);\n\t\t});\n\tconst listedActiveAccount = accounts.find((account) => account.isActive) ?? null;\n\n\treturn {\n\t\taccounts,\n\t\tactiveAccount: listedActiveAccount ? { ...listedActiveAccount } : null,\n\t\tavailableAccounts: accounts\n\t\t\t.filter((account) => account.isAvailable)\n\t\t\t.map((account) => ({ ...account })),\n\t};\n}\n\nexport interface RelayerConfig {\n\taccountId?: string;\n\tprivateKey?: string;\n\tprivateKeys?: string[];\n\twhitelistedContracts?: string[];\n\tmaxGasPerTransaction?: string;\n\tmaxDepositPerTransaction?: string;\n}\n\ninterface RelayerState {\n\tnear: Near;\n\taccountId: string;\n\tnetwork: \"mainnet\" | \"testnet\";\n\tmode: \"ephemeral\" | \"explicit\";\n\tpublicKey: string;\n\tcreatedAt?: Date;\n\tlastUsedAt?: Date;\n}\n\nfunction createNear(\n\tnetwork: \"mainnet\" | \"testnet\",\n\theaders: Record<string, string>,\n\trpcUrl?: string,\n\tkeyStore?: InMemoryKeyStore | RotatingKeyStore,\n): Near {\n\tconst config: ConstructorParameters<typeof Near>[0] = { headers };\n\tif (rpcUrl) {\n\t\tconfig.network = { rpcUrl, networkId: network };\n\t} else {\n\t\tconfig.network = network;\n\t}\n\tif (keyStore) {\n\t\tconfig.keyStore = keyStore;\n\t}\n\treturn new Near(config);\n}\n\nasync function initRelayer(\n\trelayerConfig: RelayerConfig | undefined,\n\tnetwork: \"mainnet\" | \"testnet\",\n\tadapter: DBAdapter,\n\tsecret: string | undefined,\n\tapiKey?: string,\n\trpcUrl?: string,\n): Promise<RelayerState | null> {\n\tif (!relayerConfig) return null;\n\n\tconst headers: Record<string, string> = {};\n\tif (apiKey) {\n\t\theaders[\"Authorization\"] = `Bearer ${apiKey}`;\n\t}\n\n\tif (relayerConfig.accountId && (relayerConfig.privateKey || relayerConfig.privateKeys)) {\n\t\tconst keys = relayerConfig.privateKeys ?? (relayerConfig.privateKey ? [relayerConfig.privateKey] : []);\n\t\tlet keyStore: InMemoryKeyStore | RotatingKeyStore;\n\n\t\tif (keys.length === 1) {\n\t\t\tkeyStore = new InMemoryKeyStore({\n\t\t\t\t[relayerConfig.accountId]: keys[0]!,\n\t\t\t});\n\t\t} else {\n\t\t\tkeyStore = new RotatingKeyStore({\n\t\t\t\t[relayerConfig.accountId]: keys as string[],\n\t\t\t});\n\t\t}\n\n\t\tconst near = createNear(network, headers, rpcUrl, keyStore);\n\t\tconst explicitPublicKey = parseKey(keys[0]!);\n\t\treturn {\n\t\t\tnear,\n\t\t\taccountId: relayerConfig.accountId,\n\t\t\tnetwork,\n\t\t\tmode: \"explicit\",\n\t\t\tpublicKey: explicitPublicKey.publicKey.toString(),\n\t\t};\n\t}\n\n\tconst existing = await adapter.findOne<{ encryptedPrivateKey: string; iv: string; createdAt: Date; lastUsedAt: Date }>({\n\t\tmodel: \"relayerKey\",\n\t\twhere: [{ field: \"network\", operator: \"eq\", value: network }],\n\t});\n\n\tif (existing) {\n\t\tif (!secret) throw new Error(\"BETTER_AUTH_SECRET required for relayer key decryption\");\n\t\tconst privateKeyBytes = await decryptPrivateKey(existing.encryptedPrivateKey, existing.iv, secret);\n\t\tconst keyPair = parseKey(`ed25519:${base58.encode(privateKeyBytes)}`);\n\t\tconst accountId = bytesToHex(keyPair.publicKey.data);\n\n\t\tconsole.log(`[siwn] Relayer recovered: ${accountId} (${network})`);\n\n\t\tconst keyStore = new InMemoryKeyStore();\n\t\tawait keyStore.add(accountId, keyPair);\n\n\t\tconst near = createNear(network, headers, rpcUrl, keyStore);\n\t\treturn {\n\t\t\tnear,\n\t\t\taccountId,\n\t\t\tnetwork,\n\t\t\tmode: \"ephemeral\",\n\t\t\tpublicKey: keyPair.publicKey.toString(),\n\t\t\tcreatedAt: existing.createdAt,\n\t\t\tlastUsedAt: existing.lastUsedAt,\n\t\t};\n\t}\n\n\tconst keyPair = generateKey();\n\tif (!secret) throw new Error(\"BETTER_AUTH_SECRET required for relayer key encryption\");\n\tconst privateKeyBytes = keyPair.secretKey.startsWith(\"ed25519:\")\n\t\t? base58.decode(keyPair.secretKey.slice(8))\n\t\t: new Uint8Array(0);\n\n\tconst publicKeyBase58 = keyPair.publicKey.toString().replace(\"ed25519:\", \"\");\n\tconst accountId = bytesToHex(keyPair.publicKey.data);\n\tconst createdAt = new Date();\n\n\tconst { encrypted, iv } = await encryptPrivateKey(privateKeyBytes, secret);\n\n\tawait adapter.create({\n\t\t\tmodel: \"relayerKey\",\n\t\t\tdata: {\n\t\t\t\taccountId,\n\t\t\t\tencryptedPrivateKey: encrypted,\n\t\t\t\tiv,\n\t\t\t\tpublicKey: `ed25519:${publicKeyBase58}`,\n\t\t\t\tnetwork,\n\t\t\t\tcreatedAt,\n\t\t\t\tlastUsedAt: createdAt,\n\t\t\t},\n\t\t});\n\n\tconsole.log(`[siwn] Relayer created in EPHEMERAL mode: ${accountId} (${network})`);\n\tconsole.log(`[siwn] Fund this account with NEAR to enable gasless relay`);\n\tconsole.log(`[siwn] Private key is encrypted in DB — persists across restarts`);\n\n\tconst keyStore = new InMemoryKeyStore();\n\tawait keyStore.add(accountId, keyPair);\n\n\tconst near = createNear(network, headers, rpcUrl, keyStore);\n\treturn {\n\t\tnear,\n\t\taccountId,\n\t\tnetwork,\n\t\tmode: \"ephemeral\",\n\t\tpublicKey: keyPair.publicKey.toString(),\n\t\tcreatedAt,\n\t\tlastUsedAt: createdAt,\n\t};\n}\n\nasync function relayOnChain(\n\tpayload: string,\n\trelayerState: RelayerState,\n): Promise<{ txHash: string }> {\n\tconst userAction = decodeSignedDelegateAction(payload);\n\n\tconst result = await relayerState.near\n\t\t.transaction(relayerState.accountId)\n\t\t.signedDelegateAction(userAction)\n\t\t.send({ waitUntil: \"EXECUTED\" });\n\n\treturn { txHash: result.transaction.hash };\n}\n\nasync function defaultValidateLimitedAccessKey(\n\taccountId: string,\n\tpublicKey: string,\n\trecipient: string,\n\tnear: Near,\n): Promise<boolean> {\n\tconst key = await near.getAccessKey(accountId, publicKey);\n\tif (!key) return false;\n\tif (key.permission === \"FullAccess\") return true;\n\tif (\"FunctionCall\" in key.permission) {\n\t\treturn key.permission.FunctionCall.receiver_id === recipient;\n\t}\n\treturn false;\n}\n\nfunction isImplicitAccount(accountId: string): boolean {\n\treturn /^[0-9a-f]{64}$/.test(accountId);\n}\n\nfunction resolveParentAccount(\n\tsubAccountCfg: SubAccountConfig | undefined,\n\trState: RelayerState | null,\n): { parentAccount: string | null; subAccountAvailable: boolean } {\n\tif (!rState) return { parentAccount: null, subAccountAvailable: false };\n\tconst parent = subAccountCfg?.parentAccount ?? rState.accountId;\n\tif (!parent || isImplicitAccount(parent)) {\n\t\treturn { parentAccount: null, subAccountAvailable: false };\n\t}\n\treturn { parentAccount: parent, subAccountAvailable: true };\n}\n\nexport interface SIWNPluginOptions {\n\trecipient?: string;\n\trecipients?: DualNetworkConfig<string>;\n\trequireFullAccessKey?: boolean;\n\tgetNonce?: () => Promise<Uint8Array>;\n\tgetProfile?: (accountId: AccountId) => Promise<Profile | null>;\n\tvalidateLimitedAccessKey?: (args: {\n\t\taccountId: AccountId;\n\t\tpublicKey: string;\n\t\trecipient?: string;\n\t}) => Promise<boolean>;\n\tapiKey?: string;\n\trpcUrl?: string | DualNetworkConfig<string>;\n\trelayer?: RelayerConfig | DualNetworkConfig<RelayerConfig>;\n\tsubAccount?: SubAccountConfig | DualNetworkConfig<SubAccountConfig>;\n}\n\nexport const siwn = (options: SIWNPluginOptions) => {\n\tif (!options.recipient && !options.recipients) {\n\t\tthrow new Error(\"Either 'recipient' or 'recipients' must be provided to siwn plugin\");\n\t}\n\n\tconst apiKey = options.apiKey;\n\n\tconst getRecipient = (network: \"mainnet\" | \"testnet\"): string => {\n\t\tif (options.recipients) return options.recipients[network];\n\t\treturn options.recipient!;\n\t};\n\n\tconst getSupportedNetworks = (): (\"mainnet\" | \"testnet\")[] => {\n\t\tif (options.recipients) return [\"mainnet\", \"testnet\"];\n\t\tif (options.recipient) return [getNetworkFromAccountId(options.recipient)];\n\t\treturn [\"mainnet\"];\n\t};\n\n\tconst getRelayerConfig = (network: \"mainnet\" | \"testnet\"): RelayerConfig | undefined => {\n\t\tif (!options.relayer) return undefined;\n\t\tif (\"mainnet\" in options.relayer && typeof options.relayer.mainnet === \"object\") {\n\t\t\treturn (options.relayer as DualNetworkConfig<RelayerConfig>)[network];\n\t\t}\n\t\treturn options.relayer as RelayerConfig;\n\t};\n\n\tconst getRpcUrl = (network: \"mainnet\" | \"testnet\"): string | undefined => {\n\t\tif (!options.rpcUrl) return undefined;\n\t\tif (typeof options.rpcUrl === \"object\") return (options.rpcUrl as DualNetworkConfig<string>)[network];\n\t\treturn options.rpcUrl as string;\n\t};\n\n\tconst getSubAccountConfig = (network: \"mainnet\" | \"testnet\"): SubAccountConfig | undefined => {\n\t\tif (!options.subAccount) return undefined;\n\t\tif (\"mainnet\" in options.subAccount && typeof options.subAccount.mainnet === \"object\") {\n\t\t\treturn (options.subAccount as DualNetworkConfig<SubAccountConfig>)[network];\n\t\t}\n\t\treturn options.subAccount as SubAccountConfig;\n\t};\n\n\tconst primaryNetwork = getSupportedNetworks()[0];\n\tconst relayerStates = new Map<\"mainnet\" | \"testnet\", RelayerState | null>();\n\tconst relayerInitPromises = new Map<\"mainnet\" | \"testnet\", Promise<RelayerState | null>>();\n\n\tconst headers: Record<string, string> = {};\n\tif (apiKey) {\n\t\theaders[\"Authorization\"] = `Bearer ${apiKey}`;\n\t}\n\n\tconst ensureRelayer = async (adapter: DBAdapter, secret: string | undefined, network: \"mainnet\" | \"testnet\") => {\n\t\tif (relayerStates.has(network)) return relayerStates.get(network) ?? null;\n\n\t\tconst existingInit = relayerInitPromises.get(network);\n\t\tif (existingInit) return existingInit;\n\n\t\tconst relayerCfg = getRelayerConfig(network);\n\t\tconst networkRpcUrl = getRpcUrl(network);\n\n\t\tconst initPromise = initRelayer(relayerCfg, network, adapter, secret, apiKey, networkRpcUrl)\n\t\t\t.then((state) => {\n\t\t\t\trelayerStates.set(network, state);\n\t\t\t\trelayerInitPromises.delete(network);\n\t\t\t\treturn state;\n\t\t\t})\n\t\t\t.catch((error) => {\n\t\t\t\trelayerInitPromises.delete(network);\n\t\t\t\tthrow error;\n\t\t\t});\n\n\t\trelayerInitPromises.set(network, initPromise);\n\t\treturn initPromise;\n\t};\n\n\tconst getNear = (network: \"mainnet\" | \"testnet\") => {\n\t\tconst networkRpcUrl = getRpcUrl(network);\n\t\tif (networkRpcUrl) {\n\t\t\treturn new Near({ network: { rpcUrl: networkRpcUrl, networkId: network }, headers: apiKey ? { Authorization: `Bearer ${apiKey}` } : undefined });\n\t\t}\n\t\treturn new Near({ network, headers: apiKey ? { Authorization: `Bearer ${apiKey}` } : undefined });\n\t};\n\n\treturn ({\n\t\tid: \"siwn\",\n\t\tschema,\n\t\thooks: {\n\t\t\tafter: [\n\t\t\t\t{\n\t\t\t\t\tmatcher: (context: { path?: string; method?: string }) => context.path === \"/auth/session\" && context.method === \"GET\",\n\t\t\t\t\thandler: createAuthMiddleware(async (ctx) => {\n\t\t\t\t\t\tconst session = ctx.context.session;\n\t\t\t\t\t\tif (session) {\n\t\t\t\t\t\t\tconst nearAccount: NearAccount | null = await ctx.context.adapter.findOne({\n\t\t\t\t\t\t\t\tmodel: \"nearAccount\",\n\t\t\t\t\t\t\t\twhere: [\n\t\t\t\t\t\t\t\t\t{ field: \"userId\", operator: \"eq\", value: session.user.id },\n\t\t\t\t\t\t\t\t\t{ field: \"isPrimary\", operator: \"eq\", value: true },\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\tif (nearAccount) {\n\t\t\t\t\t\t\t\tctx.context.session = {\n\t\t\t\t\t\t\t\t\t...session,\n\t\t\t\t\t\t\t\t\tuser: {\n\t\t\t\t\t\t\t\t\t\t...session.user,\n\t\t\t\t\t\t\t\t\t\tnearAccount: nearAccount\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn { context: ctx };\n\t\t\t\t\t}),\n\t\t\t\t},\n\t\t\t],\n\t\t},\n\t\tendpoints: {\n\t\t\tlinkNearAccount: createAuthEndpoint(\n\t\t\t\t\"/near/link-account\",\n\t\t\t\t{\n\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\tbody: LinkAccountRequest,\n\t\t\t\t\tuse: [sessionMiddleware],\n\t\t\t\t\trequireRequest: true,\n\t\t\t\t},\n\t\t\t\tasync (ctx) => {\n\t\t\t\t\tconst { signedMessage, message, recipient, nonce, accountId } = ctx.body;\n\t\t\t\t\tconst network = getNetworkFromAccountId(accountId);\n\t\t\t\t\tconst session = ctx.context.session;\n\n\t\t\t\t\tif (!session) {\n\t\t\t\t\t\tthrow new APIError(\"UNAUTHORIZED\", {\n\t\t\t\t\t\t\tmessage: \"Must be logged in to link NEAR account\",\n\t\t\t\t\t\t\tstatus: 401,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst near = getNear(network);\n\t\t\t\t\t\tconst nonceBytes = hex.decode(nonce);\n\n\t\t\t\t\t\tconst isValid = await verifyNep413Signature(\n\t\t\t\t\t\tsignedMessage,\n\t\t\t\t\t\t{ message, recipient, nonce: nonceBytes },\n\t\t\t\t\t\t\t{ near, maxAge: 15 * 60 * 1000 },\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\tif (!isValid) {\n\t\t\t\t\t\t\tthrow new APIError(\"UNAUTHORIZED\", {\n\t\t\t\t\t\t\t\tmessage: \"Unauthorized: Invalid signature\",\n\t\t\t\t\t\t\t\tstatus: 401,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (signedMessage.accountId !== accountId) {\n\t\t\t\t\t\t\tthrow new APIError(\"UNAUTHORIZED\", {\n\t\t\t\t\t\t\t\tmessage: \"Unauthorized: Account ID mismatch\",\n\t\t\t\t\t\t\t\tstatus: 401,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst publicKey = signedMessage.publicKey;\n\n\t\t\t\t\t\tif (!options.requireFullAccessKey && options.validateLimitedAccessKey) {\n\t\t\t\t\t\t\tconst isValidKey = await options.validateLimitedAccessKey({\n\t\t\t\t\t\t\t\taccountId: accountId,\n\t\t\t\t\t\t\t\tpublicKey: publicKey,\n\t\t\t\t\t\t\t\trecipient: options.recipient\n\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\tif (!isValidKey) {\n\t\t\t\t\t\t\t\tthrow new APIError(\"UNAUTHORIZED\", {\n\t\t\t\t\t\t\t\t\tmessage: \"Unauthorized: Invalid function call access key\",\n\t\t\t\t\t\t\t\t\tstatus: 401,\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst existingNearAccount: NearAccount | null = await ctx.context.adapter.findOne({\n\t\t\t\t\t\t\tmodel: \"nearAccount\",\n\t\t\t\t\t\t\twhere: [\n\t\t\t\t\t\t\t\t{ field: \"accountId\", operator: \"eq\", value: accountId },\n\t\t\t\t\t\t\t\t{ field: \"network\", operator: \"eq\", value: network },\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tif (existingNearAccount) {\n\t\t\t\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\t\t\t\tmessage: \"This NEAR account is already linked to another user\",\n\t\t\t\t\t\t\t\tstatus: 400,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst existingPrimaryAccount: NearAccount | null = await ctx.context.adapter.findOne({\n\t\t\t\t\t\t\tmodel: \"nearAccount\",\n\t\t\t\t\t\t\twhere: [\n\t\t\t\t\t\t\t\t{ field: \"userId\", operator: \"eq\", value: session.user.id },\n\t\t\t\t\t\t\t\t{ field: \"isPrimary\", operator: \"eq\", value: true },\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tawait ctx.context.adapter.create({\n\t\t\t\t\t\t\tmodel: \"nearAccount\",\n\t\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\t\tuserId: session.user.id,\n\t\t\t\t\t\t\t\taccountId,\n\t\t\t\t\t\t\t\tnetwork,\n\t\t\t\t\t\t\t\tpublicKey: publicKey,\n\t\t\t\t\t\t\t\tisPrimary: !existingPrimaryAccount,\n\t\t\t\t\t\t\t\tcreatedAt: new Date(),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tawait ctx.context.internalAdapter.createAccount({\n\t\t\t\t\t\t\tuserId: session.user.id,\n\t\t\t\t\t\t\tproviderId: \"siwn\",\n\t\t\t\t\t\t\taccountId: `${accountId}:${network}`,\n\t\t\t\t\t\t\tcreatedAt: new Date(),\n\t\t\t\t\t\t\tupdatedAt: new Date(),\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\treturn ctx.json({\n\t\t\t\t\t\t\tsuccess: true,\n\t\t\t\t\t\t\taccountId,\n\t\t\t\t\t\t\tnetwork,\n\t\t\t\t\t\t\tmessage: \"NEAR account successfully linked\"\n\t\t\t\t\t\t});\n\t\t\t\t\t} catch (error: unknown) {\n\t\t\t\t\t\tif (error instanceof APIError) throw error;\n\t\t\t\t\t\tthrow new APIError(\"UNAUTHORIZED\", {\n\t\t\t\t\t\t\tmessage: \"Something went wrong. Please try again later.\",\n\t\t\t\t\t\t\terror: error instanceof Error ? error.message : \"Unknown error\",\n\t\t\t\t\t\t\tstatus: 401,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t),\n\t\t\tunlinkNearAccount: createAuthEndpoint(\n\t\t\t\t\"/near/unlink-account\",\n\t\t\t\t{\n\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\tbody: z.object({\n\t\t\t\t\t\taccountId: z.string(),\n\t\t\t\t\t\tnetwork: z.enum([\"mainnet\", \"testnet\"]).optional(),\n\t\t\t\t\t}),\n\t\t\t\t\tuse: [sessionMiddleware],\n\t\t\t\t},\n\t\t\t\tasync (ctx) => {\n\t\t\t\t\tconst { accountId, network: providedNetwork } = ctx.body;\n\t\t\t\t\tconst session = ctx.context.session;\n\n\t\t\t\t\tif (!session) {\n\t\t\t\t\t\tthrow new APIError(\"UNAUTHORIZED\", {\n\t\t\t\t\t\t\tmessage: \"Must be logged in to unlink NEAR account\",\n\t\t\t\t\t\t\tstatus: 401,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\tconst network = providedNetwork || getNetworkFromAccountId(accountId);\n\n\t\t\t\t\tconst nearAccount: NearAccount | null = await ctx.context.adapter.findOne({\n\t\t\t\t\t\tmodel: \"nearAccount\",\n\t\t\t\t\t\twhere: [\n\t\t\t\t\t\t\t{ field: \"userId\", operator: \"eq\", value: session.user.id },\n\t\t\t\t\t\t\t{ field: \"accountId\", operator: \"eq\", value: accountId },\n\t\t\t\t\t\t\t{ field: \"network\", operator: \"eq\", value: network },\n\t\t\t\t\t\t],\n\t\t\t\t\t});\n\n\t\t\t\t\tif (!nearAccount) {\n\t\t\t\t\t\tthrow new APIError(\"NOT_FOUND\", {\n\t\t\t\t\t\t\tmessage: \"NEAR account not found or not linked to your user\",\n\t\t\t\t\t\t\tstatus: 404,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\tconst accounts = await ctx.context.adapter.findMany({\n\t\t\t\t\t\tmodel: \"account\",\n\t\t\t\t\t\twhere: [{ field: \"userId\", operator: \"eq\", value: session.user.id }],\n\t\t\t\t\t});\n\n\t\t\t\t\tif (accounts.length <= 1) {\n\t\t\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\t\t\tmessage: \"Cannot unlink last authentication method. Link another account first.\",\n\t\t\t\t\t\t\tstatus: 400,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\tif (nearAccount.isPrimary) {\n\t\t\t\t\t\tconst otherNearAccounts: NearAccount[] = await ctx.context.adapter.findMany({\n\t\t\t\t\t\t\tmodel: \"nearAccount\",\n\t\t\t\t\t\t\twhere: [\n\t\t\t\t\t\t\t\t{ field: \"userId\", operator: \"eq\", value: session.user.id },\n\t\t\t\t\t\t\t\t{ field: \"accountId\", operator: \"ne\", value: accountId },\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tif (otherNearAccounts.length > 0) {\n\t\t\t\t\t\t\tawait ctx.context.adapter.update({\n\t\t\t\t\t\t\t\tmodel: \"nearAccount\",\n\t\t\t\t\t\t\t\twhere: [\n\t\t\t\t\t\t\t\t\t{ field: \"id\", operator: \"eq\", value: otherNearAccounts[0]!.id },\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\tupdate: { isPrimary: true },\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tawait ctx.context.adapter.delete({\n\t\t\t\t\t\tmodel: \"nearAccount\",\n\t\t\t\t\t\twhere: [\n\t\t\t\t\t\t\t{ field: \"userId\", operator: \"eq\", value: session.user.id },\n\t\t\t\t\t\t\t{ field: \"accountId\", operator: \"eq\", value: accountId },\n\t\t\t\t\t\t\t{ field: \"network\", operator: \"eq\", value: network },\n\t\t\t\t\t\t],\n\t\t\t\t\t});\n\n\t\t\t\t\tconst accountToDelete: Account | null = await ctx.context.adapter.findOne({\n\t\t\t\t\t\tmodel: \"account\",\n\t\t\t\t\t\twhere: [\n\t\t\t\t\t\t\t{ field: \"userId\", operator: \"eq\", value: session.user.id },\n\t\t\t\t\t\t\t{ field: \"providerId\", operator: \"eq\", value: \"siwn\" },\n\t\t\t\t\t\t\t{ field: \"accountId\", operator: \"eq\", value: `${accountId}:${network}` },\n\t\t\t\t\t\t],\n\t\t\t\t\t});\n\n\t\t\t\t\tif (accountToDelete) {\n\t\t\t\t\t\tawait ctx.context.internalAdapter.deleteAccount(accountToDelete.id);\n\t\t\t\t\t}\n\n\t\t\t\t\treturn ctx.json({\n\t\t\t\t\t\tsuccess: true,\n\t\t\t\t\t\taccountId,\n\t\t\t\t\t\tnetwork,\n\t\t\t\t\t\tmessage: \"NEAR account successfully unlinked\"\n\t\t\t\t\t});\n\t\t\t\t},\n\t\t\t),\n\t\t\tlistNearAccounts: createAuthEndpoint(\n\t\t\t\t\"/near/list-accounts\",\n\t\t\t\t{\n\t\t\t\t\tmethod: \"GET\",\n\t\t\t\t\tuse: [sessionMiddleware],\n\t\t\t\t},\n\t\t\t\tasync (ctx) => {\n\t\t\t\t\tconst session = ctx.context.session;\n\n\t\t\t\t\tconst nearAccounts: NearAccount[] = await ctx.context.adapter.findMany({\n\t\t\t\t\t\tmodel: \"nearAccount\",\n\t\t\t\t\t\twhere: [{ field: \"userId\", operator: \"eq\", value: session.user.id }],\n\t\t\t\t\t});\n\n\t\t\t\t\treturn ctx.json(buildListAccountsResponse(nearAccounts));\n\t\t\t\t},\n\t\t\t),\n\t\t\tsetPrimaryNearAccount: createAuthEndpoint(\n\t\t\t\t\"/near/set-primary-account\",\n\t\t\t\t{\n\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\tbody: SetPrimaryAccountRequest,\n\t\t\t\t\tuse: [sessionMiddleware],\n\t\t\t\t},\n\t\t\t\tasync (ctx) => {\n\t\t\t\t\tconst { accountId, network: providedNetwork } = ctx.body;\n\t\t\t\t\tconst session = ctx.context.session;\n\t\t\t\t\tconst network = providedNetwork || getNetworkFromAccountId(accountId);\n\n\t\t\t\t\tconst targetAccount: NearAccount | null = await ctx.context.adapter.findOne({\n\t\t\t\t\t\tmodel: \"nearAccount\",\n\t\t\t\t\t\twhere: [\n\t\t\t\t\t\t\t{ field: \"userId\", operator: \"eq\", value: session.user.id },\n\t\t\t\t\t\t\t{ field: \"accountId\", operator: \"eq\", value: accountId },\n\t\t\t\t\t\t\t{ field: \"network\", operator: \"eq\", value: network },\n\t\t\t\t\t\t],\n\t\t\t\t\t});\n\n\t\t\t\t\tif (!targetAccount) {\n\t\t\t\t\t\tthrow new APIError(\"NOT_FOUND\", {\n\t\t\t\t\t\t\tmessage: \"NEAR account not found or not linked to your user\",\n\t\t\t\t\t\t\tstatus: 404,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\tconst nearAccounts: NearAccount[] = await ctx.context.adapter.findMany({\n\t\t\t\t\t\tmodel: \"nearAccount\",\n\t\t\t\t\t\twhere: [{ field: \"userId\", operator: \"eq\", value: session.user.id }],\n\t\t\t\t\t});\n\n\t\t\t\t\tawait Promise.all(nearAccounts.map((account) => ctx.context.adapter.update({\n\t\t\t\t\t\tmodel: \"nearAccount\",\n\t\t\t\t\t\twhere: [{ field: \"id\", operator: \"eq\", value: account.id }],\n\t\t\t\t\t\tupdate: { isPrimary: nearAccountKey(account) === nearAccountKey(targetAccount) },\n\t\t\t\t\t})));\n\n\t\t\t\t\tconst updatedNearAccounts: NearAccount[] = await ctx.context.adapter.findMany({\n\t\t\t\t\t\tmodel: \"nearAccount\",\n\t\t\t\t\t\twhere: [{ field: \"userId\", operator: \"eq\", value: session.user.id }],\n\t\t\t\t\t});\n\n\t\t\t\t\treturn ctx.json({\n\t\t\t\t\t\tsuccess: true,\n\t\t\t\t\t\taccountId,\n\t\t\t\t\t\tnetwork,\n\t\t\t\t\t\tmessage: \"Primary NEAR account updated\",\n\t\t\t\t\t\t...buildListAccountsResponse(updatedNearAccounts),\n\t\t\t\t\t});\n\t\t\t\t},\n\t\t\t),\n\t\t\tgetSiwnNonce: createAuthEndpoint(\n\t\t\t\t\"/near/nonce\",\n\t\t\t\t{\n\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\tbody: NonceRequest,\n\t\t\t\t},\n\t\t\t\tasync (ctx) => {\n\t\t\t\t\tconst { accountId, networkId } = ctx.body;\n\t\t\t\t\tconst network = getNetworkFromAccountId(accountId);\n\n\t\t\t\t\tif (networkId !== network) {\n\t\t\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\t\t\tmessage: \"Network ID mismatch with account ID\",\n\t\t\t\t\t\t\tstatus: 400,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\tconst near = getNear(network);\n\t\t\t\t\tconst exists = await near.accountExists(accountId);\n\t\t\t\t\tif (!exists) {\n\t\t\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\t\t\tmessage: \"Account does not exist on-chain\",\n\t\t\t\t\t\t\tstatus: 400,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\tconst nonce = options.getNonce ? await options.getNonce() : generateNonce();\n\n\t\t\t\t\tconst nonceString = hex.encode(nonce);\n\n\t\t\t\t\tawait ctx.context.internalAdapter.createVerificationValue({\n\t\t\t\t\t\tidentifier: `siwn:${accountId}:${network}`,\n\t\t\t\t\t\tvalue: nonceString,\n\t\t\t\t\t\texpiresAt: new Date(Date.now() + 15 * 60 * 1000),\n\t\t\t\t\t});\n\n\t\t\t\t\treturn ctx.json(NonceResponse.parse({ nonce: nonceString }));\n\t\t\t\t},\n\t\t\t),\n\t\t\tgetSiwnProfile: createAuthEndpoint(\n\t\t\t\t\"/near/profile\",\n\t\t\t\t{\n\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\tbody: ProfileRequest,\n\t\t\t\t\tuse: [sessionMiddleware],\n\t\t\t\t},\n\t\t\t\tasync (ctx) => {\n\t\t\t\t\tconst { accountId } = ctx.body;\n\t\t\t\t\tlet targetAccountId = accountId;\n\n\t\t\t\t\tif (!targetAccountId) {\n\t\t\t\t\t\tconst session = ctx.context.session;\n\t\t\t\t\t\tif (!session) {\n\t\t\t\t\t\t\tthrow new APIError(\"UNAUTHORIZED\", {\n\t\t\t\t\t\t\t\tmessage: \"Session required when no accountId provided\",\n\t\t\t\t\t\t\t\tstatus: 401,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst nearAccount: NearAccount | null = await ctx.context.adapter.findOne({\n\t\t\t\t\t\t\tmodel: \"nearAccount\",\n\t\t\t\t\t\t\twhere: [\n\t\t\t\t\t\t\t\t{ field: \"userId\", operator: \"eq\", value: session.user.id },\n\t\t\t\t\t\t\t\t{ field: \"isPrimary\", operator: \"eq\", value: true },\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tif (!nearAccount) {\n\t\t\t\t\t\t\tthrow new APIError(\"NOT_FOUND\", {\n\t\t\t\t\t\t\t\tmessage: \"No NEAR account found for user\",\n\t\t\t\t\t\t\t\tstatus: 404,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\ttargetAccountId = nearAccount.accountId;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst profile = await (options.getProfile || ((id: AccountId) => defaultGetProfile(id, apiKey)))(targetAccountId);\n\t\t\t\t\treturn ctx.json(ProfileResponse.parse(profile));\n\t\t\t\t},\n\t\t\t),\n\t\t\tverifySiwnMessage: createAuthEndpoint(\n\t\t\t\t\"/near/verify\",\n\t\t\t\t{\n\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\tbody: VerifyRequest,\n\t\t\t\t\trequireRequest: true,\n\t\t\t\t},\n\t\t\t\tasync (ctx) => {\n\t\t\t\t\tconst {\n\t\t\t\t\t\tsignedMessage,\n\t\t\t\t\t\tmessage,\n\t\t\t\t\t\trecipient,\n\t\t\t\t\t\tnonce,\n\t\t\t\t\t\taccountId,\n\t\t\t\t\t} = ctx.body;\n\t\t\t\t\tconst network = getNetworkFromAccountId(accountId);\n\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst near = getNear(network);\n\t\t\t\t\t\tconst nonceBytes = hex.decode(nonce);\n\n\t\t\t\t\t\tconst isValid = await verifyNep413Signature(\n\t\t\t\t\t\tsignedMessage,\n\t\t\t\t\t\t{ message, recipient, nonce: nonceBytes },\n\t\t\t\t\t\t\t{ near, maxAge: 15 * 60 * 1000 },\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\tif (!isValid) {\n\t\t\t\t\t\t\tthrow new APIError(\"UNAUTHORIZED\", {\n\t\t\t\t\t\t\t\tmessage: \"Unauthorized: Invalid signature\",\n\t\t\t\t\t\t\t\tstatus: 401,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (signedMessage.accountId !== accountId) {\n\t\t\t\t\t\t\tthrow new APIError(\"UNAUTHORIZED\", {\n\t\t\t\t\t\t\t\tmessage: \"Unauthorized: Account ID mismatch\",\n\t\t\t\t\t\t\t\tstatus: 401,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst publicKey = signedMessage.publicKey;\n\n\t\t\t\t\t\tconst nonceHash = await hashNonce(nonceBytes);\n\n\t\t\t\t\t\tconst existingNonce = await ctx.context.internalAdapter.findVerificationValue(\n\t\t\t\t\t\t\t`siwn-nonce:${nonceHash}`\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\tif (existingNonce) {\n\t\t\t\t\t\t\tthrow new APIError(\"UNAUTHORIZED\", {\n\t\t\t\t\t\t\t\tmessage: \"Unauthorized: Nonce already used (replay attack detected)\",\n\t\t\t\t\t\t\t\tstatus: 401,\n\t\t\t\t\t\t\t\tcode: \"UNAUTHORIZED_NONCE_REPLAY\",\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tawait ctx.context.internalAdapter.createVerificationValue({\n\t\t\t\t\t\t\tidentifier: `siwn-nonce:${nonceHash}`,\n\t\t\t\t\t\t\tvalue: \"used\",\n\t\t\t\t\t\t\texpiresAt: new Date(Date.now() + 15 * 60 * 1000),\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tif (!options.requireFullAccessKey) {\n\t\t\t\t\t\t\tconst validateKey = options.validateLimitedAccessKey\n\t\t\t\t\t\t\t\t|| ((args: { accountId: string; publicKey: string; recipient?: string }) =>\n\t\t\t\t\t\t\t\t\tdefaultValidateLimitedAccessKey(args.accountId, args.publicKey, args.recipient || getRecipient(network), near));\n\n\t\t\t\t\t\t\tconst isValidKey = await validateKey({\n\t\t\t\t\t\t\t\taccountId: accountId,\n\t\t\t\t\t\t\t\tpublicKey: publicKey,\n\t\t\t\t\t\t\t\trecipient: options.recipient\n\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\tif (!isValidKey) {\n\t\t\t\t\t\t\t\tthrow new APIError(\"UNAUTHORIZED\", {\n\t\t\t\t\t\t\t\t\tmessage: \"Unauthorized: Invalid function call access key\",\n\t\t\t\t\t\t\t\t\tstatus: 401,\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tlet user: User | null = null;\n\n\t\t\t\t\t\tconst existingNearAccount: NearAccount | null =\n\t\t\t\t\t\t\tawait ctx.context.adapter.findOne({\n\t\t\t\t\t\t\t\tmodel: \"nearAccount\",\n\t\t\t\t\t\t\t\twhere: [\n\t\t\t\t\t\t\t\t\t{ field: \"accountId\", operator: \"eq\", value: accountId },\n\t\t\t\t\t\t\t\t\t{ field: \"network\", operator: \"eq\", value: network },\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\tif (existingNearAccount) {\n\t\t\t\t\t\t\tuser = await ctx.context.adapter.findOne({\n\t\t\t\t\t\t\t\tmodel: \"user\",\n\t\t\t\t\t\t\t\twhere: [\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tfield: \"id\",\n\t\t\t\t\t\t\t\t\t\toperator: \"eq\",\n\t\t\t\t\t\t\t\t\t\tvalue: existingNearAccount.userId,\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tconst anyNearAccount: NearAccount | null =\n\t\t\t\t\t\t\t\tawait ctx.context.adapter.findOne({\n\t\t\t\t\t\t\t\t\tmodel: \"nearAccount\",\n\t\t\t\t\t\t\t\t\twhere: [\n\t\t\t\t\t\t\t\t\t\t{ field: \"accountId\", operator: \"eq\", value: accountId },\n\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\tif (anyNearAccount) {\n\t\t\t\t\t\t\t\tuser = await ctx.context.adapter.findOne({\n\t\t\t\t\t\t\t\t\tmodel: \"user\",\n\t\t\t\t\t\t\t\t\twhere: [\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\tfield: \"id\",\n\t\t\t\t\t\t\t\t\t\t\toperator: \"eq\",\n\t\t\t\t\t\t\t\t\t\t\tvalue: anyNearAccount.userId,\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (!user) {\n\t\t\t\t\t\t\tconst userEmail = deriveEmail(accountId) ?? \"\";\n\n\t\t\t\t\t\t\tconst profile = await (options.getProfile || ((id: AccountId) => defaultGetProfile(id, apiKey)))(accountId);\n\n\t\t\t\t\t\t\tuser = await ctx.context.internalAdapter.createUser({\n\t\t\t\t\t\t\t\tname: profile?.name ?? accountId,\n\t\t\t\t\t\t\t\temail: userEmail,\n\t\t\t\t\t\t\t\timage: profile?.image ? getImageUrl(profile.image) : \"\",\n\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\tawait ctx.context.adapter.create({\n\t\t\t\t\t\t\t\tmodel: \"nearAccount\",\n\t\t\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\t\t\tuserId: user.id,\n\t\t\t\t\t\t\t\t\taccountId,\n\t\t\t\t\t\t\t\t\tnetwork,\n\t\t\t\t\t\t\t\t\tpublicKey: publicKey,\n\t\t\t\t\t\t\t\t\tisPrimary: true,\n\t\t\t\t\t\t\t\t\tcreatedAt: new Date(),\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\tawait ctx.context.internalAdapter.createAccount({\n\t\t\t\t\t\t\t\tuserId: user.id,\n\t\t\t\t\t\t\t\tproviderId: \"siwn\",\n\t\t\t\t\t\t\t\taccountId: `${accountId}:${network}`,\n\t\t\t\t\t\t\t\tcreatedAt: new Date(),\n\t\t\t\t\t\t\t\tupdatedAt: new Date(),\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tif (!existingNearAccount) {\n\t\t\t\t\t\t\t\tawait ctx.context.adapter.create({\n\t\t\t\t\t\t\t\t\tmodel: \"nearAccount\",\n\t\t\t\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\t\t\t\tuserId: user.id,\n\t\t\t\t\t\t\t\t\t\taccountId,\n\t\t\t\t\t\t\t\t\t\tnetwork,\n\t\t\t\t\t\t\t\t\t\tpublicKey: publicKey,\n\t\t\t\t\t\t\t\t\t\tisPrimary: false,\n\t\t\t\t\t\t\t\t\t\tcreatedAt: new Date(),\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\tawait ctx.context.internalAdapter.createAccount({\n\t\t\t\t\t\t\t\t\tuserId: user.id,\n\t\t\t\t\t\t\t\t\tproviderId: \"siwn\",\n\t\t\t\t\t\t\t\t\taccountId: `${accountId}:${network}`,\n\t\t\t\t\t\t\t\t\tcreatedAt: new Date(),\n\t\t\t\t\t\t\t\t\tupdatedAt: new Date(),\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tawait ensureRelayer(ctx.context.adapter, ctx.context.secret, network);\n\n\t\t\t\t\t\tconst session = await ctx.context.internalAdapter.createSession(\n\t\t\t\t\t\t\tuser.id\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\tif (!session) {\n\t\t\t\t\t\t\tthrow new APIError(\"INTERNAL_SERVER_ERROR\", {\n\t\t\t\t\t\t\t\tmessage: \"Internal Server Error\",\n\t\t\t\t\t\t\t\tstatus: 500,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tawait setSessionCookie(ctx, { session, user });\n\n\t\t\t\t\t\treturn ctx.json(VerifyResponse.parse({\n\t\t\t\t\t\t\ttoken: session.token,\n\t\t\t\t\t\t\tsuccess: true,\n\t\t\t\t\t\t\tuser: {\n\t\t\t\t\t\t\t\tid: user.id,\n\t\t\t\t\t\t\t\taccountId,\n\t\t\t\t\t\t\t\tnetwork,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}));\n\t\t\t\t\t} catch (error: unknown) {\n\t\t\t\t\t\tif (error instanceof APIError) throw error;\n\t\t\t\t\t\tconst msg = error instanceof Error ? error.message : \"Unknown error\";\n\t\t\t\t\t\tconst at = error instanceof Error && error.stack ? error.stack.split(\"\\n\").slice(1, 3).map(s => s.trim()).join(\" <- \") : \"\";\n\t\t\t\t\t\tconsole.error(`[siwn] Verify error: ${msg}${at ? ` (${at})` : \"\"}`);\n\t\t\t\t\t\tthrow new APIError(\"UNAUTHORIZED\", {\n\t\t\t\t\t\t\tmessage: \"Something went wrong. Please try again later.\",\n\t\t\t\t\t\t\terror: msg,\n\t\t\t\t\t\t\tstatus: 401,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t),\n\t\t\trelayNearTransaction: createAuthEndpoint(\n\t\t\t\t\"/near/relay\",\n\t\t\t\t{\n\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\tbody: RelayRequest,\n\t\t\t\t\tuse: [sessionMiddleware],\n\t\t\t\t},\n\t\t\t\tasync (ctx) => {\n\t\t\t\t\tconst { payload } = ctx.body;\n\t\t\t\t\tconst session = ctx.context.session;\n\n\t\t\t\t\tif (!session) {\n\t\t\t\t\t\tthrow new APIError(\"UNAUTHORIZED\", {\n\t\t\t\t\t\t\tmessage: \"Must be authenticated to relay transactions\",\n\t\t\t\t\t\t\tstatus: 401,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\tconst nearAccount: NearAccount | null = await ctx.context.adapter.findOne({\n\t\t\t\t\t\tmodel: \"nearAccount\",\n\t\t\t\t\t\twhere: [\n\t\t\t\t\t\t\t{ field: \"userId\", operator: \"eq\", value: session.user.id },\n\t\t\t\t\t\t\t{ field: \"isPrimary\", operator: \"eq\", value: true },\n\t\t\t\t\t\t],\n\t\t\t\t\t});\n\n\t\t\t\t\tif (!nearAccount) {\n\t\t\t\t\t\tthrow new APIError(\"UNAUTHORIZED\", {\n\t\t\t\t\t\t\tmessage: \"No NEAR account linked to session\",\n\t\t\t\t\t\t\tstatus: 401,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\tconst network = nearAccount.network as \"mainnet\" | \"testnet\";\n\t\t\t\t\tconst rState = await ensureRelayer(ctx.context.adapter, ctx.context.secret, network);\n\n\t\t\t\t\tif (!rState) {\n\t\t\t\t\t\tthrow new APIError(\"SERVICE_UNAVAILABLE\", {\n\t\t\t\t\t\t\tmessage: \"Relayer not configured\",\n\t\t\t\t\t\t\tstatus: 503,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst decoded: SignedDelegateAction = decodeSignedDelegateAction(payload);\n\t\t\t\t\t\tconst delegateAction = decoded.signedDelegate.delegateAction;\n\n\t\t\t\t\t\tif (delegateAction.senderId !== nearAccount.accountId) {\n\t\t\t\t\t\t\tthrow new APIError(\"UNAUTHORIZED\", {\n\t\t\t\t\t\t\t\tmessage: \"Delegate action sender does not match session account\",\n\t\t\t\t\t\t\t\tstatus: 401,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst relayerConfigForNetwork = getRelayerConfig(network);\n\t\t\t\t\t\tif (relayerConfigForNetwork?.whitelistedContracts?.length) {\n\t\t\t\t\t\t\tif (!relayerConfigForNetwork.whitelistedContracts.includes(delegateAction.receiverId)) {\n\t\t\t\t\t\t\t\tthrow new APIError(\"FORBIDDEN\", {\n\t\t\t\t\t\t\t\t\tmessage: `Contract ${delegateAction.receiverId} is not whitelisted for relay`,\n\t\t\t\t\t\t\t\t\tstatus: 403,\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (relayerConfigForNetwork?.maxGasPerTransaction) {\n\t\t\t\t\t\t\tconst totalGas = delegateAction.actions.reduce((sum: bigint, a) => {\n\t\t\t\t\t\t\t\treturn sum + (\"functionCall\" in a ? a.functionCall.gas : 0n);\n\t\t\t\t\t\t\t}, 0n);\n\t\t\t\t\t\t\tif (totalGas > BigInt(relayerConfigForNetwork.maxGasPerTransaction)) {\n\t\t\t\t\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\t\t\t\t\tmessage: `Transaction gas (${totalGas}) exceeds relayer limit (${relayerConfigForNetwork.maxGasPerTransaction})`,\n\t\t\t\t\t\t\t\t\tstatus: 400,\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (relayerConfigForNetwork?.maxDepositPerTransaction) {\n\t\t\t\t\t\t\tconst totalDeposit = delegateAction.actions.reduce((sum: bigint, a) => {\n\t\t\t\t\t\t\t\tif (\"functionCall\" in a) return sum + a.functionCall.deposit;\n\t\t\t\t\t\t\t\tif (\"transfer\" in a) return sum + a.transfer.deposit;\n\t\t\t\t\t\t\t\treturn sum;\n\t\t\t\t\t\t\t}, 0n);\n\t\t\t\t\t\t\tif (totalDeposit > BigInt(relayerConfigForNetwork.maxDepositPerTransaction)) {\n\t\t\t\t\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\t\t\t\t\tmessage: `Transaction deposit (${totalDeposit}) exceeds relayer limit (${relayerConfigForNetwork.maxDepositPerTransaction})`,\n\t\t\t\t\t\t\t\t\tstatus: 400,\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst result = await relayOnChain(payload, rState);\n\n\t\t\t\t\t\tawait ctx.context.adapter.create({\n\t\t\t\t\t\t\tmodel: \"relayedTransaction\",\n\t\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\t\tuserId: session.user.id,\n\t\t\t\t\t\t\t\ttxHash: result.txHash,\n\t\t\t\t\t\t\t\tsenderId: delegateAction.senderId,\n\t\t\t\t\t\t\t\treceiverId: delegateAction.receiverId,\n\t\t\t\t\t\t\t\tnetwork,\n\t\t\t\t\t\t\t\tstatus: \"pending\",\n\t\t\t\t\t\t\t\tcreatedAt: new Date(),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t});\n\n\t\t\t\t\tif (rState.mode === \"ephemeral\") {\n\t\t\t\t\t\tawait ctx.context.adapter.update({\n\t\t\t\t\t\t\tmodel: \"relayerKey\",\n\t\t\t\t\t\t\twhere: [{ field: \"network\", operator: \"eq\", value: network }],\n\t\t\t\t\t\t\tupdate: { lastUsedAt: new Date() },\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\t\treturn ctx.json(RelayResponse.parse({\n\t\t\t\t\t\t\ttxHash: result.txHash,\n\t\t\t\t\t\t\tstatus: \"pending\",\n\t\t\t\t\t\t}));\n\t\t\t\t\t} catch (error: unknown) {\n\t\t\t\t\t\tif (error instanceof APIError) throw error;\n\t\t\t\t\t\tthrow new APIError(\"INTERNAL_SERVER_ERROR\", {\n\t\t\t\t\t\t\tmessage: error instanceof Error ? error.message : \"Relay failed\",\n\t\t\t\t\t\t\tstatus: 500,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t),\n\t\t\tgetRelayStatus: createAuthEndpoint(\n\t\t\t\t\"/near/relay-status/:txHash\",\n\t\t\t\t{\n\t\t\t\t\tmethod: \"GET\",\n\t\t\t\t\tuse: [sessionMiddleware],\n\t\t\t\t},\n\t\t\t\tasync (ctx) => {\n\t\t\t\t\tconst txHash = (ctx.params as Record<string, string>)?.txHash;\n\t\t\t\t\tif (!txHash) {\n\t\t\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\t\t\tmessage: \"Transaction hash required\",\n\t\t\t\t\t\t\tstatus: 400,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\tconst session = ctx.context.session;\n\n\t\t\t\t\tconst relayedTx = await ctx.context.adapter.findOne<RelayedTransactionRecord>({\n\t\t\t\t\t\tmodel: \"relayedTransaction\",\n\t\t\t\t\t\twhere: [\n\t\t\t\t\t\t\t{ field: \"txHash\", operator: \"eq\", value: txHash },\n\t\t\t\t\t\t\t{ field: \"userId\", operator: \"eq\", value: session.user.id },\n\t\t\t\t\t\t],\n\t\t\t\t\t});\n\n\t\t\t\t\tif (!relayedTx) {\n\t\t\t\t\t\tthrow new APIError(\"NOT_FOUND\", {\n\t\t\t\t\t\t\tmessage: \"Transaction not found or not owned by this user\",\n\t\t\t\t\t\t\tstatus: 404,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\tconst network = relayedTx.network;\n\t\t\t\t\tconst senderId = relayedTx.senderId;\n\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst near = getNear(network);\n\t\t\t\t\t\tconst txResult = await near.getTransactionStatus(txHash, senderId);\n\n\t\t\t\t\t\tconst txStatus = txResult.status;\n\t\t\t\t\t\tif (txStatus && typeof txStatus === \"object\") {\n\t\t\t\t\t\t\tconst hasSuccess = \"SuccessValue\" in txStatus || \"SuccessReceiptId\" in txStatus;\n\t\t\t\t\t\t\tconst hasFailure = \"Failure\" in txStatus;\n\t\t\t\t\t\t\tconst status = hasSuccess ? \"completed\" : hasFailure ? \"failed\" : \"pending\";\n\n\t\t\t\t\t\t\tif (status !== \"pending\") {\n\t\t\t\t\t\t\t\tawait ctx.context.adapter.update({\n\t\t\t\t\t\t\t\t\tmodel: \"relayedTransaction\",\n\t\t\t\t\t\t\t\t\twhere: [{ field: \"txHash\", operator: \"eq\", value: txHash }],\n\t\t\t\t\t\t\t\t\tupdate: { status },\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tconst gasUsed = txResult.transaction_outcome?.outcome?.gas_burnt?.toString();\n\n\t\t\t\t\t\t\treturn ctx.json(RelayStatusResponse.parse({\n\t\t\t\t\t\t\t\tstatus,\n\t\t\t\t\t\t\t\tgasUsed,\n\t\t\t\t\t\t\t\toutcome: txResult,\n\t\t\t\t\t\t\t}));\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn ctx.json(RelayStatusResponse.parse({ status: \"pending\" }));\n\t\t\t\t\t} catch (error: unknown) {\n\t\t\t\t\t\treturn ctx.json(RelayStatusResponse.parse({ status: \"pending\" }));\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t),\n\t\t\tgetRelayerInfo: createAuthEndpoint(\n\t\t\t\t\"/near/relayer-info\",\n\t\t\t\t{\n\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\tbody: GetRelayerInfoRequest,\n\t\t\t\t\tuse: [sessionMiddleware],\n\t\t\t\t},\n\t\t\t\tasync (ctx) => {\n\t\t\t\t\tconst { network: requestedNetwork } = ctx.body;\n\t\t\t\t\tconst targetNetwork = (requestedNetwork ?? primaryNetwork) as \"mainnet\" | \"testnet\";\n\t\t\t\t\tconst rState = await ensureRelayer(ctx.context.adapter, ctx.context.secret, targetNetwork);\n\n\t\t\t\t\tif (!rState) {\n\t\t\t\t\t\treturn ctx.json({ enabled: false, subAccountAvailable: false } satisfies Partial<RelayerInfo> & { enabled: boolean });\n\t\t\t\t\t}\n\n\t\t\t\t\tconst subAccountCfg = getSubAccountConfig(targetNetwork);\n\t\t\t\t\tconst { parentAccount, subAccountAvailable } = resolveParentAccount(subAccountCfg, rState);\n\n\t\t\t\t\tconst near = getNear(rState.network);\n\t\t\t\t\tlet account;\n\t\t\t\t\ttry {\n\t\t\t\t\t\taccount = await near.getAccount(rState.accountId);\n\t\t\t\t\t} catch {\n\t\t\t\t\t\taccount = {\n\t\t\t\t\t\t\tbalance: \"0\",\n\t\t\t\t\t\t\tavailable: \"0\",\n\t\t\t\t\t\t\tstaked: \"0\",\n\t\t\t\t\t\t\tstorageUsage: \"0\",\n\t\t\t\t\t\t\tstorageBytes: 0,\n\t\t\t\t\t\t\thasContract: false,\n\t\t\t\t\t\t\tcodeHash: \"\",\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\n\t\t\t\t\treturn ctx.json({\n\t\t\t\t\t\tenabled: true,\n\t\t\t\t\t\taccountId: rState.accountId,\n\t\t\t\t\t\tmode: rState.mode,\n\t\t\t\t\t\tnetwork: rState.network,\n\t\t\t\t\t\tpublicKey: rState.publicKey,\n\t\t\t\t\t\tbalance: account.balance,\n\t\t\t\t\t\tavailable: account.available,\n\t\t\t\t\t\tstaked: account.staked,\n\t\t\t\t\t\tstorageUsage: account.storageUsage,\n\t\t\t\t\t\tstorageBytes: account.storageBytes,\n\t\t\t\t\t\thasContract: account.hasContract,\n\t\t\t\t\t\thasKey: true,\n\t\t\t\t\t\tcreatedAt: rState.createdAt,\n\t\t\t\t\t\tlastUsedAt: rState.lastUsedAt,\n\t\t\t\t\t\tparentAccount: parentAccount ?? undefined,\n\t\t\t\t\t\tsubAccountAvailable,\n\t\t\t\t\t});\n\t\t\t\t},\n\t\t\t),\n\t\t\tgetRelayHistory: createAuthEndpoint(\n\t\t\t\t\"/near/relay-history\",\n\t\t\t\t{\n\t\t\t\t\tmethod: \"GET\",\n\t\t\t\t\tuse: [sessionMiddleware],\n\t\t\t\t},\n\t\t\t\tasync (ctx) => {\n\t\t\t\t\tconst session = ctx.context.session;\n\n\t\t\t\t\tlet transactions: RelayedTransactionRecord[] = [];\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst result = await ctx.context.adapter.findMany<RelayedTransactionRecord>({\n\t\t\t\t\t\t\tmodel: \"relayedTransaction\",\n\t\t\t\t\t\t\twhere: [\n\t\t\t\t\t\t\t\t{ field: \"userId\", operator: \"eq\", value: session.user.id },\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t});\n\t\t\t\t\t\ttransactions = result || [];\n\t\t\t\t\t} catch (err) {\n\t\t\t\t\t\tconsole.error(\"relay-history findMany error:\", err);\n\t\t\t\t\t}\n\n\t\t\t\t\tconst sorted = transactions.sort((a, b) => {\n\t\t\t\t\t\tconst aTime = a.createdAt instanceof Date ? a.createdAt.getTime() : new Date(a.createdAt ?? 0).getTime();\n\t\t\t\t\t\tconst bTime = b.createdAt instanceof Date ? b.createdAt.getTime() : new Date(b.createdAt ?? 0).getTime();\n\t\t\t\t\t\treturn bTime - aTime;\n\t\t\t\t\t});\n\n\t\t\t\t\treturn ctx.json({\n\t\t\t\t\t\ttransactions: sorted.map((tx) => ({\n\t\t\t\t\t\t\tid: String(tx.id ?? \"\"),\n\t\t\t\t\t\t\tuserId: String(tx.userId ?? \"\"),\n\t\t\t\t\t\t\ttxHash: String(tx.txHash ?? \"\"),\n\t\t\t\t\t\t\tsenderId: String(tx.senderId ?? \"\"),\n\t\t\t\t\t\t\treceiverId: String(tx.receiverId ?? \"\"),\n\t\t\t\t\t\t\tnetwork: String(tx.network ?? \"mainnet\"),\n\t\t\t\t\t\t\tstatus: String(tx.status ?? \"pending\"),\n\t\t\t\t\t\t\tgasUsed: tx.gasUsed ? String(tx.gasUsed) : undefined,\n\t\t\t\t\t\t\tcreatedAt: tx.createdAt instanceof Date ? tx.createdAt.toISOString() : tx.createdAt ? String(tx.createdAt) : new Date().toISOString(),\n\t\t\t\t\t\t\tupdatedAt: tx.updatedAt instanceof Date ? tx.updatedAt.toISOString() : tx.updatedAt ? String(tx.updatedAt) : undefined,\n\t\t\t\t\t\t})),\n\t\t\t\t\t});\n\t\t\t\t},\n\t\t\t),\n\t\t\tviewContract: createAuthEndpoint(\n\t\t\t\t\"/near/view\",\n\t\t\t\t{\n\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\tbody: ViewContractRequest,\n\t\t\t\t\tuse: [sessionMiddleware],\n\t\t\t\t},\n\t\t\t\tasync (ctx) => {\n\t\t\t\t\tconst { contractId, methodName, args } = ctx.body;\n\t\t\t\t\tconst session = ctx.context.session;\n\t\t\t\t\tconst nearAccount: NearAccount | null = await ctx.context.adapter.findOne({\n\t\t\t\t\t\tmodel: \"nearAccount\",\n\t\t\t\t\t\twhere: [\n\t\t\t\t\t\t\t{ field: \"userId\", operator: \"eq\", value: session.user.id },\n\t\t\t\t\t\t\t{ field: \"isPrimary\", operator: \"eq\", value: true },\n\t\t\t\t\t\t],\n\t\t\t\t\t});\n\n\t\t\t\t\tconst network = (nearAccount?.network || primaryNetwork) as \"mainnet\" | \"testnet\";\n\t\t\t\t\tconst near = getNear(network);\n\t\t\t\t\tlet result: unknown;\n\t\t\t\t\ttry {\n\t\t\t\t\t\tresult = await near.view(contractId, methodName, args ?? {});\n\t\t\t\t\t} catch (error: unknown) {\n\t\t\t\t\t\tif (error instanceof APIError) throw error;\n\t\t\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\t\t\tmessage: error instanceof Error ? error.message : \"Unknown error\",\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t\treturn ctx.json(ViewContractResponse.parse({ result }));\n\t\t\t\t},\n\t\t\t),\n\t\t\tcreateSubAccount: createAuthEndpoint(\n\t\t\t\t\"/near/create-sub-account\",\n\t\t\t\t{\n\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\tbody: CreateSubAccountRequest,\n\t\t\t\t\tuse: [sessionMiddleware],\n\t\t\t\t},\n\t\t\t\tasync (ctx) => {\n\t\t\t\t\tconst { subAccountName, network: providedNetwork, publicKey } = ctx.body;\n\t\t\t\t\tconst session = ctx.context.session;\n\n\t\t\t\t\tif (!session) {\n\t\t\t\t\t\tthrow new APIError(\"UNAUTHORIZED\", {\n\t\t\t\t\t\t\tmessage: \"Must be authenticated to create a sub-account\",\n\t\t\t\t\t\t\tstatus: 401,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\tconst nearAccount: NearAccount | null = await ctx.context.adapter.findOne({\n\t\t\t\t\t\tmodel: \"nearAccount\",\n\t\t\t\t\t\twhere: [\n\t\t\t\t\t\t\t{ field: \"userId\", operator: \"eq\", value: session.user.id },\n\t\t\t\t\t\t\t{ field: \"isPrimary\", operator: \"eq\", value: true },\n\t\t\t\t\t\t],\n\t\t\t\t\t});\n\n\t\t\t\t\tconst network = (providedNetwork || nearAccount?.network || primaryNetwork) as \"mainnet\" | \"testnet\";\n\t\t\t\t\tconst subAccountCfg = getSubAccountConfig(network);\n\t\t\t\t\tconst rState = await ensureRelayer(ctx.context.adapter, ctx.context.secret, network);\n\n\t\t\t\t\tif (!rState) {\n\t\t\t\t\t\tthrow new APIError(\"SERVICE_UNAVAILABLE\", {\n\t\t\t\t\t\t\tmessage: \"Relayer not configured — sub-account creation requires a funded relayer\",\n\t\t\t\t\t\t\tstatus: 503,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\tconst { parentAccount, subAccountAvailable } = resolveParentAccount(subAccountCfg, rState);\n\n\t\t\t\t\tif (!subAccountAvailable || !parentAccount) {\n\t\t\t\t\t\tthrow new APIError(\"SERVICE_UNAVAILABLE\", {\n\t\t\t\t\t\t\tmessage: \"Sub-account creation requires a named parent account. Configure subAccount.parentAccount in your SIWN plugin options, or use an explicit relayer with a named account.\",\n\t\t\t\t\t\t\tstatus: 503,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\tif (parentAccount !== rState.accountId && !subAccountCfg?.parentKey) {\n\t\t\t\t\t\tthrow new APIError(\"SERVICE_UNAVAILABLE\", {\n\t\t\t\t\t\t\tmessage: \"Sub-account parent differs from relayer account. Configure subAccount.parentKey to enable signing as the parent account.\",\n\t\t\t\t\t\t\tstatus: 503,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\tconst newAccountId = `${subAccountName}.${parentAccount}`;\n\t\t\t\t\tconst minDeposit = subAccountCfg?.minDeposit || \"0.1 NEAR\";\n\n\t\t\t\t\tconst near = getNear(network);\n\t\t\t\t\tconst exists = await near.accountExists(newAccountId);\n\t\t\t\t\tif (exists) {\n\t\t\t\t\t\tthrow new APIError(\"CONFLICT\", {\n\t\t\t\t\t\t\tmessage: `Account ${newAccountId} already exists on ${network}`,\n\t\t\t\t\t\t\tstatus: 409,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\tlet txBuilder = rState.near\n\t\t\t\t\t\t.transaction(parentAccount)\n\t\t\t\t\t\t.createAccount(newAccountId)\n\t\t\t\t\t\t.addKey(publicKey, { type: \"fullAccess\" });\n\n\t\t\t\t\tif (subAccountCfg?.parentKey) {\n\t\t\t\t\t\ttxBuilder = txBuilder.signWith(subAccountCfg.parentKey as PrivateKey);\n\t\t\t\t\t}\n\n\t\t\t\t\tif (subAccountCfg?.addRelayerFCAK !== false && subAccountCfg?.relayerFCAK) {\n\t\t\t\t\t\tconst fcakPermission: { type: \"functionCall\"; receiverId: string; methodNames?: string[]; allowance?: string } = {\n\t\t\t\t\t\t\ttype: \"functionCall\",\n\t\t\t\t\t\t\treceiverId: subAccountCfg.relayerFCAK.receiverId,\n\t\t\t\t\t\t};\n\t\t\t\t\t\tif (subAccountCfg.relayerFCAK.methodNames) {\n\t\t\t\t\t\t\tfcakPermission.methodNames = subAccountCfg.relayerFCAK.methodNames;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (subAccountCfg.relayerFCAK.allowance) {\n\t\t\t\t\t\t\tfcakPermission.allowance = subAccountCfg.relayerFCAK.allowance as `${number} NEAR` | `${bigint} yocto`;\n\t\t\t\t\t\t}\n\t\t\t\t\t\ttxBuilder.addKey(rState.publicKey, fcakPermission as any);\n\t\t\t\t\t}\n\n\t\t\t\t\ttxBuilder.transfer(newAccountId, minDeposit as `${number} NEAR`);\n\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait txBuilder.send({ waitUntil: \"EXECUTED\" });\n\n\t\t\t\t\t\tawait ctx.context.adapter.create({\n\t\t\t\t\t\t\tmodel: \"nearAccount\",\n\t\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\t\tuserId: session.user.id,\n\t\t\t\t\t\t\t\taccountId: newAccountId,\n\t\t\t\t\t\t\t\tnetwork,\n\t\t\t\t\t\t\t\tpublicKey,\n\t\t\t\t\t\t\t\tisPrimary: false,\n\t\t\t\t\t\t\t\tcreatedAt: new Date(),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tawait ctx.context.internalAdapter.createAccount({\n\t\t\t\t\t\t\tuserId: session.user.id,\n\t\t\t\t\t\t\tproviderId: \"siwn\",\n\t\t\t\t\t\t\taccountId: `${newAccountId}:${network}`,\n\t\t\t\t\t\t\tcreatedAt: new Date(),\n\t\t\t\t\t\t\tupdatedAt: new Date(),\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\treturn ctx.json(CreateSubAccountResponse.parse({\n\t\t\t\t\t\t\tsuccess: true,\n\t\t\t\t\t\t\taccountId: newAccountId,\n\t\t\t\t\t\t\tnetwork,\n\t\t\t\t\t\t\tpublicKey,\n\t\t\t\t\t\t\tmessage: `Sub-account ${newAccountId} created on ${network}`,\n\t\t\t\t\t\t}));\n\t\t\t\t\t} catch (error: unknown) {\n\t\t\t\t\t\tconst msg = error instanceof Error ? error.message : \"Unknown error\";\n\t\t\t\t\t\tthrow new APIError(\"INTERNAL_SERVER_ERROR\", {\n\t\t\t\t\t\t\tmessage: `Failed to create sub-account: ${msg}`,\n\t\t\t\t\t\t\tstatus: 500,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t),\n\t\t\tcheckSubAccountAvailability: createAuthEndpoint(\n\t\t\t\t\"/near/check-sub-account-availability\",\n\t\t\t\t{\n\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\tbody: CheckSubAccountAvailabilityRequest,\n\t\t\t\t},\n\t\t\t\tasync (ctx) => {\n\t\t\t\t\tconst { subAccountName, network: providedNetwork } = ctx.body;\n\n\t\t\t\t\tconst network = (providedNetwork || primaryNetwork) as \"mainnet\" | \"testnet\";\n\t\t\t\t\tconst subAccountCfg = getSubAccountConfig(network);\n\t\t\t\t\tconst rState = await ensureRelayer(ctx.context.adapter, ctx.context.secret, network);\n\n\t\t\t\t\tconst { parentAccount, subAccountAvailable } = resolveParentAccount(subAccountCfg, rState);\n\n\t\t\t\t\tif (!subAccountAvailable || !parentAccount) {\n\t\t\t\t\t\tthrow new APIError(\"SERVICE_UNAVAILABLE\", {\n\t\t\t\t\t\t\tmessage: \"Sub-account creation requires a named parent account. Configure subAccount.parentAccount in your SIWN plugin options, or use an explicit relayer with a named account.\",\n\t\t\t\t\t\t\tstatus: 503,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\tconst accountId = `${subAccountName}.${parentAccount}`;\n\n\t\t\t\t\tconst near = getNear(network);\n\t\t\t\t\tconst exists = await near.accountExists(accountId);\n\n\t\t\t\t\treturn ctx.json(CheckSubAccountAvailabilityResponse.parse({\n\t\t\t\t\t\tavailable: !exists,\n\t\t\t\t\t\taccountId,\n\t\t\t\t\t}));\n\t\t\t\t},\n\t\t\t),\n\t\t},\n\t});\n};\n"],"mappings":";;;;;;;AAEA,MAAM,eACL;AAED,SAAS,wBAAwB,WAA0C;CAC1E,OAAO,UAAU,SAAS,UAAU,IAAI,YAAY;AACrD;AAEA,SAAS,YACR,OACA,UACS;CACT,IAAI,OAAO,KAAK,OAAO,MAAM;CAC7B,IAAI,OAAO,UAAU,OAAO,iCAAiC,MAAM;CACnE,OAAO,YAAY;AACpB;AAmBA,eAAe,kBAAkB,WAAsB,QAA0C;CAChG,MAAM,UAAU,wBAAwB,SAAS;CAEjD,IAAI;EACH,MAAM,QAAQ,YAAY,YACvB,iCACA;EAEH,MAAM,kBAAkB,UAAU,QAAQ,I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AK;MACrB;KACD,CAAC;KAED,MAAM,IAAI,QAAQ,gBAAgB,cAAc;MAC/C,QAAQ,QAAQ,KAAK;MACrB,YAAY;MACZ,WAAW,GAAG,aAAa,GAAG;MAC9B,2BAAW,IAAI,KAAK;MACpB,2BAAW,IAAI,KAAK;KACrB,CAAC;KAED,OAAO,IAAI,KAAK,yBAAyB,MAAM;MAC9C,SAAS;MACT,WAAW;MACX;MACA;MACA,SAAS,eAAe,aAAa,cAAc;KACpD,CAAC,CAAC;IACH,SAAS,OAAgB;KAExB,MAAM,IAAI,SAAS,yBAAyB;MAC3C,SAAS,iCAFE,iBAAiB,QAAQ,MAAM,UAAU;MAGpD,QAAQ;KACT,CAAC;IACF;GACD,CACD;GACA,6BAA6B,mBAC5B,wCACA;IACC,QAAQ;IACR,MAAM;GACP,GACA,OAAO,QAAQ;IACd,MAAM,EAAE,gBAAgB,SAAS,oBAAoB,IAAI;IAEzD,MAAM,UAAW,mBAAmB;IAIpC,MAAM,EAAE,eAAe,wBAAwB,qBAHzB,oBAAoB,OAGsC,GAAG,MAF9D,cAAc,IAAI,QAAQ,SAAS,IAAI,QAAQ,QAAQ,OAAO,CAEM;IAEzF,IAAI,CAAC,uBAAuB,CAAC,eAC5B,MAAM,IAAI,SAAS,uBAAuB;KACzC,SAAS;KACT,QAAQ;IACT,CAAC;IAGF,MAAM,YAAY,GAAG,eAAe,GAAG;IAGvC,MAAM,SAAS,MADF,QAAQ,OACG,EAAE,cAAc,SAAS;IAEjD,OAAO,IAAI,KAAK,oCAAoC,MAAM;KACzD,WAAW,CAAC;KACZ;IACD,CAAC,CAAC;GACH,CACD;EACD;CACD;AACD"}
1
+ {"version":3,"file":"index.js","names":["z"],"sources":["../src/profile.ts","../src/schema.ts","../src/types.ts","../src/utils.ts","../src/index.ts"],"sourcesContent":["import type { AccountId, Profile, SocialImage } from \"./types.js\";\n\nconst FALLBACK_URL =\n\t\"https://ipfs.near.social/ipfs/bafkreidn5fb2oygegqaldx7ycdmhu4owcrmoxd7ekbzfmeakkobz2ja7qy\";\n\nfunction getNetworkFromAccountId(accountId: string): \"mainnet\" | \"testnet\" {\n\treturn accountId.endsWith('.testnet') ? 'testnet' : 'mainnet';\n}\n\nfunction getImageUrl(\n\timage: SocialImage | undefined,\n\tfallback?: string,\n): string {\n\tif (image?.url) return image.url;\n\tif (image?.ipfs_cid) return `https://ipfs.near.social/ipfs/${image.ipfs_cid}`;\n\treturn fallback || FALLBACK_URL;\n}\n\ninterface SocialApiResponse {\n\t[accountId: string]: {\n\t\tprofile?: Profile;\n\t};\n}\n\ninterface KvEntry {\n\tvalue: Record<string, unknown> | string;\n\tblock_height?: number;\n\tblock_hash?: string;\n\ttimestamp_nanosec?: string;\n}\n\ninterface KvResponse {\n\tentries: KvEntry[];\n}\n\nasync function defaultGetProfile(accountId: AccountId, apiKey?: string): Promise<Profile | null> {\n\tconst network = getNetworkFromAccountId(accountId);\n\n\ttry {\n\t\tconst kvUrl = network === \"testnet\"\n\t\t\t? \"https://kv.test.fastnear.com\"\n\t\t\t: \"https://kv.main.fastnear.com\";\n\n\t\tconst effectiveApiKey = apiKey || process.env.FASTNEAR_API_KEY;\n\t\tconst headers: Record<string, string> = { \"Content-Type\": \"application/json\" };\n\t\tif (effectiveApiKey) {\n\t\t\theaders[\"Authorization\"] = `Bearer ${effectiveApiKey}`;\n\t\t}\n\n\t\tconst response = await fetch(\n\t\t\t`${kvUrl}/v0/latest/social.near/${accountId}/profile/**`,\n\t\t\t{ headers },\n\t\t);\n\n\t\tif (response.ok) {\n\t\t\tconst data = await response.json() as KvResponse;\n\t\t\tconst entry = data?.entries?.[0];\n\t\t\tif (entry?.value) {\n\t\t\t\ttry {\n\t\t\t\t\tconst profile = typeof entry.value === \"string\"\n\t\t\t\t\t\t? JSON.parse(entry.value)\n\t\t\t\t\t\t: entry.value;\n\t\t\t\t\tif (profile?.name || profile?.description || profile?.image) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tname: profile.name,\n\t\t\t\t\t\t\tdescription: profile.description,\n\t\t\t\t\t\t\timage: profile.image,\n\t\t\t\t\t\t\tbackgroundImage: profile.backgroundImage,\n\t\t\t\t\t\t\tlinktree: profile.linktree,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t} catch {}\n\t\t\t}\n\t\t}\n\n\t\tconst apiBase = {\n\t\t\tmainnet: \"https://api.near.social\",\n\t\t\ttestnet: \"https://test.api.near.social\",\n\t\t}[network];\n\n\t\tconst keys = [`${accountId}/profile/**`];\n\n\t\tconst fallbackResponse = await fetch(`${apiBase}/get`, {\n\t\t\tmethod: \"POST\",\n\t\t\theaders: { \"Content-Type\": \"application/json\" },\n\t\t\tbody: JSON.stringify({ keys })\n\t\t});\n\n\t\tif (!fallbackResponse.ok) {\n\t\t\tthrow new Error(`HTTP error! status: ${fallbackResponse.status}`);\n\t\t}\n\n\t\tconst fallbackData = await fallbackResponse.json() as SocialApiResponse;\n\t\tconst profile: Profile | undefined = fallbackData?.[accountId]?.profile;\n\n\t\tif (profile) {\n\t\t\treturn {\n\t\t\t\tname: profile.name,\n\t\t\t\tdescription: profile.description,\n\t\t\t\timage: profile.image,\n\t\t\t\tbackgroundImage: profile.backgroundImage,\n\t\t\t\tlinktree: profile.linktree\n\t\t\t};\n\t\t}\n\t\treturn null;\n\t} catch (error) {\n\t\treturn null;\n\t}\n}\n\nexport { defaultGetProfile, getImageUrl, getNetworkFromAccountId };\n","import type { BetterAuthPluginDBSchema } from \"better-auth/db\";\n\nexport const schema = {\n\tnearAccount: {\n\t\tfields: {\n\t\t\tuserId: {\n\t\t\t\ttype: \"string\",\n\t\t\t\treferences: {\n\t\t\t\t\tmodel: \"user\",\n\t\t\t\t\tfield: \"id\",\n\t\t\t\t},\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t\taccountId: {\n\t\t\t\ttype: \"string\",\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t\tnetwork: {\n\t\t\t\ttype: \"string\",\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t\tpublicKey: {\n\t\t\t\ttype: \"string\",\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t\tisPrimary: {\n\t\t\t\ttype: \"boolean\",\n\t\t\t\tdefaultValue: false,\n\t\t\t},\n\t\t\tcreatedAt: {\n\t\t\t\ttype: \"date\",\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t},\n\t},\n\trelayedTransaction: {\n\t\tfields: {\n\t\t\tuserId: {\n\t\t\t\ttype: \"string\",\n\t\t\t\treferences: {\n\t\t\t\t\tmodel: \"user\",\n\t\t\t\t\tfield: \"id\",\n\t\t\t\t},\n\t\t\t},\n\t\t\ttxHash: {\n\t\t\t\ttype: \"string\",\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t\tsenderId: {\n\t\t\t\ttype: \"string\",\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t\treceiverId: {\n\t\t\t\ttype: \"string\",\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t\tnetwork: {\n\t\t\t\ttype: \"string\",\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t\tstatus: {\n\t\t\t\ttype: \"string\",\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t\tgasUsed: {\n\t\t\t\ttype: \"string\",\n\t\t\t},\n\t\t\tcreatedAt: {\n\t\t\t\ttype: \"date\",\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t\tupdatedAt: {\n\t\t\t\ttype: \"date\",\n\t\t\t},\n\t\t},\n\t},\n\trelayerKey: {\n\t\tfields: {\n\t\t\taccountId: {\n\t\t\t\ttype: \"string\",\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t\tencryptedPrivateKey: {\n\t\t\t\ttype: \"string\",\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t\tiv: {\n\t\t\t\ttype: \"string\",\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t\tpublicKey: {\n\t\t\t\ttype: \"string\",\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t\tnetwork: {\n\t\t\t\ttype: \"string\",\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t\tcreatedAt: {\n\t\t\t\ttype: \"date\",\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t\tlastUsedAt: {\n\t\t\t\ttype: \"date\",\n\t\t\t},\n\t\t},\n\t},\n} satisfies BetterAuthPluginDBSchema;\n","import { z } from \"zod\";\nimport { AccountIdSchema, type AccountId } from \"near-kit/schemas\";\nimport type { AccountState } from \"near-kit\";\n\nexport type { AccountId };\n\nexport interface NearAccount {\n\tid: string;\n\tuserId: string;\n\taccountId: string;\n\tnetwork: \"mainnet\" | \"testnet\";\n\tpublicKey: string;\n\tisPrimary: boolean;\n\tcreatedAt: Date;\n}\n\nexport interface ListedNearAccount extends NearAccount {\n\tproviderId: \"siwn\";\n\tisActive: boolean;\n\tisAvailable: boolean;\n}\n\nexport interface ListAccountsResponseT {\n\taccounts: ListedNearAccount[];\n\tactiveAccount: ListedNearAccount | null;\n\tavailableAccounts: ListedNearAccount[];\n}\n\nexport interface SetPrimaryAccountResponseT extends ListAccountsResponseT {\n\tsuccess: boolean;\n\taccountId: string;\n\tnetwork: \"mainnet\" | \"testnet\";\n\tmessage: string;\n}\n\nexport const socialImageSchema = z.object({\n\turl: z.string().optional(),\n\tipfs_cid: z.string().optional(),\n});\n\nexport const profileSchema = z.object({\n\tname: z.string().optional(),\n\tdescription: z.string().optional(),\n\timage: socialImageSchema.optional(),\n\tbackgroundImage: socialImageSchema.optional(),\n\tlinktree: z.record(z.string(), z.string()).optional(),\n});\n\nexport type SocialImage = z.infer<typeof socialImageSchema>;\nexport type Profile = z.infer<typeof profileSchema>;\n\nconst signedMessageSchema = z.object({\n\taccountId: z.string(),\n\tpublicKey: z.string(),\n\tsignature: z.string(),\n\tstate: z.string().optional(),\n});\n\nexport const LinkAccountRequest = z.object({\n\tsignedMessage: signedMessageSchema,\n\tmessage: z.string(),\n\trecipient: z.string(),\n\tnonce: z.string(),\n\taccountId: AccountIdSchema,\n\tcallbackUrl: z.string().optional(),\n});\n\nexport const SetPrimaryAccountRequest = z.object({\n\taccountId: AccountIdSchema,\n\tnetwork: z.enum([\"mainnet\", \"testnet\"]).optional(),\n});\n\nexport const NonceRequest = z.object({\n\taccountId: AccountIdSchema,\n\tnetworkId: z.union([z.literal(\"mainnet\"), z.literal(\"testnet\")])\n});\n\nexport const VerifyRequest = z.object({\n\tsignedMessage: signedMessageSchema,\n\tmessage: z.string(),\n\trecipient: z.string(),\n\tnonce: z.string(),\n\taccountId: AccountIdSchema,\n\tcallbackUrl: z.string().optional(),\n});\n\nexport const RelayRequest = z.object({\n\tpayload: z.string(),\n});\nexport type RelayRequestT = z.infer<typeof RelayRequest>;\n\nexport const RelayResponse = z.object({\n\ttxHash: z.string(),\n\tstatus: z.enum([\"pending\", \"completed\", \"failed\"]),\n});\nexport type RelayResponseT = z.infer<typeof RelayResponse>;\n\nexport const RelayStatusResponse = z.object({\n\tstatus: z.enum([\"pending\", \"completed\", \"failed\"]),\n\tgasUsed: z.string().optional(),\n\toutcome: z.unknown().optional(),\n});\nexport type RelayStatusResponseT = z.infer<typeof RelayStatusResponse>;\n\nexport const ViewContractRequest = z.object({\n\tcontractId: z.string(),\n\tmethodName: z.string(),\n\targs: z.record(z.string(), z.any()).optional(),\n});\nexport type ViewContractRequestT = z.infer<typeof ViewContractRequest>;\n\nexport const NonceResponse = z.object({ nonce: z.string() });\nexport const VerifyResponse = z.object({\n\ttoken: z.string(),\n\tsuccess: z.literal(true),\n\tuser: z.object({\n\t\tid: z.string(),\n\t\taccountId: AccountIdSchema,\n\t\tnetwork: z.union([z.literal(\"mainnet\"), z.literal(\"testnet\")]),\n\t}),\n});\nexport const ProfileResponse = profileSchema.nullable();\nexport const ViewContractResponse = z.object({ result: z.unknown() });\n\nexport const ProfileRequest = z.object({\n\taccountId: AccountIdSchema.optional(),\n});\nexport type ProfileRequestT = z.infer<typeof ProfileRequest>;\n\nexport type NonceRequestT = z.infer<typeof NonceRequest>;\nexport type NonceResponseT = z.infer<typeof NonceResponse>;\nexport type SetPrimaryAccountRequestT = z.infer<typeof SetPrimaryAccountRequest>;\nexport type VerifyRequestT = z.infer<typeof VerifyRequest>;\nexport type VerifyResponseT = z.infer<typeof VerifyResponse>;\nexport type ProfileResponseT = z.infer<typeof ProfileResponse>;\nexport type ViewContractResponseT = z.infer<typeof ViewContractResponse>;\n\nexport const RelayedTransactionSchema = z.object({\n\tid: z.string(),\n\tuserId: z.string(),\n\ttxHash: z.string(),\n\tsenderId: z.string(),\n\treceiverId: z.string(),\n\tnetwork: z.string(),\n\tstatus: z.string(),\n\tgasUsed: z.string().optional(),\n\tcreatedAt: z.string(),\n\tupdatedAt: z.string().optional(),\n});\nexport type RelayedTransactionT = z.infer<typeof RelayedTransactionSchema>;\n\nexport const RelayHistoryResponse = z.object({\n\ttransactions: z.array(RelayedTransactionSchema),\n});\nexport type RelayHistoryResponseT = z.infer<typeof RelayHistoryResponse>;\n\nexport interface RelayedTransactionRecord {\n\tid: string;\n\tuserId: string;\n\ttxHash: string;\n\tsenderId: string;\n\treceiverId: string;\n\tnetwork: \"mainnet\" | \"testnet\";\n\tstatus: string;\n\tgasUsed?: string;\n\tcreatedAt: Date;\n\tupdatedAt: Date;\n}\n\nexport interface RelayerInfo extends AccountState {\n\taccountId: string;\n\tmode: \"ephemeral\" | \"explicit\";\n\tnetwork: \"mainnet\" | \"testnet\";\n\tpublicKey: string;\n\thasKey: boolean;\n\tcreatedAt?: Date;\n\tlastUsedAt?: Date;\n\tparentAccount?: string;\n\tsubAccountAvailable?: boolean;\n}\n\nexport interface DualNetworkConfig<T> {\n\tmainnet: T;\n\ttestnet: T;\n}\n\nexport const GetRelayerInfoRequest = z.object({\n\tnetwork: z.enum([\"mainnet\", \"testnet\"]).optional(),\n});\nexport type GetRelayerInfoRequestT = z.infer<typeof GetRelayerInfoRequest>;\n\nexport interface SubAccountRelayerFCAKConfig {\n\treceiverId: string;\n\tmethodNames?: string[];\n\tallowance?: string;\n}\n\nexport interface SubAccountConfig {\n\tparentAccount?: string;\n\tparentKey?: string;\n\tminDeposit?: string;\n\taddRelayerFCAK?: boolean;\n\trelayerFCAK?: SubAccountRelayerFCAKConfig;\n}\n\nexport const CreateSubAccountRequest = z.object({\n\tsubAccountName: z.string().regex(/^[a-z0-9]+$/, \"Must be lowercase alphanumeric characters only\"),\n\tnetwork: z.enum([\"mainnet\", \"testnet\"]).optional(),\n\tpublicKey: z.string(),\n});\nexport type CreateSubAccountRequestT = z.infer<typeof CreateSubAccountRequest>;\n\nexport const CreateSubAccountResponse = z.object({\n\tsuccess: z.literal(true),\n\taccountId: z.string(),\n\tnetwork: z.enum([\"mainnet\", \"testnet\"]),\n\tpublicKey: z.string(),\n\tmessage: z.string(),\n});\nexport type CreateSubAccountResponseT = z.infer<typeof CreateSubAccountResponse>;\n\nexport const CheckSubAccountAvailabilityRequest = z.object({\n\tsubAccountName: z.string().regex(/^[a-z0-9]+$/),\n\tnetwork: z.enum([\"mainnet\", \"testnet\"]).optional(),\n});\nexport type CheckSubAccountAvailabilityRequestT = z.infer<typeof CheckSubAccountAvailabilityRequest>;\n\nexport const CheckSubAccountAvailabilityResponse = z.object({\n\tavailable: z.boolean(),\n\taccountId: z.string(),\n});\nexport type CheckSubAccountAvailabilityResponseT = z.infer<typeof CheckSubAccountAvailabilityResponse>;\n","export function bytesToBase64(bytes: Uint8Array): string {\n\treturn btoa(String.fromCharCode(...bytes));\n}\n\nfunction base64ToBytes(base64: string): Uint8Array {\n\treturn Uint8Array.from(atob(base64), c => c.charCodeAt(0));\n}\n\nexport function bytesToHex(bytes: Uint8Array): string {\n\treturn Array.from(bytes).map(b => b.toString(16).padStart(2, \"0\")).join(\"\");\n}\n\nexport function hexToBytes(hex: string): Uint8Array {\n\tconst bytes = new Uint8Array(hex.length / 2);\n\tfor (let i = 0; i < hex.length; i += 2) {\n\t\tbytes[i / 2] = parseInt(hex.substring(i, i + 2), 16);\n\t}\n\treturn bytes;\n}\n\nasync function deriveAesKey(secret: string): Promise<CryptoKey> {\n\tconst keyMaterial = await crypto.subtle.importKey(\n\t\t\"raw\",\n\t\tnew TextEncoder().encode(secret),\n\t\t{ name: \"HKDF\" },\n\t\tfalse,\n\t\t[\"deriveKey\"],\n\t);\n\treturn crypto.subtle.deriveKey(\n\t\t{\n\t\t\tname: \"HKDF\",\n\t\t\thash: \"SHA-256\",\n\t\t\tsalt: new TextEncoder().encode(\"better-near-auth-relayer\"),\n\t\t\tinfo: new Uint8Array(0),\n\t\t},\n\t\tkeyMaterial,\n\t\t{ name: \"AES-GCM\", length: 256 },\n\t\tfalse,\n\t\t[\"encrypt\", \"decrypt\"],\n\t);\n}\n\nexport async function encryptPrivateKey(\n\tprivateKey: Uint8Array,\n\tsecret: string,\n): Promise<{ encrypted: string; iv: string }> {\n\tconst aesKey = await deriveAesKey(secret);\n\tconst iv = crypto.getRandomValues(new Uint8Array(12));\n\tconst encrypted = await crypto.subtle.encrypt(\n\t\t{ name: \"AES-GCM\", iv },\n\t\taesKey,\n\t\tprivateKey as Uint8Array<ArrayBuffer>,\n\t);\n\treturn {\n\t\tencrypted: bytesToBase64(new Uint8Array(encrypted)),\n\t\tiv: bytesToBase64(iv),\n\t};\n}\n\nexport async function decryptPrivateKey(\n\tencrypted: string,\n\tiv: string,\n\tsecret: string,\n): Promise<Uint8Array> {\n\tconst aesKey = await deriveAesKey(secret);\n\tconst decrypted = await crypto.subtle.decrypt(\n\t\t{ name: \"AES-GCM\", iv: base64ToBytes(iv) as Uint8Array<ArrayBuffer> },\n\t\taesKey,\n\t\tbase64ToBytes(encrypted) as Uint8Array<ArrayBuffer>,\n\t);\n\treturn new Uint8Array(decrypted);\n}\n","import { APIError, createAuthEndpoint, createAuthMiddleware, sessionMiddleware } from \"better-auth/api\";\nimport { setSessionCookie } from \"better-auth/cookies\";\nimport type { Account, User, DBAdapter } from \"better-auth/types\";\n// Explicit type imports for declaration emit\nimport type {} from \"@better-auth/core/env\";\nimport type {} from \"@better-auth/core/oauth2\";\nimport type {} from \"better-call\";\n\nimport { Near, generateNonce, generateKey, parseKey, verifyNep413Signature, decodeSignedDelegateAction, InMemoryKeyStore, RotatingKeyStore } from \"near-kit\";\nimport type { SignedDelegateAction, PrivateKey } from \"near-kit\";\nimport { hex, base58 } from \"@scure/base\";\nimport z from \"zod\";\nimport { defaultGetProfile, getImageUrl, getNetworkFromAccountId } from \"./profile.js\";\nimport { schema } from \"./schema.js\";\nimport {\n\ttype AccountId,\n\ttype DualNetworkConfig,\n\ttype ListAccountsResponseT,\n\ttype ListedNearAccount,\n\ttype NearAccount,\n\ttype Profile,\n\ttype RelayerInfo,\n\ttype RelayedTransactionRecord,\n\ttype SubAccountConfig,\n\tLinkAccountRequest,\n\tNonceRequest,\n\tNonceResponse,\n\tProfileRequest,\n\tProfileResponse,\n\tVerifyRequest,\n\tVerifyResponse,\n\tRelayRequest,\n\tRelayResponse,\n\tRelayStatusResponse,\n\tSetPrimaryAccountRequest,\n\tViewContractRequest,\n\tViewContractResponse,\n\tGetRelayerInfoRequest,\n\tCreateSubAccountRequest,\n\tCreateSubAccountResponse,\n\tCheckSubAccountAvailabilityRequest,\n\tCheckSubAccountAvailabilityResponse,\n} from \"./types.js\";\nexport * from \"./types.js\";\nimport {\n\tbytesToHex,\n\tencryptPrivateKey,\n\tdecryptPrivateKey,\n} from \"./utils.js\";\n\nasync function hashNonce(nonce: Uint8Array): Promise<string> {\n\tconst data = new TextEncoder().encode(hex.encode(nonce));\n\tconst hashBuffer = await crypto.subtle.digest('SHA-256', data);\n\treturn hex.encode(new Uint8Array(hashBuffer));\n}\n\nfunction deriveEmail(accountId: string, recipient: string): string {\n\tif (accountId.endsWith(\".near\")) {\n\t\tconst localPart = accountId.slice(0, -5);\n\t\tif (!localPart.includes(\".\")) {\n\t\t\treturn `${localPart}@near.email`;\n\t\t}\n\t}\n\tconst randomId = crypto.randomUUID().slice(0, 8);\n\treturn `temp-${randomId}@${recipient}`;\n}\n\nfunction nearAccountKey(account: Pick<NearAccount, \"accountId\" | \"network\">): string {\n\treturn `${account.accountId}:${account.network}`;\n}\n\nfunction getCreatedAtTime(account: NearAccount): number {\n\treturn account.createdAt instanceof Date\n\t\t? account.createdAt.getTime()\n\t\t: new Date(account.createdAt).getTime();\n}\n\nfunction buildListAccountsResponse(nearAccounts: NearAccount[]): ListAccountsResponseT {\n\tconst activeAccount = nearAccounts.find((account) => account.isPrimary) ?? nearAccounts[0] ?? null;\n\tconst activeKey = activeAccount ? nearAccountKey(activeAccount) : null;\n\tconst accounts: ListedNearAccount[] = nearAccounts\n\t\t.map((account) => {\n\t\t\tconst isActive = activeKey === nearAccountKey(account);\n\t\t\treturn {\n\t\t\t\t...account,\n\t\t\t\tproviderId: \"siwn\" as const,\n\t\t\t\tisActive,\n\t\t\t\tisAvailable: !isActive,\n\t\t\t};\n\t\t})\n\t\t.sort((a, b) => {\n\t\t\tif (a.isActive !== b.isActive) return a.isActive ? -1 : 1;\n\t\t\treturn getCreatedAtTime(a) - getCreatedAtTime(b);\n\t\t});\n\tconst listedActiveAccount = accounts.find((account) => account.isActive) ?? null;\n\n\treturn {\n\t\taccounts,\n\t\tactiveAccount: listedActiveAccount ? { ...listedActiveAccount } : null,\n\t\tavailableAccounts: accounts\n\t\t\t.filter((account) => account.isAvailable)\n\t\t\t.map((account) => ({ ...account })),\n\t};\n}\n\nexport interface RelayerConfig {\n\taccountId?: string;\n\tprivateKey?: string;\n\tprivateKeys?: string[];\n\twhitelistedContracts?: string[];\n\tmaxGasPerTransaction?: string;\n\tmaxDepositPerTransaction?: string;\n}\n\ninterface RelayerState {\n\tnear: Near;\n\taccountId: string;\n\tnetwork: \"mainnet\" | \"testnet\";\n\tmode: \"ephemeral\" | \"explicit\";\n\tpublicKey: string;\n\tcreatedAt?: Date;\n\tlastUsedAt?: Date;\n}\n\nfunction createNear(\n\tnetwork: \"mainnet\" | \"testnet\",\n\theaders: Record<string, string>,\n\trpcUrl?: string,\n\tkeyStore?: InMemoryKeyStore | RotatingKeyStore,\n): Near {\n\tconst config: ConstructorParameters<typeof Near>[0] = { headers };\n\tif (rpcUrl) {\n\t\tconfig.network = { rpcUrl, networkId: network };\n\t} else {\n\t\tconfig.network = network;\n\t}\n\tif (keyStore) {\n\t\tconfig.keyStore = keyStore;\n\t}\n\treturn new Near(config);\n}\n\nasync function initRelayer(\n\trelayerConfig: RelayerConfig | undefined,\n\tnetwork: \"mainnet\" | \"testnet\",\n\tadapter: DBAdapter,\n\tsecret: string | undefined,\n\tapiKey?: string,\n\trpcUrl?: string,\n): Promise<RelayerState | null> {\n\tif (!relayerConfig) return null;\n\n\tconst headers: Record<string, string> = {};\n\tif (apiKey) {\n\t\theaders[\"Authorization\"] = `Bearer ${apiKey}`;\n\t}\n\n\tif (relayerConfig.accountId && (relayerConfig.privateKey || relayerConfig.privateKeys)) {\n\t\tconst keys = relayerConfig.privateKeys ?? (relayerConfig.privateKey ? [relayerConfig.privateKey] : []);\n\t\tlet keyStore: InMemoryKeyStore | RotatingKeyStore;\n\n\t\tif (keys.length === 1) {\n\t\t\tkeyStore = new InMemoryKeyStore({\n\t\t\t\t[relayerConfig.accountId]: keys[0]!,\n\t\t\t});\n\t\t} else {\n\t\t\tkeyStore = new RotatingKeyStore({\n\t\t\t\t[relayerConfig.accountId]: keys as string[],\n\t\t\t});\n\t\t}\n\n\t\tconst near = createNear(network, headers, rpcUrl, keyStore);\n\t\tconst explicitPublicKey = parseKey(keys[0]!);\n\t\treturn {\n\t\t\tnear,\n\t\t\taccountId: relayerConfig.accountId,\n\t\t\tnetwork,\n\t\t\tmode: \"explicit\",\n\t\t\tpublicKey: explicitPublicKey.publicKey.toString(),\n\t\t};\n\t}\n\n\tconst existing = await adapter.findOne<{ encryptedPrivateKey: string; iv: string; createdAt: Date; lastUsedAt: Date }>({\n\t\tmodel: \"relayerKey\",\n\t\twhere: [{ field: \"network\", operator: \"eq\", value: network }],\n\t});\n\n\tif (existing) {\n\t\tif (!secret) throw new Error(\"BETTER_AUTH_SECRET required for relayer key decryption\");\n\t\tconst privateKeyBytes = await decryptPrivateKey(existing.encryptedPrivateKey, existing.iv, secret);\n\t\tconst keyPair = parseKey(`ed25519:${base58.encode(privateKeyBytes)}`);\n\t\tconst accountId = bytesToHex(keyPair.publicKey.data);\n\n\t\tconsole.log(`[siwn] Relayer recovered: ${accountId} (${network})`);\n\n\t\tconst keyStore = new InMemoryKeyStore();\n\t\tawait keyStore.add(accountId, keyPair);\n\n\t\tconst near = createNear(network, headers, rpcUrl, keyStore);\n\t\treturn {\n\t\t\tnear,\n\t\t\taccountId,\n\t\t\tnetwork,\n\t\t\tmode: \"ephemeral\",\n\t\t\tpublicKey: keyPair.publicKey.toString(),\n\t\t\tcreatedAt: existing.createdAt,\n\t\t\tlastUsedAt: existing.lastUsedAt,\n\t\t};\n\t}\n\n\tconst keyPair = generateKey();\n\tif (!secret) throw new Error(\"BETTER_AUTH_SECRET required for relayer key encryption\");\n\tconst privateKeyBytes = keyPair.secretKey.startsWith(\"ed25519:\")\n\t\t? base58.decode(keyPair.secretKey.slice(8))\n\t\t: new Uint8Array(0);\n\n\tconst publicKeyBase58 = keyPair.publicKey.toString().replace(\"ed25519:\", \"\");\n\tconst accountId = bytesToHex(keyPair.publicKey.data);\n\tconst createdAt = new Date();\n\n\tconst { encrypted, iv } = await encryptPrivateKey(privateKeyBytes, secret);\n\n\tawait adapter.create({\n\t\t\tmodel: \"relayerKey\",\n\t\t\tdata: {\n\t\t\t\taccountId,\n\t\t\t\tencryptedPrivateKey: encrypted,\n\t\t\t\tiv,\n\t\t\t\tpublicKey: `ed25519:${publicKeyBase58}`,\n\t\t\t\tnetwork,\n\t\t\t\tcreatedAt,\n\t\t\t\tlastUsedAt: createdAt,\n\t\t\t},\n\t\t});\n\n\tconsole.log(`[siwn] Relayer created in EPHEMERAL mode: ${accountId} (${network})`);\n\tconsole.log(`[siwn] Fund this account with NEAR to enable gasless relay`);\n\tconsole.log(`[siwn] Private key is encrypted in DB — persists across restarts`);\n\n\tconst keyStore = new InMemoryKeyStore();\n\tawait keyStore.add(accountId, keyPair);\n\n\tconst near = createNear(network, headers, rpcUrl, keyStore);\n\treturn {\n\t\tnear,\n\t\taccountId,\n\t\tnetwork,\n\t\tmode: \"ephemeral\",\n\t\tpublicKey: keyPair.publicKey.toString(),\n\t\tcreatedAt,\n\t\tlastUsedAt: createdAt,\n\t};\n}\n\nasync function relayOnChain(\n\tpayload: string,\n\trelayerState: RelayerState,\n): Promise<{ txHash: string }> {\n\tconst userAction = decodeSignedDelegateAction(payload);\n\n\tconst result = await relayerState.near\n\t\t.transaction(relayerState.accountId)\n\t\t.signedDelegateAction(userAction)\n\t\t.send({ waitUntil: \"EXECUTED\" });\n\n\treturn { txHash: result.transaction.hash };\n}\n\nasync function defaultValidateLimitedAccessKey(\n\taccountId: string,\n\tpublicKey: string,\n\trecipient: string,\n\tnear: Near,\n): Promise<boolean> {\n\tconst key = await near.getAccessKey(accountId, publicKey);\n\tif (!key) return false;\n\tif (key.permission === \"FullAccess\") return true;\n\tif (\"FunctionCall\" in key.permission) {\n\t\treturn key.permission.FunctionCall.receiver_id === recipient;\n\t}\n\treturn false;\n}\n\nfunction isImplicitAccount(accountId: string): boolean {\n\treturn /^[0-9a-f]{64}$/.test(accountId);\n}\n\nfunction resolveParentAccount(\n\tsubAccountCfg: SubAccountConfig | undefined,\n\trState: RelayerState | null,\n): { parentAccount: string | null; subAccountAvailable: boolean } {\n\tif (!rState) return { parentAccount: null, subAccountAvailable: false };\n\tconst parent = subAccountCfg?.parentAccount ?? rState.accountId;\n\tif (!parent || isImplicitAccount(parent)) {\n\t\treturn { parentAccount: null, subAccountAvailable: false };\n\t}\n\treturn { parentAccount: parent, subAccountAvailable: true };\n}\n\nexport interface SIWNPluginOptions {\n\trecipient?: string;\n\trecipients?: DualNetworkConfig<string>;\n\trequireFullAccessKey?: boolean;\n\tgetNonce?: () => Promise<Uint8Array>;\n\tgetProfile?: (accountId: AccountId) => Promise<Profile | null>;\n\tvalidateLimitedAccessKey?: (args: {\n\t\taccountId: AccountId;\n\t\tpublicKey: string;\n\t\trecipient?: string;\n\t}) => Promise<boolean>;\n\tapiKey?: string;\n\trpcUrl?: string | DualNetworkConfig<string>;\n\trelayer?: RelayerConfig | DualNetworkConfig<RelayerConfig>;\n\tsubAccount?: SubAccountConfig | DualNetworkConfig<SubAccountConfig>;\n}\n\nexport const siwn = (options: SIWNPluginOptions) => {\n\tif (!options.recipient && !options.recipients) {\n\t\tthrow new Error(\"Either 'recipient' or 'recipients' must be provided to siwn plugin\");\n\t}\n\n\tconst apiKey = options.apiKey;\n\n\tconst getRecipient = (network: \"mainnet\" | \"testnet\"): string => {\n\t\tif (options.recipients) return options.recipients[network];\n\t\treturn options.recipient!;\n\t};\n\n\tconst getSupportedNetworks = (): (\"mainnet\" | \"testnet\")[] => {\n\t\tif (options.recipients) return [\"mainnet\", \"testnet\"];\n\t\tif (options.recipient) return [getNetworkFromAccountId(options.recipient)];\n\t\treturn [\"mainnet\"];\n\t};\n\n\tconst getRelayerConfig = (network: \"mainnet\" | \"testnet\"): RelayerConfig | undefined => {\n\t\tif (!options.relayer) return undefined;\n\t\tif (\"mainnet\" in options.relayer && typeof options.relayer.mainnet === \"object\") {\n\t\t\treturn (options.relayer as DualNetworkConfig<RelayerConfig>)[network];\n\t\t}\n\t\treturn options.relayer as RelayerConfig;\n\t};\n\n\tconst getRpcUrl = (network: \"mainnet\" | \"testnet\"): string | undefined => {\n\t\tif (!options.rpcUrl) return undefined;\n\t\tif (typeof options.rpcUrl === \"object\") return (options.rpcUrl as DualNetworkConfig<string>)[network];\n\t\treturn options.rpcUrl as string;\n\t};\n\n\tconst getSubAccountConfig = (network: \"mainnet\" | \"testnet\"): SubAccountConfig | undefined => {\n\t\tif (!options.subAccount) return undefined;\n\t\tif (\"mainnet\" in options.subAccount && typeof options.subAccount.mainnet === \"object\") {\n\t\t\treturn (options.subAccount as DualNetworkConfig<SubAccountConfig>)[network];\n\t\t}\n\t\treturn options.subAccount as SubAccountConfig;\n\t};\n\n\tconst primaryNetwork = getSupportedNetworks()[0];\n\tconst relayerStates = new Map<\"mainnet\" | \"testnet\", RelayerState | null>();\n\tconst relayerInitPromises = new Map<\"mainnet\" | \"testnet\", Promise<RelayerState | null>>();\n\n\tconst headers: Record<string, string> = {};\n\tif (apiKey) {\n\t\theaders[\"Authorization\"] = `Bearer ${apiKey}`;\n\t}\n\n\tconst ensureRelayer = async (adapter: DBAdapter, secret: string | undefined, network: \"mainnet\" | \"testnet\") => {\n\t\tif (relayerStates.has(network)) return relayerStates.get(network) ?? null;\n\n\t\tconst existingInit = relayerInitPromises.get(network);\n\t\tif (existingInit) return existingInit;\n\n\t\tconst relayerCfg = getRelayerConfig(network);\n\t\tconst networkRpcUrl = getRpcUrl(network);\n\n\t\tconst initPromise = initRelayer(relayerCfg, network, adapter, secret, apiKey, networkRpcUrl)\n\t\t\t.then((state) => {\n\t\t\t\trelayerStates.set(network, state);\n\t\t\t\trelayerInitPromises.delete(network);\n\t\t\t\treturn state;\n\t\t\t})\n\t\t\t.catch((error) => {\n\t\t\t\trelayerInitPromises.delete(network);\n\t\t\t\tthrow error;\n\t\t\t});\n\n\t\trelayerInitPromises.set(network, initPromise);\n\t\treturn initPromise;\n\t};\n\n\tconst getNear = (network: \"mainnet\" | \"testnet\") => {\n\t\tconst networkRpcUrl = getRpcUrl(network);\n\t\tif (networkRpcUrl) {\n\t\t\treturn new Near({ network: { rpcUrl: networkRpcUrl, networkId: network }, headers: apiKey ? { Authorization: `Bearer ${apiKey}` } : undefined });\n\t\t}\n\t\treturn new Near({ network, headers: apiKey ? { Authorization: `Bearer ${apiKey}` } : undefined });\n\t};\n\n\treturn ({\n\t\tid: \"siwn\",\n\t\tschema,\n\t\thooks: {\n\t\t\tafter: [\n\t\t\t\t{\n\t\t\t\t\tmatcher: (context: { path?: string; method?: string }) => context.path === \"/auth/session\" && context.method === \"GET\",\n\t\t\t\t\thandler: createAuthMiddleware(async (ctx) => {\n\t\t\t\t\t\tconst session = ctx.context.session;\n\t\t\t\t\t\tif (session) {\n\t\t\t\t\t\t\tconst nearAccount: NearAccount | null = await ctx.context.adapter.findOne({\n\t\t\t\t\t\t\t\tmodel: \"nearAccount\",\n\t\t\t\t\t\t\t\twhere: [\n\t\t\t\t\t\t\t\t\t{ field: \"userId\", operator: \"eq\", value: session.user.id },\n\t\t\t\t\t\t\t\t\t{ field: \"isPrimary\", operator: \"eq\", value: true },\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\tif (nearAccount) {\n\t\t\t\t\t\t\t\tctx.context.session = {\n\t\t\t\t\t\t\t\t\t...session,\n\t\t\t\t\t\t\t\t\tuser: {\n\t\t\t\t\t\t\t\t\t\t...session.user,\n\t\t\t\t\t\t\t\t\t\tnearAccount: nearAccount\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn { context: ctx };\n\t\t\t\t\t}),\n\t\t\t\t},\n\t\t\t],\n\t\t},\n\t\tendpoints: {\n\t\t\tlinkNearAccount: createAuthEndpoint(\n\t\t\t\t\"/near/link-account\",\n\t\t\t\t{\n\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\tbody: LinkAccountRequest,\n\t\t\t\t\tuse: [sessionMiddleware],\n\t\t\t\t\trequireRequest: true,\n\t\t\t\t},\n\t\t\t\tasync (ctx) => {\n\t\t\t\t\tconst { signedMessage, message, recipient, nonce, accountId, callbackUrl } = ctx.body;\n\t\t\t\t\tconst network = getNetworkFromAccountId(accountId);\n\t\t\t\t\tconst session = ctx.context.session;\n\n\t\t\t\t\tif (!session) {\n\t\t\t\t\t\tthrow new APIError(\"UNAUTHORIZED\", {\n\t\t\t\t\t\t\tmessage: \"Must be logged in to link NEAR account\",\n\t\t\t\t\t\t\tstatus: 401,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst near = getNear(network);\n\t\t\t\t\t\tconst nonceBytes = hex.decode(nonce);\n\n\t\t\t\t\t\tconst isValid = await verifyNep413Signature(\n\t\t\t\t\t\tsignedMessage,\n\t\t\t\t\t\t{ message, recipient, nonce: nonceBytes, callbackUrl },\n\t\t\t\t\t\t\t{ near, maxAge: 15 * 60 * 1000 },\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\tif (!isValid) {\n\t\t\t\t\t\t\tthrow new APIError(\"UNAUTHORIZED\", {\n\t\t\t\t\t\t\t\tmessage: \"Unauthorized: Invalid signature\",\n\t\t\t\t\t\t\t\tstatus: 401,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (signedMessage.accountId !== accountId) {\n\t\t\t\t\t\t\tthrow new APIError(\"UNAUTHORIZED\", {\n\t\t\t\t\t\t\t\tmessage: \"Unauthorized: Account ID mismatch\",\n\t\t\t\t\t\t\t\tstatus: 401,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst publicKey = signedMessage.publicKey;\n\n\t\t\t\t\t\tif (!options.requireFullAccessKey && options.validateLimitedAccessKey) {\n\t\t\t\t\t\t\tconst isValidKey = await options.validateLimitedAccessKey({\n\t\t\t\t\t\t\t\taccountId: accountId,\n\t\t\t\t\t\t\t\tpublicKey: publicKey,\n\t\t\t\t\t\t\t\trecipient: options.recipient\n\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\tif (!isValidKey) {\n\t\t\t\t\t\t\t\tthrow new APIError(\"UNAUTHORIZED\", {\n\t\t\t\t\t\t\t\t\tmessage: \"Unauthorized: Invalid function call access key\",\n\t\t\t\t\t\t\t\t\tstatus: 401,\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst existingNearAccount: NearAccount | null = await ctx.context.adapter.findOne({\n\t\t\t\t\t\t\tmodel: \"nearAccount\",\n\t\t\t\t\t\t\twhere: [\n\t\t\t\t\t\t\t\t{ field: \"accountId\", operator: \"eq\", value: accountId },\n\t\t\t\t\t\t\t\t{ field: \"network\", operator: \"eq\", value: network },\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tif (existingNearAccount) {\n\t\t\t\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\t\t\t\tmessage: \"This NEAR account is already linked to another user\",\n\t\t\t\t\t\t\t\tstatus: 400,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst existingPrimaryAccount: NearAccount | null = await ctx.context.adapter.findOne({\n\t\t\t\t\t\t\tmodel: \"nearAccount\",\n\t\t\t\t\t\t\twhere: [\n\t\t\t\t\t\t\t\t{ field: \"userId\", operator: \"eq\", value: session.user.id },\n\t\t\t\t\t\t\t\t{ field: \"isPrimary\", operator: \"eq\", value: true },\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tawait ctx.context.adapter.create({\n\t\t\t\t\t\t\tmodel: \"nearAccount\",\n\t\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\t\tuserId: session.user.id,\n\t\t\t\t\t\t\t\taccountId,\n\t\t\t\t\t\t\t\tnetwork,\n\t\t\t\t\t\t\t\tpublicKey: publicKey,\n\t\t\t\t\t\t\t\tisPrimary: !existingPrimaryAccount,\n\t\t\t\t\t\t\t\tcreatedAt: new Date(),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tawait ctx.context.internalAdapter.createAccount({\n\t\t\t\t\t\t\tuserId: session.user.id,\n\t\t\t\t\t\t\tproviderId: \"siwn\",\n\t\t\t\t\t\t\taccountId: `${accountId}:${network}`,\n\t\t\t\t\t\t\tcreatedAt: new Date(),\n\t\t\t\t\t\t\tupdatedAt: new Date(),\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\treturn ctx.json({\n\t\t\t\t\t\t\tsuccess: true,\n\t\t\t\t\t\t\taccountId,\n\t\t\t\t\t\t\tnetwork,\n\t\t\t\t\t\t\tmessage: \"NEAR account successfully linked\"\n\t\t\t\t\t\t});\n\t\t\t\t\t} catch (error: unknown) {\n\t\t\t\t\t\tif (error instanceof APIError) throw error;\n\t\t\t\t\t\tthrow new APIError(\"UNAUTHORIZED\", {\n\t\t\t\t\t\t\tmessage: \"Something went wrong. Please try again later.\",\n\t\t\t\t\t\t\terror: error instanceof Error ? error.message : \"Unknown error\",\n\t\t\t\t\t\t\tstatus: 401,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t),\n\t\t\tunlinkNearAccount: createAuthEndpoint(\n\t\t\t\t\"/near/unlink-account\",\n\t\t\t\t{\n\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\tbody: z.object({\n\t\t\t\t\t\taccountId: z.string(),\n\t\t\t\t\t\tnetwork: z.enum([\"mainnet\", \"testnet\"]).optional(),\n\t\t\t\t\t}),\n\t\t\t\t\tuse: [sessionMiddleware],\n\t\t\t\t},\n\t\t\t\tasync (ctx) => {\n\t\t\t\t\tconst { accountId, network: providedNetwork } = ctx.body;\n\t\t\t\t\tconst session = ctx.context.session;\n\n\t\t\t\t\tif (!session) {\n\t\t\t\t\t\tthrow new APIError(\"UNAUTHORIZED\", {\n\t\t\t\t\t\t\tmessage: \"Must be logged in to unlink NEAR account\",\n\t\t\t\t\t\t\tstatus: 401,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\tconst network = providedNetwork || getNetworkFromAccountId(accountId);\n\n\t\t\t\t\tconst nearAccount: NearAccount | null = await ctx.context.adapter.findOne({\n\t\t\t\t\t\tmodel: \"nearAccount\",\n\t\t\t\t\t\twhere: [\n\t\t\t\t\t\t\t{ field: \"userId\", operator: \"eq\", value: session.user.id },\n\t\t\t\t\t\t\t{ field: \"accountId\", operator: \"eq\", value: accountId },\n\t\t\t\t\t\t\t{ field: \"network\", operator: \"eq\", value: network },\n\t\t\t\t\t\t],\n\t\t\t\t\t});\n\n\t\t\t\t\tif (!nearAccount) {\n\t\t\t\t\t\tthrow new APIError(\"NOT_FOUND\", {\n\t\t\t\t\t\t\tmessage: \"NEAR account not found or not linked to your user\",\n\t\t\t\t\t\t\tstatus: 404,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\tconst accounts = await ctx.context.adapter.findMany({\n\t\t\t\t\t\tmodel: \"account\",\n\t\t\t\t\t\twhere: [{ field: \"userId\", operator: \"eq\", value: session.user.id }],\n\t\t\t\t\t});\n\n\t\t\t\t\tif (accounts.length <= 1) {\n\t\t\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\t\t\tmessage: \"Cannot unlink last authentication method. Link another account first.\",\n\t\t\t\t\t\t\tstatus: 400,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\tif (nearAccount.isPrimary) {\n\t\t\t\t\t\tconst otherNearAccounts: NearAccount[] = await ctx.context.adapter.findMany({\n\t\t\t\t\t\t\tmodel: \"nearAccount\",\n\t\t\t\t\t\t\twhere: [\n\t\t\t\t\t\t\t\t{ field: \"userId\", operator: \"eq\", value: session.user.id },\n\t\t\t\t\t\t\t\t{ field: \"accountId\", operator: \"ne\", value: accountId },\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tif (otherNearAccounts.length > 0) {\n\t\t\t\t\t\t\tawait ctx.context.adapter.update({\n\t\t\t\t\t\t\t\tmodel: \"nearAccount\",\n\t\t\t\t\t\t\t\twhere: [\n\t\t\t\t\t\t\t\t\t{ field: \"id\", operator: \"eq\", value: otherNearAccounts[0]!.id },\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\tupdate: { isPrimary: true },\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tawait ctx.context.adapter.delete({\n\t\t\t\t\t\tmodel: \"nearAccount\",\n\t\t\t\t\t\twhere: [\n\t\t\t\t\t\t\t{ field: \"userId\", operator: \"eq\", value: session.user.id },\n\t\t\t\t\t\t\t{ field: \"accountId\", operator: \"eq\", value: accountId },\n\t\t\t\t\t\t\t{ field: \"network\", operator: \"eq\", value: network },\n\t\t\t\t\t\t],\n\t\t\t\t\t});\n\n\t\t\t\t\tconst accountToDelete: Account | null = await ctx.context.adapter.findOne({\n\t\t\t\t\t\tmodel: \"account\",\n\t\t\t\t\t\twhere: [\n\t\t\t\t\t\t\t{ field: \"userId\", operator: \"eq\", value: session.user.id },\n\t\t\t\t\t\t\t{ field: \"providerId\", operator: \"eq\", value: \"siwn\" },\n\t\t\t\t\t\t\t{ field: \"accountId\", operator: \"eq\", value: `${accountId}:${network}` },\n\t\t\t\t\t\t],\n\t\t\t\t\t});\n\n\t\t\t\t\tif (accountToDelete) {\n\t\t\t\t\t\tawait ctx.context.internalAdapter.deleteAccount(accountToDelete.id);\n\t\t\t\t\t}\n\n\t\t\t\t\treturn ctx.json({\n\t\t\t\t\t\tsuccess: true,\n\t\t\t\t\t\taccountId,\n\t\t\t\t\t\tnetwork,\n\t\t\t\t\t\tmessage: \"NEAR account successfully unlinked\"\n\t\t\t\t\t});\n\t\t\t\t},\n\t\t\t),\n\t\t\tlistNearAccounts: createAuthEndpoint(\n\t\t\t\t\"/near/list-accounts\",\n\t\t\t\t{\n\t\t\t\t\tmethod: \"GET\",\n\t\t\t\t\tuse: [sessionMiddleware],\n\t\t\t\t},\n\t\t\t\tasync (ctx) => {\n\t\t\t\t\tconst session = ctx.context.session;\n\n\t\t\t\t\tconst nearAccounts: NearAccount[] = await ctx.context.adapter.findMany({\n\t\t\t\t\t\tmodel: \"nearAccount\",\n\t\t\t\t\t\twhere: [{ field: \"userId\", operator: \"eq\", value: session.user.id }],\n\t\t\t\t\t});\n\n\t\t\t\t\treturn ctx.json(buildListAccountsResponse(nearAccounts));\n\t\t\t\t},\n\t\t\t),\n\t\t\tsetPrimaryNearAccount: createAuthEndpoint(\n\t\t\t\t\"/near/set-primary-account\",\n\t\t\t\t{\n\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\tbody: SetPrimaryAccountRequest,\n\t\t\t\t\tuse: [sessionMiddleware],\n\t\t\t\t},\n\t\t\t\tasync (ctx) => {\n\t\t\t\t\tconst { accountId, network: providedNetwork } = ctx.body;\n\t\t\t\t\tconst session = ctx.context.session;\n\t\t\t\t\tconst network = providedNetwork || getNetworkFromAccountId(accountId);\n\n\t\t\t\t\tconst targetAccount: NearAccount | null = await ctx.context.adapter.findOne({\n\t\t\t\t\t\tmodel: \"nearAccount\",\n\t\t\t\t\t\twhere: [\n\t\t\t\t\t\t\t{ field: \"userId\", operator: \"eq\", value: session.user.id },\n\t\t\t\t\t\t\t{ field: \"accountId\", operator: \"eq\", value: accountId },\n\t\t\t\t\t\t\t{ field: \"network\", operator: \"eq\", value: network },\n\t\t\t\t\t\t],\n\t\t\t\t\t});\n\n\t\t\t\t\tif (!targetAccount) {\n\t\t\t\t\t\tthrow new APIError(\"NOT_FOUND\", {\n\t\t\t\t\t\t\tmessage: \"NEAR account not found or not linked to your user\",\n\t\t\t\t\t\t\tstatus: 404,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\tconst nearAccounts: NearAccount[] = await ctx.context.adapter.findMany({\n\t\t\t\t\t\tmodel: \"nearAccount\",\n\t\t\t\t\t\twhere: [{ field: \"userId\", operator: \"eq\", value: session.user.id }],\n\t\t\t\t\t});\n\n\t\t\t\t\tawait Promise.all(nearAccounts.map((account) => ctx.context.adapter.update({\n\t\t\t\t\t\tmodel: \"nearAccount\",\n\t\t\t\t\t\twhere: [{ field: \"id\", operator: \"eq\", value: account.id }],\n\t\t\t\t\t\tupdate: { isPrimary: nearAccountKey(account) === nearAccountKey(targetAccount) },\n\t\t\t\t\t})));\n\n\t\t\t\t\tconst updatedNearAccounts: NearAccount[] = await ctx.context.adapter.findMany({\n\t\t\t\t\t\tmodel: \"nearAccount\",\n\t\t\t\t\t\twhere: [{ field: \"userId\", operator: \"eq\", value: session.user.id }],\n\t\t\t\t\t});\n\n\t\t\t\t\treturn ctx.json({\n\t\t\t\t\t\tsuccess: true,\n\t\t\t\t\t\taccountId,\n\t\t\t\t\t\tnetwork,\n\t\t\t\t\t\tmessage: \"Primary NEAR account updated\",\n\t\t\t\t\t\t...buildListAccountsResponse(updatedNearAccounts),\n\t\t\t\t\t});\n\t\t\t\t},\n\t\t\t),\n\t\t\tgetSiwnNonce: createAuthEndpoint(\n\t\t\t\t\"/near/nonce\",\n\t\t\t\t{\n\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\tbody: NonceRequest,\n\t\t\t\t},\n\t\t\t\tasync (ctx) => {\n\t\t\t\t\tconst { accountId, networkId } = ctx.body;\n\t\t\t\t\tconst network = getNetworkFromAccountId(accountId);\n\n\t\t\t\t\tif (networkId !== network) {\n\t\t\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\t\t\tmessage: \"Network ID mismatch with account ID\",\n\t\t\t\t\t\t\tstatus: 400,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\tconst near = getNear(network);\n\t\t\t\t\tconst exists = await near.accountExists(accountId);\n\t\t\t\t\tif (!exists) {\n\t\t\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\t\t\tmessage: \"Account does not exist on-chain\",\n\t\t\t\t\t\t\tstatus: 400,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\tconst nonce = options.getNonce ? await options.getNonce() : generateNonce();\n\n\t\t\t\t\tconst nonceString = hex.encode(nonce);\n\n\t\t\t\t\tawait ctx.context.internalAdapter.createVerificationValue({\n\t\t\t\t\t\tidentifier: `siwn:${accountId}:${network}`,\n\t\t\t\t\t\tvalue: nonceString,\n\t\t\t\t\t\texpiresAt: new Date(Date.now() + 15 * 60 * 1000),\n\t\t\t\t\t});\n\n\t\t\t\t\treturn ctx.json(NonceResponse.parse({ nonce: nonceString }));\n\t\t\t\t},\n\t\t\t),\n\t\t\tgetSiwnProfile: createAuthEndpoint(\n\t\t\t\t\"/near/profile\",\n\t\t\t\t{\n\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\tbody: ProfileRequest,\n\t\t\t\t\tuse: [sessionMiddleware],\n\t\t\t\t},\n\t\t\t\tasync (ctx) => {\n\t\t\t\t\tconst { accountId } = ctx.body;\n\t\t\t\t\tlet targetAccountId = accountId;\n\n\t\t\t\t\tif (!targetAccountId) {\n\t\t\t\t\t\tconst session = ctx.context.session;\n\t\t\t\t\t\tif (!session) {\n\t\t\t\t\t\t\tthrow new APIError(\"UNAUTHORIZED\", {\n\t\t\t\t\t\t\t\tmessage: \"Session required when no accountId provided\",\n\t\t\t\t\t\t\t\tstatus: 401,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst nearAccount: NearAccount | null = await ctx.context.adapter.findOne({\n\t\t\t\t\t\t\tmodel: \"nearAccount\",\n\t\t\t\t\t\t\twhere: [\n\t\t\t\t\t\t\t\t{ field: \"userId\", operator: \"eq\", value: session.user.id },\n\t\t\t\t\t\t\t\t{ field: \"isPrimary\", operator: \"eq\", value: true },\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tif (!nearAccount) {\n\t\t\t\t\t\t\tthrow new APIError(\"NOT_FOUND\", {\n\t\t\t\t\t\t\t\tmessage: \"No NEAR account found for user\",\n\t\t\t\t\t\t\t\tstatus: 404,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\ttargetAccountId = nearAccount.accountId;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst profile = await (options.getProfile || ((id: AccountId) => defaultGetProfile(id, apiKey)))(targetAccountId);\n\t\t\t\t\treturn ctx.json(ProfileResponse.parse(profile));\n\t\t\t\t},\n\t\t\t),\n\t\t\tverifySiwnMessage: createAuthEndpoint(\n\t\t\t\t\"/near/verify\",\n\t\t\t\t{\n\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\tbody: VerifyRequest,\n\t\t\t\t\trequireRequest: true,\n\t\t\t\t},\n\t\t\t\tasync (ctx) => {\n\t\t\t\t\tconst {\n\t\t\t\t\t\tsignedMessage,\n\t\t\t\t\t\tmessage,\n\t\t\t\t\t\trecipient,\n\t\t\t\t\t\tnonce,\n\t\t\t\t\t\taccountId,\n\t\t\t\t\t\tcallbackUrl,\n\t\t\t\t\t} = ctx.body;\n\t\t\t\t\tconst network = getNetworkFromAccountId(accountId);\n\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst near = getNear(network);\n\t\t\t\t\t\tconst nonceBytes = hex.decode(nonce);\n\n\t\t\t\t\t\tconst isValid = await verifyNep413Signature(\n\t\t\t\t\t\tsignedMessage,\n\t\t\t\t\t\t{ message, recipient, nonce: nonceBytes, callbackUrl },\n\t\t\t\t\t\t\t{ near, maxAge: 15 * 60 * 1000 },\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\tif (!isValid) {\n\t\t\t\t\t\t\tthrow new APIError(\"UNAUTHORIZED\", {\n\t\t\t\t\t\t\t\tmessage: \"Unauthorized: Invalid signature\",\n\t\t\t\t\t\t\t\tstatus: 401,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (signedMessage.accountId !== accountId) {\n\t\t\t\t\t\t\tthrow new APIError(\"UNAUTHORIZED\", {\n\t\t\t\t\t\t\t\tmessage: \"Unauthorized: Account ID mismatch\",\n\t\t\t\t\t\t\t\tstatus: 401,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst publicKey = signedMessage.publicKey;\n\n\t\t\t\t\t\tconst nonceHash = await hashNonce(nonceBytes);\n\n\t\t\t\t\t\tconst existingNonce = await ctx.context.internalAdapter.findVerificationValue(\n\t\t\t\t\t\t\t`siwn-nonce:${nonceHash}`\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\tif (existingNonce) {\n\t\t\t\t\t\t\tthrow new APIError(\"UNAUTHORIZED\", {\n\t\t\t\t\t\t\t\tmessage: \"Unauthorized: Nonce already used (replay attack detected)\",\n\t\t\t\t\t\t\t\tstatus: 401,\n\t\t\t\t\t\t\t\tcode: \"UNAUTHORIZED_NONCE_REPLAY\",\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tawait ctx.context.internalAdapter.createVerificationValue({\n\t\t\t\t\t\t\tidentifier: `siwn-nonce:${nonceHash}`,\n\t\t\t\t\t\t\tvalue: \"used\",\n\t\t\t\t\t\t\texpiresAt: new Date(Date.now() + 15 * 60 * 1000),\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tif (!options.requireFullAccessKey) {\n\t\t\t\t\t\t\tconst validateKey = options.validateLimitedAccessKey\n\t\t\t\t\t\t\t\t|| ((args: { accountId: string; publicKey: string; recipient?: string }) =>\n\t\t\t\t\t\t\t\t\tdefaultValidateLimitedAccessKey(args.accountId, args.publicKey, args.recipient || getRecipient(network), near));\n\n\t\t\t\t\t\t\tconst isValidKey = await validateKey({\n\t\t\t\t\t\t\t\taccountId: accountId,\n\t\t\t\t\t\t\t\tpublicKey: publicKey,\n\t\t\t\t\t\t\t\trecipient: options.recipient\n\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\tif (!isValidKey) {\n\t\t\t\t\t\t\t\tthrow new APIError(\"UNAUTHORIZED\", {\n\t\t\t\t\t\t\t\t\tmessage: \"Unauthorized: Invalid function call access key\",\n\t\t\t\t\t\t\t\t\tstatus: 401,\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tlet user: User | null = null;\n\n\t\t\t\t\t\tconst existingNearAccount: NearAccount | null =\n\t\t\t\t\t\t\tawait ctx.context.adapter.findOne({\n\t\t\t\t\t\t\t\tmodel: \"nearAccount\",\n\t\t\t\t\t\t\t\twhere: [\n\t\t\t\t\t\t\t\t\t{ field: \"accountId\", operator: \"eq\", value: accountId },\n\t\t\t\t\t\t\t\t\t{ field: \"network\", operator: \"eq\", value: network },\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\tif (existingNearAccount) {\n\t\t\t\t\t\t\tuser = await ctx.context.adapter.findOne({\n\t\t\t\t\t\t\t\tmodel: \"user\",\n\t\t\t\t\t\t\t\twhere: [\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tfield: \"id\",\n\t\t\t\t\t\t\t\t\t\toperator: \"eq\",\n\t\t\t\t\t\t\t\t\t\tvalue: existingNearAccount.userId,\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tconst anyNearAccount: NearAccount | null =\n\t\t\t\t\t\t\t\tawait ctx.context.adapter.findOne({\n\t\t\t\t\t\t\t\t\tmodel: \"nearAccount\",\n\t\t\t\t\t\t\t\t\twhere: [\n\t\t\t\t\t\t\t\t\t\t{ field: \"accountId\", operator: \"eq\", value: accountId },\n\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\tif (anyNearAccount) {\n\t\t\t\t\t\t\t\tuser = await ctx.context.adapter.findOne({\n\t\t\t\t\t\t\t\t\tmodel: \"user\",\n\t\t\t\t\t\t\t\t\twhere: [\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\tfield: \"id\",\n\t\t\t\t\t\t\t\t\t\t\toperator: \"eq\",\n\t\t\t\t\t\t\t\t\t\t\tvalue: anyNearAccount.userId,\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (!user) {\n\t\t\t\t\t\t\tconst userEmail = deriveEmail(accountId, getRecipient(network));\n\n\t\t\t\t\t\t\tconst profile = await (options.getProfile || ((id: AccountId) => defaultGetProfile(id, apiKey)))(accountId);\n\n\t\t\t\t\t\t\tuser = await ctx.context.internalAdapter.createUser({\n\t\t\t\t\t\t\t\tname: profile?.name ?? accountId,\n\t\t\t\t\t\t\t\temail: userEmail,\n\t\t\t\t\t\t\t\timage: profile?.image ? getImageUrl(profile.image) : \"\",\n\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\tawait ctx.context.adapter.create({\n\t\t\t\t\t\t\t\tmodel: \"nearAccount\",\n\t\t\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\t\t\tuserId: user.id,\n\t\t\t\t\t\t\t\t\taccountId,\n\t\t\t\t\t\t\t\t\tnetwork,\n\t\t\t\t\t\t\t\t\tpublicKey: publicKey,\n\t\t\t\t\t\t\t\t\tisPrimary: true,\n\t\t\t\t\t\t\t\t\tcreatedAt: new Date(),\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\tawait ctx.context.internalAdapter.createAccount({\n\t\t\t\t\t\t\t\tuserId: user.id,\n\t\t\t\t\t\t\t\tproviderId: \"siwn\",\n\t\t\t\t\t\t\t\taccountId: `${accountId}:${network}`,\n\t\t\t\t\t\t\t\tcreatedAt: new Date(),\n\t\t\t\t\t\t\t\tupdatedAt: new Date(),\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tif (!existingNearAccount) {\n\t\t\t\t\t\t\t\tawait ctx.context.adapter.create({\n\t\t\t\t\t\t\t\t\tmodel: \"nearAccount\",\n\t\t\t\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\t\t\t\tuserId: user.id,\n\t\t\t\t\t\t\t\t\t\taccountId,\n\t\t\t\t\t\t\t\t\t\tnetwork,\n\t\t\t\t\t\t\t\t\t\tpublicKey: publicKey,\n\t\t\t\t\t\t\t\t\t\tisPrimary: false,\n\t\t\t\t\t\t\t\t\t\tcreatedAt: new Date(),\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\tawait ctx.context.internalAdapter.createAccount({\n\t\t\t\t\t\t\t\t\tuserId: user.id,\n\t\t\t\t\t\t\t\t\tproviderId: \"siwn\",\n\t\t\t\t\t\t\t\t\taccountId: `${accountId}:${network}`,\n\t\t\t\t\t\t\t\t\tcreatedAt: new Date(),\n\t\t\t\t\t\t\t\t\tupdatedAt: new Date(),\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tawait ensureRelayer(ctx.context.adapter, ctx.context.secret, network);\n\n\t\t\t\t\t\tconst session = await ctx.context.internalAdapter.createSession(\n\t\t\t\t\t\t\tuser.id\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\tif (!session) {\n\t\t\t\t\t\t\tthrow new APIError(\"INTERNAL_SERVER_ERROR\", {\n\t\t\t\t\t\t\t\tmessage: \"Internal Server Error\",\n\t\t\t\t\t\t\t\tstatus: 500,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tawait setSessionCookie(ctx, { session, user });\n\n\t\t\t\t\t\treturn ctx.json(VerifyResponse.parse({\n\t\t\t\t\t\t\ttoken: session.token,\n\t\t\t\t\t\t\tsuccess: true,\n\t\t\t\t\t\t\tuser: {\n\t\t\t\t\t\t\t\tid: user.id,\n\t\t\t\t\t\t\t\taccountId,\n\t\t\t\t\t\t\t\tnetwork,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}));\n\t\t\t\t\t} catch (error: unknown) {\n\t\t\t\t\t\tif (error instanceof APIError) throw error;\n\t\t\t\t\t\tconst msg = error instanceof Error ? error.message : \"Unknown error\";\n\t\t\t\t\t\tconst at = error instanceof Error && error.stack ? error.stack.split(\"\\n\").slice(1, 3).map(s => s.trim()).join(\" <- \") : \"\";\n\t\t\t\t\t\tconsole.error(`[siwn] Verify error: ${msg}${at ? ` (${at})` : \"\"}`);\n\t\t\t\t\t\tthrow new APIError(\"UNAUTHORIZED\", {\n\t\t\t\t\t\t\tmessage: \"Something went wrong. Please try again later.\",\n\t\t\t\t\t\t\terror: msg,\n\t\t\t\t\t\t\tstatus: 401,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t),\n\t\t\trelayNearTransaction: createAuthEndpoint(\n\t\t\t\t\"/near/relay\",\n\t\t\t\t{\n\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\tbody: RelayRequest,\n\t\t\t\t\tuse: [sessionMiddleware],\n\t\t\t\t},\n\t\t\t\tasync (ctx) => {\n\t\t\t\t\tconst { payload } = ctx.body;\n\t\t\t\t\tconst session = ctx.context.session;\n\n\t\t\t\t\tif (!session) {\n\t\t\t\t\t\tthrow new APIError(\"UNAUTHORIZED\", {\n\t\t\t\t\t\t\tmessage: \"Must be authenticated to relay transactions\",\n\t\t\t\t\t\t\tstatus: 401,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\tconst nearAccount: NearAccount | null = await ctx.context.adapter.findOne({\n\t\t\t\t\t\tmodel: \"nearAccount\",\n\t\t\t\t\t\twhere: [\n\t\t\t\t\t\t\t{ field: \"userId\", operator: \"eq\", value: session.user.id },\n\t\t\t\t\t\t\t{ field: \"isPrimary\", operator: \"eq\", value: true },\n\t\t\t\t\t\t],\n\t\t\t\t\t});\n\n\t\t\t\t\tif (!nearAccount) {\n\t\t\t\t\t\tthrow new APIError(\"UNAUTHORIZED\", {\n\t\t\t\t\t\t\tmessage: \"No NEAR account linked to session\",\n\t\t\t\t\t\t\tstatus: 401,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\tconst network = nearAccount.network as \"mainnet\" | \"testnet\";\n\t\t\t\t\tconst rState = await ensureRelayer(ctx.context.adapter, ctx.context.secret, network);\n\n\t\t\t\t\tif (!rState) {\n\t\t\t\t\t\tthrow new APIError(\"SERVICE_UNAVAILABLE\", {\n\t\t\t\t\t\t\tmessage: \"Relayer not configured\",\n\t\t\t\t\t\t\tstatus: 503,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst decoded: SignedDelegateAction = decodeSignedDelegateAction(payload);\n\t\t\t\t\t\tconst delegateAction = decoded.signedDelegate.delegateAction;\n\n\t\t\t\t\t\tif (delegateAction.senderId !== nearAccount.accountId) {\n\t\t\t\t\t\t\tthrow new APIError(\"UNAUTHORIZED\", {\n\t\t\t\t\t\t\t\tmessage: \"Delegate action sender does not match session account\",\n\t\t\t\t\t\t\t\tstatus: 401,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst relayerConfigForNetwork = getRelayerConfig(network);\n\t\t\t\t\t\tif (relayerConfigForNetwork?.whitelistedContracts?.length) {\n\t\t\t\t\t\t\tif (!relayerConfigForNetwork.whitelistedContracts.includes(delegateAction.receiverId)) {\n\t\t\t\t\t\t\t\tthrow new APIError(\"FORBIDDEN\", {\n\t\t\t\t\t\t\t\t\tmessage: `Contract ${delegateAction.receiverId} is not whitelisted for relay`,\n\t\t\t\t\t\t\t\t\tstatus: 403,\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (relayerConfigForNetwork?.maxGasPerTransaction) {\n\t\t\t\t\t\t\tconst totalGas = delegateAction.actions.reduce((sum: bigint, a) => {\n\t\t\t\t\t\t\t\treturn sum + (\"functionCall\" in a ? a.functionCall.gas : 0n);\n\t\t\t\t\t\t\t}, 0n);\n\t\t\t\t\t\t\tif (totalGas > BigInt(relayerConfigForNetwork.maxGasPerTransaction)) {\n\t\t\t\t\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\t\t\t\t\tmessage: `Transaction gas (${totalGas}) exceeds relayer limit (${relayerConfigForNetwork.maxGasPerTransaction})`,\n\t\t\t\t\t\t\t\t\tstatus: 400,\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (relayerConfigForNetwork?.maxDepositPerTransaction) {\n\t\t\t\t\t\t\tconst totalDeposit = delegateAction.actions.reduce((sum: bigint, a) => {\n\t\t\t\t\t\t\t\tif (\"functionCall\" in a) return sum + a.functionCall.deposit;\n\t\t\t\t\t\t\t\tif (\"transfer\" in a) return sum + a.transfer.deposit;\n\t\t\t\t\t\t\t\treturn sum;\n\t\t\t\t\t\t\t}, 0n);\n\t\t\t\t\t\t\tif (totalDeposit > BigInt(relayerConfigForNetwork.maxDepositPerTransaction)) {\n\t\t\t\t\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\t\t\t\t\tmessage: `Transaction deposit (${totalDeposit}) exceeds relayer limit (${relayerConfigForNetwork.maxDepositPerTransaction})`,\n\t\t\t\t\t\t\t\t\tstatus: 400,\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst result = await relayOnChain(payload, rState);\n\n\t\t\t\t\t\tawait ctx.context.adapter.create({\n\t\t\t\t\t\t\tmodel: \"relayedTransaction\",\n\t\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\t\tuserId: session.user.id,\n\t\t\t\t\t\t\t\ttxHash: result.txHash,\n\t\t\t\t\t\t\t\tsenderId: delegateAction.senderId,\n\t\t\t\t\t\t\t\treceiverId: delegateAction.receiverId,\n\t\t\t\t\t\t\t\tnetwork,\n\t\t\t\t\t\t\t\tstatus: \"pending\",\n\t\t\t\t\t\t\t\tcreatedAt: new Date(),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t});\n\n\t\t\t\t\tif (rState.mode === \"ephemeral\") {\n\t\t\t\t\t\tawait ctx.context.adapter.update({\n\t\t\t\t\t\t\tmodel: \"relayerKey\",\n\t\t\t\t\t\t\twhere: [{ field: \"network\", operator: \"eq\", value: network }],\n\t\t\t\t\t\t\tupdate: { lastUsedAt: new Date() },\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\t\treturn ctx.json(RelayResponse.parse({\n\t\t\t\t\t\t\ttxHash: result.txHash,\n\t\t\t\t\t\t\tstatus: \"pending\",\n\t\t\t\t\t\t}));\n\t\t\t\t\t} catch (error: unknown) {\n\t\t\t\t\t\tif (error instanceof APIError) throw error;\n\t\t\t\t\t\tthrow new APIError(\"INTERNAL_SERVER_ERROR\", {\n\t\t\t\t\t\t\tmessage: error instanceof Error ? error.message : \"Relay failed\",\n\t\t\t\t\t\t\tstatus: 500,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t),\n\t\t\tgetRelayStatus: createAuthEndpoint(\n\t\t\t\t\"/near/relay-status/:txHash\",\n\t\t\t\t{\n\t\t\t\t\tmethod: \"GET\",\n\t\t\t\t\tuse: [sessionMiddleware],\n\t\t\t\t},\n\t\t\t\tasync (ctx) => {\n\t\t\t\t\tconst txHash = (ctx.params as Record<string, string>)?.txHash;\n\t\t\t\t\tif (!txHash) {\n\t\t\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\t\t\tmessage: \"Transaction hash required\",\n\t\t\t\t\t\t\tstatus: 400,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\tconst session = ctx.context.session;\n\n\t\t\t\t\tconst relayedTx = await ctx.context.adapter.findOne<RelayedTransactionRecord>({\n\t\t\t\t\t\tmodel: \"relayedTransaction\",\n\t\t\t\t\t\twhere: [\n\t\t\t\t\t\t\t{ field: \"txHash\", operator: \"eq\", value: txHash },\n\t\t\t\t\t\t\t{ field: \"userId\", operator: \"eq\", value: session.user.id },\n\t\t\t\t\t\t],\n\t\t\t\t\t});\n\n\t\t\t\t\tif (!relayedTx) {\n\t\t\t\t\t\tthrow new APIError(\"NOT_FOUND\", {\n\t\t\t\t\t\t\tmessage: \"Transaction not found or not owned by this user\",\n\t\t\t\t\t\t\tstatus: 404,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\tconst network = relayedTx.network;\n\t\t\t\t\tconst senderId = relayedTx.senderId;\n\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst near = getNear(network);\n\t\t\t\t\t\tconst txResult = await near.getTransactionStatus(txHash, senderId);\n\n\t\t\t\t\t\tconst txStatus = txResult.status;\n\t\t\t\t\t\tif (txStatus && typeof txStatus === \"object\") {\n\t\t\t\t\t\t\tconst hasSuccess = \"SuccessValue\" in txStatus || \"SuccessReceiptId\" in txStatus;\n\t\t\t\t\t\t\tconst hasFailure = \"Failure\" in txStatus;\n\t\t\t\t\t\t\tconst status = hasSuccess ? \"completed\" : hasFailure ? \"failed\" : \"pending\";\n\n\t\t\t\t\t\t\tif (status !== \"pending\") {\n\t\t\t\t\t\t\t\tawait ctx.context.adapter.update({\n\t\t\t\t\t\t\t\t\tmodel: \"relayedTransaction\",\n\t\t\t\t\t\t\t\t\twhere: [{ field: \"txHash\", operator: \"eq\", value: txHash }],\n\t\t\t\t\t\t\t\t\tupdate: { status },\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tconst gasUsed = txResult.transaction_outcome?.outcome?.gas_burnt?.toString();\n\n\t\t\t\t\t\t\treturn ctx.json(RelayStatusResponse.parse({\n\t\t\t\t\t\t\t\tstatus,\n\t\t\t\t\t\t\t\tgasUsed,\n\t\t\t\t\t\t\t\toutcome: txResult,\n\t\t\t\t\t\t\t}));\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn ctx.json(RelayStatusResponse.parse({ status: \"pending\" }));\n\t\t\t\t\t} catch (error: unknown) {\n\t\t\t\t\t\treturn ctx.json(RelayStatusResponse.parse({ status: \"pending\" }));\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t),\n\t\t\tgetRelayerInfo: createAuthEndpoint(\n\t\t\t\t\"/near/relayer-info\",\n\t\t\t\t{\n\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\tbody: GetRelayerInfoRequest,\n\t\t\t\t\tuse: [sessionMiddleware],\n\t\t\t\t},\n\t\t\t\tasync (ctx) => {\n\t\t\t\t\tconst { network: requestedNetwork } = ctx.body;\n\t\t\t\t\tconst targetNetwork = (requestedNetwork ?? primaryNetwork) as \"mainnet\" | \"testnet\";\n\t\t\t\t\tconst rState = await ensureRelayer(ctx.context.adapter, ctx.context.secret, targetNetwork);\n\n\t\t\t\t\tif (!rState) {\n\t\t\t\t\t\treturn ctx.json({ enabled: false, subAccountAvailable: false } satisfies Partial<RelayerInfo> & { enabled: boolean });\n\t\t\t\t\t}\n\n\t\t\t\t\tconst subAccountCfg = getSubAccountConfig(targetNetwork);\n\t\t\t\t\tconst { parentAccount, subAccountAvailable } = resolveParentAccount(subAccountCfg, rState);\n\n\t\t\t\t\tconst near = getNear(rState.network);\n\t\t\t\t\tlet account;\n\t\t\t\t\ttry {\n\t\t\t\t\t\taccount = await near.getAccount(rState.accountId);\n\t\t\t\t\t} catch {\n\t\t\t\t\t\taccount = {\n\t\t\t\t\t\t\tbalance: \"0\",\n\t\t\t\t\t\t\tavailable: \"0\",\n\t\t\t\t\t\t\tstaked: \"0\",\n\t\t\t\t\t\t\tstorageUsage: \"0\",\n\t\t\t\t\t\t\tstorageBytes: 0,\n\t\t\t\t\t\t\thasContract: false,\n\t\t\t\t\t\t\tcodeHash: \"\",\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\n\t\t\t\t\treturn ctx.json({\n\t\t\t\t\t\tenabled: true,\n\t\t\t\t\t\taccountId: rState.accountId,\n\t\t\t\t\t\tmode: rState.mode,\n\t\t\t\t\t\tnetwork: rState.network,\n\t\t\t\t\t\tpublicKey: rState.publicKey,\n\t\t\t\t\t\tbalance: account.balance,\n\t\t\t\t\t\tavailable: account.available,\n\t\t\t\t\t\tstaked: account.staked,\n\t\t\t\t\t\tstorageUsage: account.storageUsage,\n\t\t\t\t\t\tstorageBytes: account.storageBytes,\n\t\t\t\t\t\thasContract: account.hasContract,\n\t\t\t\t\t\thasKey: true,\n\t\t\t\t\t\tcreatedAt: rState.createdAt,\n\t\t\t\t\t\tlastUsedAt: rState.lastUsedAt,\n\t\t\t\t\t\tparentAccount: parentAccount ?? undefined,\n\t\t\t\t\t\tsubAccountAvailable,\n\t\t\t\t\t});\n\t\t\t\t},\n\t\t\t),\n\t\t\tgetRelayHistory: createAuthEndpoint(\n\t\t\t\t\"/near/relay-history\",\n\t\t\t\t{\n\t\t\t\t\tmethod: \"GET\",\n\t\t\t\t\tuse: [sessionMiddleware],\n\t\t\t\t},\n\t\t\t\tasync (ctx) => {\n\t\t\t\t\tconst session = ctx.context.session;\n\n\t\t\t\t\tlet transactions: RelayedTransactionRecord[] = [];\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst result = await ctx.context.adapter.findMany<RelayedTransactionRecord>({\n\t\t\t\t\t\t\tmodel: \"relayedTransaction\",\n\t\t\t\t\t\t\twhere: [\n\t\t\t\t\t\t\t\t{ field: \"userId\", operator: \"eq\", value: session.user.id },\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t});\n\t\t\t\t\t\ttransactions = result || [];\n\t\t\t\t\t} catch (err) {\n\t\t\t\t\t\tconsole.error(\"relay-history findMany error:\", err);\n\t\t\t\t\t}\n\n\t\t\t\t\tconst sorted = transactions.sort((a, b) => {\n\t\t\t\t\t\tconst aTime = a.createdAt instanceof Date ? a.createdAt.getTime() : new Date(a.createdAt ?? 0).getTime();\n\t\t\t\t\t\tconst bTime = b.createdAt instanceof Date ? b.createdAt.getTime() : new Date(b.createdAt ?? 0).getTime();\n\t\t\t\t\t\treturn bTime - aTime;\n\t\t\t\t\t});\n\n\t\t\t\t\treturn ctx.json({\n\t\t\t\t\t\ttransactions: sorted.map((tx) => ({\n\t\t\t\t\t\t\tid: String(tx.id ?? \"\"),\n\t\t\t\t\t\t\tuserId: String(tx.userId ?? \"\"),\n\t\t\t\t\t\t\ttxHash: String(tx.txHash ?? \"\"),\n\t\t\t\t\t\t\tsenderId: String(tx.senderId ?? \"\"),\n\t\t\t\t\t\t\treceiverId: String(tx.receiverId ?? \"\"),\n\t\t\t\t\t\t\tnetwork: String(tx.network ?? \"mainnet\"),\n\t\t\t\t\t\t\tstatus: String(tx.status ?? \"pending\"),\n\t\t\t\t\t\t\tgasUsed: tx.gasUsed ? String(tx.gasUsed) : undefined,\n\t\t\t\t\t\t\tcreatedAt: tx.createdAt instanceof Date ? tx.createdAt.toISOString() : tx.createdAt ? String(tx.createdAt) : new Date().toISOString(),\n\t\t\t\t\t\t\tupdatedAt: tx.updatedAt instanceof Date ? tx.updatedAt.toISOString() : tx.updatedAt ? String(tx.updatedAt) : undefined,\n\t\t\t\t\t\t})),\n\t\t\t\t\t});\n\t\t\t\t},\n\t\t\t),\n\t\t\tviewContract: createAuthEndpoint(\n\t\t\t\t\"/near/view\",\n\t\t\t\t{\n\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\tbody: ViewContractRequest,\n\t\t\t\t\tuse: [sessionMiddleware],\n\t\t\t\t},\n\t\t\t\tasync (ctx) => {\n\t\t\t\t\tconst { contractId, methodName, args } = ctx.body;\n\t\t\t\t\tconst session = ctx.context.session;\n\t\t\t\t\tconst nearAccount: NearAccount | null = await ctx.context.adapter.findOne({\n\t\t\t\t\t\tmodel: \"nearAccount\",\n\t\t\t\t\t\twhere: [\n\t\t\t\t\t\t\t{ field: \"userId\", operator: \"eq\", value: session.user.id },\n\t\t\t\t\t\t\t{ field: \"isPrimary\", operator: \"eq\", value: true },\n\t\t\t\t\t\t],\n\t\t\t\t\t});\n\n\t\t\t\t\tconst network = (nearAccount?.network || primaryNetwork) as \"mainnet\" | \"testnet\";\n\t\t\t\t\tconst near = getNear(network);\n\t\t\t\t\tlet result: unknown;\n\t\t\t\t\ttry {\n\t\t\t\t\t\tresult = await near.view(contractId, methodName, args ?? {});\n\t\t\t\t\t} catch (error: unknown) {\n\t\t\t\t\t\tif (error instanceof APIError) throw error;\n\t\t\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\t\t\tmessage: error instanceof Error ? error.message : \"Unknown error\",\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t\treturn ctx.json(ViewContractResponse.parse({ result }));\n\t\t\t\t},\n\t\t\t),\n\t\t\tcreateSubAccount: createAuthEndpoint(\n\t\t\t\t\"/near/create-sub-account\",\n\t\t\t\t{\n\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\tbody: CreateSubAccountRequest,\n\t\t\t\t\tuse: [sessionMiddleware],\n\t\t\t\t},\n\t\t\t\tasync (ctx) => {\n\t\t\t\t\tconst { subAccountName, network: providedNetwork, publicKey } = ctx.body;\n\t\t\t\t\tconst session = ctx.context.session;\n\n\t\t\t\t\tif (!session) {\n\t\t\t\t\t\tthrow new APIError(\"UNAUTHORIZED\", {\n\t\t\t\t\t\t\tmessage: \"Must be authenticated to create a sub-account\",\n\t\t\t\t\t\t\tstatus: 401,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\tconst nearAccount: NearAccount | null = await ctx.context.adapter.findOne({\n\t\t\t\t\t\tmodel: \"nearAccount\",\n\t\t\t\t\t\twhere: [\n\t\t\t\t\t\t\t{ field: \"userId\", operator: \"eq\", value: session.user.id },\n\t\t\t\t\t\t\t{ field: \"isPrimary\", operator: \"eq\", value: true },\n\t\t\t\t\t\t],\n\t\t\t\t\t});\n\n\t\t\t\t\tconst network = (providedNetwork || nearAccount?.network || primaryNetwork) as \"mainnet\" | \"testnet\";\n\t\t\t\t\tconst subAccountCfg = getSubAccountConfig(network);\n\t\t\t\t\tconst rState = await ensureRelayer(ctx.context.adapter, ctx.context.secret, network);\n\n\t\t\t\t\tif (!rState) {\n\t\t\t\t\t\tthrow new APIError(\"SERVICE_UNAVAILABLE\", {\n\t\t\t\t\t\t\tmessage: \"Relayer not configured — sub-account creation requires a funded relayer\",\n\t\t\t\t\t\t\tstatus: 503,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\tconst { parentAccount, subAccountAvailable } = resolveParentAccount(subAccountCfg, rState);\n\n\t\t\t\t\tif (!subAccountAvailable || !parentAccount) {\n\t\t\t\t\t\tthrow new APIError(\"SERVICE_UNAVAILABLE\", {\n\t\t\t\t\t\t\tmessage: \"Sub-account creation requires a named parent account. Configure subAccount.parentAccount in your SIWN plugin options, or use an explicit relayer with a named account.\",\n\t\t\t\t\t\t\tstatus: 503,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\tif (parentAccount !== rState.accountId && !subAccountCfg?.parentKey) {\n\t\t\t\t\t\tthrow new APIError(\"SERVICE_UNAVAILABLE\", {\n\t\t\t\t\t\t\tmessage: \"Sub-account parent differs from relayer account. Configure subAccount.parentKey to enable signing as the parent account.\",\n\t\t\t\t\t\t\tstatus: 503,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\tconst newAccountId = `${subAccountName}.${parentAccount}`;\n\t\t\t\t\tconst minDeposit = subAccountCfg?.minDeposit || \"0.1 NEAR\";\n\n\t\t\t\t\tconst near = getNear(network);\n\t\t\t\t\tconst exists = await near.accountExists(newAccountId);\n\t\t\t\t\tif (exists) {\n\t\t\t\t\t\tthrow new APIError(\"CONFLICT\", {\n\t\t\t\t\t\t\tmessage: `Account ${newAccountId} already exists on ${network}`,\n\t\t\t\t\t\t\tstatus: 409,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\tlet txBuilder = rState.near\n\t\t\t\t\t\t.transaction(parentAccount)\n\t\t\t\t\t\t.createAccount(newAccountId)\n\t\t\t\t\t\t.addKey(publicKey, { type: \"fullAccess\" });\n\n\t\t\t\t\tif (subAccountCfg?.parentKey) {\n\t\t\t\t\t\ttxBuilder = txBuilder.signWith(subAccountCfg.parentKey as PrivateKey);\n\t\t\t\t\t}\n\n\t\t\t\t\tif (subAccountCfg?.addRelayerFCAK !== false && subAccountCfg?.relayerFCAK) {\n\t\t\t\t\t\tconst fcakPermission: { type: \"functionCall\"; receiverId: string; methodNames?: string[]; allowance?: string } = {\n\t\t\t\t\t\t\ttype: \"functionCall\",\n\t\t\t\t\t\t\treceiverId: subAccountCfg.relayerFCAK.receiverId,\n\t\t\t\t\t\t};\n\t\t\t\t\t\tif (subAccountCfg.relayerFCAK.methodNames) {\n\t\t\t\t\t\t\tfcakPermission.methodNames = subAccountCfg.relayerFCAK.methodNames;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (subAccountCfg.relayerFCAK.allowance) {\n\t\t\t\t\t\t\tfcakPermission.allowance = subAccountCfg.relayerFCAK.allowance as `${number} NEAR` | `${bigint} yocto`;\n\t\t\t\t\t\t}\n\t\t\t\t\t\ttxBuilder.addKey(rState.publicKey, fcakPermission as any);\n\t\t\t\t\t}\n\n\t\t\t\t\ttxBuilder.transfer(newAccountId, minDeposit as `${number} NEAR`);\n\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait txBuilder.send({ waitUntil: \"EXECUTED\" });\n\n\t\t\t\t\t\tawait ctx.context.adapter.create({\n\t\t\t\t\t\t\tmodel: \"nearAccount\",\n\t\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\t\tuserId: session.user.id,\n\t\t\t\t\t\t\t\taccountId: newAccountId,\n\t\t\t\t\t\t\t\tnetwork,\n\t\t\t\t\t\t\t\tpublicKey,\n\t\t\t\t\t\t\t\tisPrimary: false,\n\t\t\t\t\t\t\t\tcreatedAt: new Date(),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tawait ctx.context.internalAdapter.createAccount({\n\t\t\t\t\t\t\tuserId: session.user.id,\n\t\t\t\t\t\t\tproviderId: \"siwn\",\n\t\t\t\t\t\t\taccountId: `${newAccountId}:${network}`,\n\t\t\t\t\t\t\tcreatedAt: new Date(),\n\t\t\t\t\t\t\tupdatedAt: new Date(),\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\treturn ctx.json(CreateSubAccountResponse.parse({\n\t\t\t\t\t\t\tsuccess: true,\n\t\t\t\t\t\t\taccountId: newAccountId,\n\t\t\t\t\t\t\tnetwork,\n\t\t\t\t\t\t\tpublicKey,\n\t\t\t\t\t\t\tmessage: `Sub-account ${newAccountId} created on ${network}`,\n\t\t\t\t\t\t}));\n\t\t\t\t\t} catch (error: unknown) {\n\t\t\t\t\t\tconst msg = error instanceof Error ? error.message : \"Unknown error\";\n\t\t\t\t\t\tthrow new APIError(\"INTERNAL_SERVER_ERROR\", {\n\t\t\t\t\t\t\tmessage: `Failed to create sub-account: ${msg}`,\n\t\t\t\t\t\t\tstatus: 500,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t),\n\t\t\tcheckSubAccountAvailability: createAuthEndpoint(\n\t\t\t\t\"/near/check-sub-account-availability\",\n\t\t\t\t{\n\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\tbody: CheckSubAccountAvailabilityRequest,\n\t\t\t\t},\n\t\t\t\tasync (ctx) => {\n\t\t\t\t\tconst { subAccountName, network: providedNetwork } = ctx.body;\n\n\t\t\t\t\tconst network = (providedNetwork || primaryNetwork) as \"mainnet\" | \"testnet\";\n\t\t\t\t\tconst subAccountCfg = getSubAccountConfig(network);\n\t\t\t\t\tconst rState = await ensureRelayer(ctx.context.adapter, ctx.context.secret, network);\n\n\t\t\t\t\tconst { parentAccount, subAccountAvailable } = resolveParentAccount(subAccountCfg, rState);\n\n\t\t\t\t\tif (!subAccountAvailable || !parentAccount) {\n\t\t\t\t\t\tthrow new APIError(\"SERVICE_UNAVAILABLE\", {\n\t\t\t\t\t\t\tmessage: \"Sub-account creation requires a named parent account. Configure subAccount.parentAccount in your SIWN plugin options, or use an explicit relayer with a named account.\",\n\t\t\t\t\t\t\tstatus: 503,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\tconst accountId = `${subAccountName}.${parentAccount}`;\n\n\t\t\t\t\tconst near = getNear(network);\n\t\t\t\t\tconst exists = await near.accountExists(accountId);\n\n\t\t\t\t\treturn ctx.json(CheckSubAccountAvailabilityResponse.parse({\n\t\t\t\t\t\tavailable: !exists,\n\t\t\t\t\t\taccountId,\n\t\t\t\t\t}));\n\t\t\t\t},\n\t\t\t),\n\t\t},\n\t});\n};\n"],"mappings":";;;;;;;AAEA,MAAM,eACL;AAED,SAAS,wBAAwB,WAA0C;CAC1E,OAAO,UAAU,SAAS,UAAU,IAAI,YAAY;AACrD;AAEA,SAAS,YACR,OACA,UACS;CACT,IAAI,OAAO,KAAK,OAAO,MAAM;CAC7B,IAAI,OAAO,UAAU,OAAO,iCAAiC,MAAM;CACnE,OAAO,YAAY;AACpB;AAmBA,eAAe,kBAAkB,WAAsB,QAA0C;CAChG,MAAM,UAAU,wBAAwB,SAAS;CAEjD,IAAI;EACH,MAAM,QAAQ,YAAY,YACvB,iCACA;EAEH,MAAM,kBAAkB,UAAU,QAAQ,IAAI;EAC9C,MAAM,UAAkC,EAAE,gBAAgB,mBAAmB;EAC7E,IAAI,iBACH,QAAQ,mBAAmB,UAAU;EAGtC,MAAM,WAAW,MAAM,MACtB,GAAG,MAAM,yBAAyB,UAAU,cAC5C,EAAE,QAAQ,CACX;EAEA,IAAI,SAAS,IAAI;GAEhB,MAAM,SAAQ,MADK,SAAS,KAAK,IACb,UAAU;GAC9B,IAAI,OAAO,OACV,IAAI;IACH,MAAM,UAAU,OAAO,MAAM,UAAU,WACpC,KAAK,MAAM,MAAM,KAAK,IACtB,MAAM;IACT,IAAI,SAAS,QAAQ,SAAS,eAAe,SAAS,OACrD,OAAO;KACN,MAAM,QAAQ;KACd,aAAa,QAAQ;KACrB,OAAO,QAAQ;KACf,iBAAiB,QAAQ;KACzB,UAAU,QAAQ;IACnB;GAEF,QAAQ,CAAC;EAEX;EAEA,MAAM,UAAU;GACf,SAAS;GACT,SAAS;EACV,EAAE;EAEF,MAAM,OAAO,CAAC,GAAG,UAAU,YAAY;EAEvC,MAAM,mBA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,UAAU;MAGpD,QAAQ;KACT,CAAC;IACF;GACD,CACD;GACA,6BAA6B,mBAC5B,wCACA;IACC,QAAQ;IACR,MAAM;GACP,GACA,OAAO,QAAQ;IACd,MAAM,EAAE,gBAAgB,SAAS,oBAAoB,IAAI;IAEzD,MAAM,UAAW,mBAAmB;IAIpC,MAAM,EAAE,eAAe,wBAAwB,qBAHzB,oBAAoB,OAGsC,GAAG,MAF9D,cAAc,IAAI,QAAQ,SAAS,IAAI,QAAQ,QAAQ,OAAO,CAEM;IAEzF,IAAI,CAAC,uBAAuB,CAAC,eAC5B,MAAM,IAAI,SAAS,uBAAuB;KACzC,SAAS;KACT,QAAQ;IACT,CAAC;IAGF,MAAM,YAAY,GAAG,eAAe,GAAG;IAGvC,MAAM,SAAS,MADF,QAAQ,OACG,EAAE,cAAc,SAAS;IAEjD,OAAO,IAAI,KAAK,oCAAoC,MAAM;KACzD,WAAW,CAAC;KACZ;IACD,CAAC,CAAC;GACH,CACD;EACD;CACD;AACD"}
package/dist/types.d.ts CHANGED
@@ -57,6 +57,7 @@ export declare const LinkAccountRequest: z.ZodObject<{
57
57
  recipient: z.ZodString;
58
58
  nonce: z.ZodString;
59
59
  accountId: z.ZodString;
60
+ callbackUrl: z.ZodOptional<z.ZodString>;
60
61
  }, z.core.$strip>;
61
62
  export declare const SetPrimaryAccountRequest: z.ZodObject<{
62
63
  accountId: z.ZodString;
@@ -80,6 +81,7 @@ export declare const VerifyRequest: z.ZodObject<{
80
81
  recipient: z.ZodString;
81
82
  nonce: z.ZodString;
82
83
  accountId: z.ZodString;
84
+ callbackUrl: z.ZodOptional<z.ZodString>;
83
85
  }, z.core.$strip>;
84
86
  export declare const RelayRequest: z.ZodObject<{
85
87
  payload: z.ZodString;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAmB,KAAK,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X,OAAO,EAAE,CAAC,CAAC;CACX;AAED,eAAO,MAAM,qBAAqB;;;;;iBAEhC,CAAC;AACH,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAE3E,MAAM,WAAW,2BAA2B;IAC3C,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,gBAAgB;IAChC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,WAAW,CAAC,EAAE,2BAA2B,CAAC;CAC1C;AAED,eAAO,MAAM,uBAAuB;;;;;;;iBAIlC,CAAC;AACH,MAAM,MAAM,wBAAwB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAE/E,eAAO,MAAM,wBAAwB;;;;;;;;;iBAMnC,CAAC;AACH,MAAM,MAAM,yBAAyB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAEjF,eAAO,MAAM,kCAAkC;;;;;;iBAG7C,CAAC;AACH,MAAM,MAAM,mCAAmC,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kCAAkC,CAAC,CAAC;AAErG,eAAO,MAAM,mCAAmC;;;iBAG9C,CAAC;AACH,MAAM,MAAM,oCAAoC,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mCAAmC,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "better-near-auth",
3
- "version": "1.6.3",
3
+ "version": "1.6.5",
4
4
  "description": "Sign in with NEAR (SIWN) plugin for Better Auth",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -5,10 +5,11 @@ description: >
5
5
  connection via NearConnect, use authClient.near actions for sign-in, profile
6
6
  lookup, account management, delegate action building with TransactionBuilder,
7
7
  and relay submission. Load when implementing NEAR wallet sign-in on the client,
8
- using authClient.near.* methods, or building delegate actions for gasless relay.
9
- type: core
10
- library: better-near-auth
11
- library_version: "1.6.3"
8
+ using authClient.near.* methods, or building delegate actions for gasless relay.
9
+ metadata:
10
+ type: core
11
+ library: better-near-auth
12
+ library_version: "1.6.5"
12
13
  sources:
13
14
  - "elliotBraem/better-near-auth:src/client.ts"
14
15
  - "elliotBraem/better-near-auth:src/types.ts"
@@ -204,11 +205,18 @@ const result = await authClient.near.view({
204
205
  | `link(callbacks?)` | `Promise<void>` | Link NEAR account to session |
205
206
  | `unlink(params)` | `Promise<Response>` | Unlink NEAR account |
206
207
  | `listAccounts()` | `Promise<Response>` | List linked NEAR accounts |
208
+ | `setPrimaryAccount(params)` | `Promise<Response<SetPrimaryAccountResponse>>` | Set primary linked NEAR account |
209
+ | `createSubAccount(params)` | `Promise<Response<CreateSubAccountResponse>>` | Create a sub-account |
210
+ | `checkSubAccountAvailability(params)` | `Promise<Response<CheckSubAccountAvailabilityResponse>>` | Check if a sub-account name is available |
207
211
  | `buildSignedDelegateAction(receiverId, buildActions)` | `Promise<string>` | Build + sign delegate action, returns base64 payload |
208
212
  | `relayTransaction({ payload })` | `Promise<Response<RelayResponse>>` | Submit delegate action to relayer |
209
213
  | `getRelayStatus(txHash)` | `Promise<Response<RelayStatusResponse>>` | Check relayed tx status |
210
214
  | `getRelayerInfo()` | `Promise<Response<RelayerInfo>>` | Get relayer info and balance |
211
215
  | `relayHistory()` | `Promise<Response<RelayHistoryResponse>>` | List relayed transactions |
216
+ | `setNetwork(network)` | `void` | Switch active network (mainnet/testnet) |
217
+ | `getNetwork()` | `"mainnet" \| "testnet"` | Get currently active network |
218
+ | `getSupportedNetworks()` | `("mainnet" \| "testnet")[]` | List supported networks |
219
+ | `getRecipient(network?)` | `string` | Get configured recipient for a network |
212
220
  | `client` | `Near` | Access near-kit Near instance (throws on server) |
213
221
 
214
222
  ### authClient.signIn
@@ -6,9 +6,10 @@ description: >
6
6
  gas/deposit limits, check relay status and history, and use the contract view
7
7
  endpoint. Load when setting up relayer config, debugging relay failures, or
8
8
  configuring RotatingKeyStore for high-throughput relay.
9
- type: core
10
- library: better-near-auth
11
- library_version: "1.6.3"
9
+ metadata:
10
+ type: core
11
+ library: better-near-auth
12
+ library_version: "1.6.5"
12
13
  sources:
13
14
  - "elliotBraem/better-near-auth:src/index.ts"
14
15
  - "elliotBraem/better-near-auth:src/utils.ts"
@@ -139,7 +140,7 @@ View calls are read-only, authenticated, and executed server-side.
139
140
  | ------ | ---- | ----------- |
140
141
  | POST | `/near/relay` | Relay a signed delegate action on-chain |
141
142
  | GET | `/near/relay-status/:txHash` | Check relayed transaction status |
142
- | GET | `/near/relayer-info` | Get relayer accountId, mode, balance |
143
+ | POST | `/near/relayer-info` | Get relayer accountId, mode, balance |
143
144
  | GET | `/near/relay-history` | List relayed transactions for current user |
144
145
  | POST | `/near/view` | Server-side read-only contract call |
145
146
 
@@ -284,12 +285,4 @@ The ephemeral relayer encrypts its private key using HKDF-SHA256 derived from `B
284
285
 
285
286
  Source: src/utils.ts:21-41, src/index.ts:134
286
287
 
287
- ### HIGH Tension: Ephemeral simplicity vs production reliability
288
288
 
289
- Ephemeral mode is zero-config but requires funding an implicit account with no human-readable name. Explicit mode uses a named, pre-funded account but requires managing private keys securely. Agents optimizing for setup simplicity may default to ephemeral without warning about the funding requirement, or use explicit mode with the private key hardcoded instead of using environment variables.
290
-
291
- See also: client/SKILL.md — delegate action building pattern
292
-
293
- ### HIGH Tension: Whitelist security vs development flexibility
294
-
295
- Strict `whitelistedContracts` prevents relay abuse but blocks calls to new contracts during development. Omitting the whitelist enables any contract call at the relayer's expense. Agents may copy quickstart examples without `whitelistedContracts` into production code, or add overly permissive whitelists that defeat the security purpose.
@@ -6,9 +6,10 @@ description: >
6
6
  account linking and unlinking, and NEAR profile lookup. Load when adding
7
7
  NEAR wallet sign-in to a Better Auth server, configuring siwn() plugin options,
8
8
  or debugging NEP-413 verify or nonce issues.
9
- type: core
10
- library: better-near-auth
11
- library_version: "1.6.3"
9
+ metadata:
10
+ type: core
11
+ library: better-near-auth
12
+ library_version: "1.6.5"
12
13
  sources:
13
14
  - "elliotBraem/better-near-auth:src/index.ts"
14
15
  - "elliotBraem/better-near-auth:src/profile.ts"
@@ -122,6 +123,7 @@ You cannot unlink the last authentication method — link another account first.
122
123
  | POST | `/near/link-account` | Link NEAR account to session |
123
124
  | POST | `/near/unlink-account` | Unlink NEAR account |
124
125
  | GET | `/near/list-accounts` | List linked NEAR accounts |
126
+ | POST | `/near/set-primary-account` | Set primary linked NEAR account |
125
127
 
126
128
  ## Plugin Options
127
129
 
@@ -135,6 +137,8 @@ You cannot unlink the last authentication method — link another account first.
135
137
  | `apiKey` | `string` | `process.env.FASTNEAR_API_KEY` | API key for RPC |
136
138
  | `rpcUrl` | `string` | — | Custom RPC URL |
137
139
  | `relayer` | `RelayerConfig` | — | See relay skill |
140
+ | `recipients` | `DualNetworkConfig<string>` | — | Per-network recipient (overrides `recipient` for mainnet/testnet) |
141
+ | `subAccount` | `SubAccountConfig \| DualNetworkConfig<SubAccountConfig>` | — | Sub-account configuration for delegated account creation |
138
142
 
139
143
  ## Email Handling
140
144
 
@@ -7,12 +7,13 @@ description: >
7
7
  Load when scaffolding a new TanStack Router app with better-near-auth,
8
8
  wiring auth into router context, or debugging wallet state loss after
9
9
  sign-in in SSR/CSR TanStack apps.
10
- type: framework
11
10
  requires:
12
11
  - client
13
12
  - siwn
14
- library: better-near-auth
15
- library_version: "1.6.3"
13
+ metadata:
14
+ type: framework
15
+ library: better-near-auth
16
+ library_version: "1.6.5"
16
17
  sources:
17
18
  - "elliotBraem/better-near-auth:src/client.ts"
18
19
  - "elliotBraem/better-near-auth:examples/auth.everything.dev/ui/src/lib/auth.ts"
@@ -235,6 +236,8 @@ Methods that throw on server: `buildSignedDelegateAction`, `ensureConnected`, `s
235
236
 
236
237
  Properties that return defaults on server: `getAccountId()` → `null`, `getState()` → `null`, `isWalletConnected()` → `false`.
237
238
 
239
+ See also: siwn/SKILL.md — server-side plugin options such as `recipient`, `requireFullAccessKey`, and custom profile/access key validation
240
+
238
241
  ## File Consolidation
239
242
 
240
243
  Replace three separate files with one `auth.ts`: