better-near-auth 1.8.2 → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +82 -7
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +10 -0
- package/dist/client.js.map +1 -1
- package/dist/index.d.ts +15 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +53 -18
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/skills/auth-plugin/SKILL.md +171 -34
- package/skills/client/SKILL.md +1 -1
- package/skills/relay/SKILL.md +101 -12
- package/skills/siwn/SKILL.md +1 -1
- package/skills/subaccount/SKILL.md +4 -1
- package/skills/tanstack/SKILL.md +8 -6
package/README.md
CHANGED
|
@@ -44,15 +44,45 @@ npm install better-near-auth
|
|
|
44
44
|
siwn({
|
|
45
45
|
recipient: "myapp.com",
|
|
46
46
|
|
|
47
|
-
// Optional: enable gasless relay
|
|
48
|
-
relayer:
|
|
49
|
-
whitelistedContracts: ["myapp.near"],
|
|
50
|
-
},
|
|
47
|
+
// Optional: enable gasless relay (ephemeral mode by default)
|
|
48
|
+
relayer: true,
|
|
51
49
|
}),
|
|
52
50
|
],
|
|
53
51
|
});
|
|
54
52
|
```
|
|
55
53
|
|
|
54
|
+
**Relayer Configuration Options:**
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
// Ephemeral mode (default) - auto-generated keypair
|
|
58
|
+
relayer: true
|
|
59
|
+
|
|
60
|
+
// Ephemeral with custom settings
|
|
61
|
+
relayer: {
|
|
62
|
+
whitelistedContracts: ["myapp.near"],
|
|
63
|
+
maxGasPerTransaction: "300000000000000",
|
|
64
|
+
maxDepositPerTransaction: "0",
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Explicit mode - bring your own key
|
|
68
|
+
relayer: {
|
|
69
|
+
accountId: "relayer.myapp.near",
|
|
70
|
+
privateKey: process.env.RELAYER_PRIVATE_KEY,
|
|
71
|
+
whitelistedContracts: ["myapp.near"],
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Per-network configuration
|
|
75
|
+
relayer: {
|
|
76
|
+
mainnet: {
|
|
77
|
+
whitelistedContracts: ["myapp.near"],
|
|
78
|
+
},
|
|
79
|
+
testnet: {
|
|
80
|
+
whitelistedContracts: ["myapp.testnet"],
|
|
81
|
+
maxGasPerTransaction: "100000000000000", // lower for testing
|
|
82
|
+
},
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
56
86
|
3. Generate the schema to add the necessary fields and tables to the database.
|
|
57
87
|
|
|
58
88
|
```bash
|
|
@@ -183,15 +213,42 @@ await authClient.near.disconnect();
|
|
|
183
213
|
|
|
184
214
|
#### Relayer Configuration
|
|
185
215
|
|
|
216
|
+
The relayer can be configured in several ways:
|
|
217
|
+
|
|
218
|
+
| Value | Mode | Description |
|
|
219
|
+
|---|---|---|
|
|
220
|
+
| `true` | Ephemeral | Auto-generated ED25519 keypair (default) |
|
|
221
|
+
| `RelayerEphemeralConfig` | Ephemeral | Ephemeral with custom settings |
|
|
222
|
+
| `RelayerExplicitConfig` | Explicit | Bring your own key |
|
|
223
|
+
| `RelayerDualNetworkConfig` | Mixed | Per-network configuration |
|
|
224
|
+
|
|
225
|
+
**Ephemeral Config (`RelayerEphemeralConfig`):**
|
|
226
|
+
|
|
227
|
+
| Option | Type | Default | Description |
|
|
228
|
+
|---|---|---|---|
|
|
229
|
+
| `whitelistedContracts` | `string[]` | — | Restrict relay to these contracts |
|
|
230
|
+
| `maxGasPerTransaction` | `string` | — | Max gas per relayed tx |
|
|
231
|
+
| `maxDepositPerTransaction` | `string` | — | Max deposit per relayed tx |
|
|
232
|
+
|
|
233
|
+
**Explicit Config (`RelayerExplicitConfig`):**
|
|
234
|
+
|
|
186
235
|
| Option | Type | Default | Description |
|
|
187
236
|
|---|---|---|---|
|
|
188
|
-
| `accountId` | `string` | — | Named relayer account (
|
|
189
|
-
| `privateKey` | `string` | — | Base64 private key (
|
|
237
|
+
| `accountId` | `string` | — | Named relayer account (required) |
|
|
238
|
+
| `privateKey` | `string` | — | Base64 private key (required) |
|
|
239
|
+
| `privateKeys` | `string[]` | — | Multiple keys for rotation |
|
|
190
240
|
| `whitelistedContracts` | `string[]` | — | Restrict relay to these contracts |
|
|
191
241
|
| `maxGasPerTransaction` | `string` | — | Max gas per relayed tx |
|
|
192
242
|
| `maxDepositPerTransaction` | `string` | — | Max deposit per relayed tx |
|
|
193
243
|
|
|
194
|
-
|
|
244
|
+
**Dual Network Config (`RelayerDualNetworkConfig`):**
|
|
245
|
+
|
|
246
|
+
| Option | Type | Default | Description |
|
|
247
|
+
|---|---|---|---|
|
|
248
|
+
| `mainnet` | `RelayerEphemeralConfig \| RelayerExplicitConfig` | — | Mainnet relayer config |
|
|
249
|
+
| `testnet` | `RelayerEphemeralConfig \| RelayerExplicitConfig` | — | Testnet relayer config |
|
|
250
|
+
|
|
251
|
+
When using `relayer: true` or ephemeral config (no `accountId`/`privateKey`), an ED25519 keypair is generated on first startup, the implicit account ID is derived from the public key, and the private key is encrypted with AES-256-GCM (using `BETTER_AUTH_SECRET` as KEK via HKDF-SHA256) and stored in the database. The same keypair is recovered on restart.
|
|
195
252
|
|
|
196
253
|
### Client Options
|
|
197
254
|
|
|
@@ -332,6 +389,10 @@ export const auth = betterAuth({
|
|
|
332
389
|
|
|
333
390
|
apiKey: process.env.FASTNEAR_API_KEY,
|
|
334
391
|
|
|
392
|
+
// Ephemeral mode (simplest)
|
|
393
|
+
relayer: true,
|
|
394
|
+
|
|
395
|
+
// OR explicit mode
|
|
335
396
|
relayer: {
|
|
336
397
|
accountId: "relayer.myapp.near",
|
|
337
398
|
privateKey: process.env.RELAYER_PRIVATE_KEY,
|
|
@@ -339,6 +400,17 @@ export const auth = betterAuth({
|
|
|
339
400
|
maxGasPerTransaction: "300000000000000",
|
|
340
401
|
maxDepositPerTransaction: "0",
|
|
341
402
|
},
|
|
403
|
+
|
|
404
|
+
// OR per-network configuration
|
|
405
|
+
relayer: {
|
|
406
|
+
mainnet: {
|
|
407
|
+
whitelistedContracts: ["myapp.near"],
|
|
408
|
+
},
|
|
409
|
+
testnet: {
|
|
410
|
+
whitelistedContracts: ["myapp.testnet"],
|
|
411
|
+
maxGasPerTransaction: "100000000000000",
|
|
412
|
+
},
|
|
413
|
+
},
|
|
342
414
|
}),
|
|
343
415
|
],
|
|
344
416
|
});
|
|
@@ -378,6 +450,9 @@ The plugin detects the network from the account ID:
|
|
|
378
450
|
| "Network ID mismatch" | Ensure networkId matches the account's network |
|
|
379
451
|
| Relay fails with "insufficient balance" | Fund the relayer account with NEAR |
|
|
380
452
|
| Relay fails with "contract not whitelisted" | Add `receiverId` to `whitelistedContracts` |
|
|
453
|
+
| Relayer not initializing (ephemeral mode) | Ensure `BETTER_AUTH_SECRET` is set; check startup logs for `[siwn] Relayer initialized` |
|
|
454
|
+
| Empty `relayer_key` table | Relayer config not being passed; use `relayer: true` or provide config object |
|
|
455
|
+
| "BETTER_AUTH_SECRET required" error | Required for ephemeral mode encryption; generate a secure random string |
|
|
381
456
|
|
|
382
457
|
## Examples
|
|
383
458
|
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwC,kBAAkB,EAAE,MAAM,UAAU,CAAC;AACpF,OAAO,KAAK,EAAE,IAAI,IAAI,QAAQ,EAAiB,MAAM,UAAU,CAAC;AAGhE,OAAO,KAAK,EAAE,WAAW,EAAqB,mBAAmB,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAE3G,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,iBAAiB,EAAE,KAAK,aAAa,EAAE,KAAK,cAAc,EAAE,KAAK,gBAAgB,EAAE,KAAK,cAAc,EAAE,KAAK,eAAe,EAAE,KAAK,cAAc,EAAE,KAAK,oBAAoB,EAAoB,KAAK,qBAAqB,EAAE,KAAK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C;QACtD,YAAY,EAAE,CAAC,OAAO,CAAC,EAAE,SAAS,GAAG,SAAS,KAAK,MAAM,CAAC;QAC1D,aAAa,EAAE,MAAM,QAAQ,CAAC;KAC9B,CAAC;IACF,MAAM,EAAE;QACP,IAAI,EAAE,CAAC,SAAS,CAAC,EAAE,aAAa,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;KACnD,CAAC;CACF;AAED,KAAK,SAAS,GAAG;IAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAAC;AAElG,eAAO,MAAM,UAAU,GAAI,QAAQ,gBAAgB;;;wBAqS7B,WAAW;;;;;yBAMV,WAAW,UAAU,WAAW,YAAY,OAAO,KAAG,iBAAiB;CA6R7F,CAAC"}
|
package/dist/client.js
CHANGED
|
@@ -373,6 +373,15 @@ const siwnClient = (config) => {
|
|
|
373
373
|
}),
|
|
374
374
|
getActions: ($fetch, $store, _options) => {
|
|
375
375
|
initClient($fetch);
|
|
376
|
+
const sessionAtom = $store.atoms?.session;
|
|
377
|
+
if (sessionAtom) sessionAtom.subscribe(() => {
|
|
378
|
+
if ((sessionAtom.get()?.data ?? null) === null) {
|
|
379
|
+
for (const [_net, conn] of connectors) conn?.disconnect().catch(() => {});
|
|
380
|
+
walletConnected.set(false);
|
|
381
|
+
nearState.set(null);
|
|
382
|
+
sessionRestored = false;
|
|
383
|
+
}
|
|
384
|
+
});
|
|
376
385
|
return {
|
|
377
386
|
near: {
|
|
378
387
|
nonce: async (params, fetchOptions) => {
|
|
@@ -455,6 +464,7 @@ const siwnClient = (config) => {
|
|
|
455
464
|
} catch {}
|
|
456
465
|
walletConnected.set(false);
|
|
457
466
|
nearState.set(null);
|
|
467
|
+
sessionRestored = false;
|
|
458
468
|
},
|
|
459
469
|
link: async (callbacks) => {
|
|
460
470
|
const net = activeNetwork.get();
|
package/dist/client.js.map
CHANGED
|
@@ -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, Near, TransactionBuilder } 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 SubAccountTxCtx {\n\tnewAccountId: string;\n\tparentAccount: string;\n\tuserPublicKey: string;\n\tuserAccountId: string;\n\tuserId: string;\n\tnetwork: \"mainnet\" | \"testnet\";\n}\n\nexport interface SubAccountLifecycleCtx extends SubAccountTxCtx {\n\tnear: Near;\n}\n\nexport interface SubAccountConfig {\n\tparentAccount?: string;\n\tminDeposit?: string;\n\tparentHasFullAccess?: boolean;\n\tdeploy?:\n\t\t| { wasm: Uint8Array }\n\t\t| { fromPublished: { accountId?: string; codeHash?: string } };\n\tinit?: {\n\t\tmethodName: string;\n\t\targs: object | ((ctx: SubAccountTxCtx) => object);\n\t};\n\textendTx?: (tx: TransactionBuilder, ctx: SubAccountTxCtx) => TransactionBuilder;\n\tonCreated?: (ctx: SubAccountLifecycleCtx) => Promise<void>;\n\tonRollback?: (ctx: SubAccountLifecycleCtx) => Promise<void>;\n\taddRelayerFCAK?: boolean;\n\trelayerFCAK?: SubAccountRelayerFCAKConfig;\n}\n\nexport const SUB_ACCOUNT_LABEL_REGEX = /^([a-z\\d]+[-_])*[a-z\\d]+$/;\n\nexport const SubAccountNameSchema = z\n\t.string()\n\t.min(2, \"Sub-account name must be at least 2 characters\")\n\t.max(64, \"Sub-account name must be at most 64 characters\")\n\t.regex(SUB_ACCOUNT_LABEL_REGEX, \"Sub-account name must contain only lowercase alphanumeric characters, hyphens, and underscores (no leading/trailing hyphens or underscores)\");\n\nexport const CreateSubAccountRequest = z.object({\n\tsubAccountName: SubAccountNameSchema,\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: SubAccountNameSchema,\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\tparentAccount: z.string().optional(),\n\treason: z.enum([\"taken\", \"invalid\", \"too-long\", \"not-configured\"]).optional(),\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 { BetterFetch, BetterFetchOption, BetterFetchResponse, ClientStore } from \"better-auth/client\";\nimport { atom } from \"nanostores\";\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, SUB_ACCOUNT_LABEL_REGEX } 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\tdetectNearAccount: () => Promise<{ accountId: string; publicKey: string | null; networkId: string } | null>;\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\tgetNearClient: () => NearType;\n\t};\n\tsignIn: {\n\t\tnear: (callbacks?: AuthCallbacks) => Promise<void>;\n\t};\n}\n\ntype NearState = { accountId: string | null; publicKey: string | null; networkId: string } | null;\n\nexport const siwnClient = (config: SIWNClientConfig) => {\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 = {\n\t\tid: \"siwn\" as const,\n\t\t$InferServerPlugin: {},\n\n\t\tgetAtoms: (_$fetch: BetterFetch) => ({\n\t\t\tnearState,\n\t\t\twalletConnected,\n\t\t\tactiveNetwork,\n\t\t}),\n\n\t\tgetActions: ($fetch: BetterFetch, $store: ClientStore, _options: unknown): 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\tdetectNearAccount: async () => {\n\t\t\t\t\t\tconst state = nearState.get();\n\t\t\t\t\t\tif (state?.accountId && walletConnected.get()) {\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\taccountId: state.accountId,\n\t\t\t\t\t\t\t\tpublicKey: state.publicKey ?? null,\n\t\t\t\t\t\t\t\tnetworkId: state.networkId,\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t}\n\t\t\t\t\t\tfor (const network of getSupportedNetworks()) {\n\t\t\t\t\t\t\tconst initialized = await initClientForNetwork(network);\n\t\t\t\t\t\t\tif (!initialized) continue;\n\t\t\t\t\t\t\tconst conn = connectors.get(network);\n\t\t\t\t\t\t\tif (!conn) continue;\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tconst { accounts } = await conn.getConnectedWallet();\n\t\t\t\t\t\t\t\tif (accounts?.length) {\n\t\t\t\t\t\t\t\t\tconst account = accounts[0]!;\n\t\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t\taccountId: account.accountId,\n\t\t\t\t\t\t\t\t\t\tpublicKey: account.publicKey ?? null,\n\t\t\t\t\t\t\t\t\t\tnetworkId: network,\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} catch {}\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t},\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\t$store.notify(\"$sessionSignal\");\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 ?? {}), network: params?.network ?? activeNetwork.get() },\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, network: params.network ?? activeNetwork.get() },\n\t\t\t\t\t\t});\n\t\t\t\t\t},\n\t\t\t\tcheckSubAccountAvailability: async (params: CheckSubAccountAvailabilityRequestT) => {\n\t\t\t\t\tif (!SUB_ACCOUNT_LABEL_REGEX.test(params.subAccountName) || params.subAccountName.length < 2) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tdata: { available: false, accountId: \"\", reason: \"invalid\" as const },\n\t\t\t\t\t\t\terror: null,\n\t\t\t\t\t\t} as BetterFetchResponse<CheckSubAccountAvailabilityResponseT>;\n\t\t\t\t\t}\n\t\t\t\t\treturn await $fetch(\"/near/check-sub-account-availability\", {\n\t\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\t\tbody: { ...params, network: params.network ?? activeNetwork.get() },\n\t\t\t\t\t});\n\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\tgetNearClient: (): 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\t$store.notify(\"$sessionSignal\");\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,eAAe;CACf,SAAS,EAAE,OAAO;CAClB,WAAW,EAAE,OAAO;CACpB,OAAO,EAAE,OAAO;CAChB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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;MACvB,OAAO,OAAO,gBAAgB;KAC/B,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, Near, TransactionBuilder } 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 SubAccountTxCtx {\n\tnewAccountId: string;\n\tparentAccount: string;\n\tuserPublicKey: string;\n\tuserAccountId: string;\n\tuserId: string;\n\tnetwork: \"mainnet\" | \"testnet\";\n}\n\nexport interface SubAccountLifecycleCtx extends SubAccountTxCtx {\n\tnear: Near;\n}\n\nexport interface SubAccountConfig {\n\tparentAccount?: string;\n\tminDeposit?: string;\n\tparentHasFullAccess?: boolean;\n\tdeploy?:\n\t\t| { wasm: Uint8Array }\n\t\t| { fromPublished: { accountId?: string; codeHash?: string } };\n\tinit?: {\n\t\tmethodName: string;\n\t\targs: object | ((ctx: SubAccountTxCtx) => object);\n\t};\n\textendTx?: (tx: TransactionBuilder, ctx: SubAccountTxCtx) => TransactionBuilder;\n\tonCreated?: (ctx: SubAccountLifecycleCtx) => Promise<void>;\n\tonRollback?: (ctx: SubAccountLifecycleCtx) => Promise<void>;\n\taddRelayerFCAK?: boolean;\n\trelayerFCAK?: SubAccountRelayerFCAKConfig;\n}\n\nexport const SUB_ACCOUNT_LABEL_REGEX = /^([a-z\\d]+[-_])*[a-z\\d]+$/;\n\nexport const SubAccountNameSchema = z\n\t.string()\n\t.min(2, \"Sub-account name must be at least 2 characters\")\n\t.max(64, \"Sub-account name must be at most 64 characters\")\n\t.regex(SUB_ACCOUNT_LABEL_REGEX, \"Sub-account name must contain only lowercase alphanumeric characters, hyphens, and underscores (no leading/trailing hyphens or underscores)\");\n\nexport const CreateSubAccountRequest = z.object({\n\tsubAccountName: SubAccountNameSchema,\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: SubAccountNameSchema,\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\tparentAccount: z.string().optional(),\n\treason: z.enum([\"taken\", \"invalid\", \"too-long\", \"not-configured\"]).optional(),\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 { BetterFetch, BetterFetchOption, BetterFetchResponse, ClientStore } from \"better-auth/client\";\nimport { atom } from \"nanostores\";\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, SUB_ACCOUNT_LABEL_REGEX } 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\tdetectNearAccount: () => Promise<{ accountId: string; publicKey: string | null; networkId: string } | null>;\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\tgetNearClient: () => NearType;\n\t};\n\tsignIn: {\n\t\tnear: (callbacks?: AuthCallbacks) => Promise<void>;\n\t};\n}\n\ntype NearState = { accountId: string | null; publicKey: string | null; networkId: string } | null;\n\nexport const siwnClient = (config: SIWNClientConfig) => {\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 = {\n\t\tid: \"siwn\" as const,\n\t\t$InferServerPlugin: {},\n\n\t\tgetAtoms: (_$fetch: BetterFetch) => ({\n\t\t\tnearState,\n\t\t\twalletConnected,\n\t\t\tactiveNetwork,\n\t\t}),\n\n\t\tgetActions: ($fetch: BetterFetch, $store: ClientStore, _options: unknown): SIWNClientActions => {\n\t\t\tvoid initClient($fetch);\n\n\t\t\tconst sessionAtom = $store.atoms?.session;\n\t\t\tif (sessionAtom) {\n\t\t\t\tsessionAtom.subscribe(() => {\n\t\t\t\t\tconst sessionData = sessionAtom.get()?.data ?? null;\n\t\t\t\t\tif (sessionData === null) {\n\t\t\t\t\t\tfor (const [_net, conn] of connectors) {\n\t\t\t\t\t\t\tvoid conn?.disconnect().catch(() => {});\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\tsessionRestored = false;\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\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\tdetectNearAccount: async () => {\n\t\t\t\t\t\tconst state = nearState.get();\n\t\t\t\t\t\tif (state?.accountId && walletConnected.get()) {\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\taccountId: state.accountId,\n\t\t\t\t\t\t\t\tpublicKey: state.publicKey ?? null,\n\t\t\t\t\t\t\t\tnetworkId: state.networkId,\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t}\n\t\t\t\t\t\tfor (const network of getSupportedNetworks()) {\n\t\t\t\t\t\t\tconst initialized = await initClientForNetwork(network);\n\t\t\t\t\t\t\tif (!initialized) continue;\n\t\t\t\t\t\t\tconst conn = connectors.get(network);\n\t\t\t\t\t\t\tif (!conn) continue;\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tconst { accounts } = await conn.getConnectedWallet();\n\t\t\t\t\t\t\t\tif (accounts?.length) {\n\t\t\t\t\t\t\t\t\tconst account = accounts[0]!;\n\t\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t\taccountId: account.accountId,\n\t\t\t\t\t\t\t\t\t\tpublicKey: account.publicKey ?? null,\n\t\t\t\t\t\t\t\t\t\tnetworkId: network,\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} catch {}\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t},\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\tsessionRestored = false;\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\t$store.notify(\"$sessionSignal\");\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 ?? {}), network: params?.network ?? activeNetwork.get() },\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, network: params.network ?? activeNetwork.get() },\n\t\t\t\t\t\t});\n\t\t\t\t\t},\n\t\t\t\tcheckSubAccountAvailability: async (params: CheckSubAccountAvailabilityRequestT) => {\n\t\t\t\t\tif (!SUB_ACCOUNT_LABEL_REGEX.test(params.subAccountName) || params.subAccountName.length < 2) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tdata: { available: false, accountId: \"\", reason: \"invalid\" as const },\n\t\t\t\t\t\t\terror: null,\n\t\t\t\t\t\t} as BetterFetchResponse<CheckSubAccountAvailabilityResponseT>;\n\t\t\t\t\t}\n\t\t\t\t\treturn await $fetch(\"/near/check-sub-account-availability\", {\n\t\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\t\tbody: { ...params, network: params.network ?? activeNetwork.get() },\n\t\t\t\t\t});\n\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\tgetNearClient: (): 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\t$store.notify(\"$sessionSignal\");\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,E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,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;MACvB,OAAO,OAAO,gBAAgB;KAC/B,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
|
@@ -2,14 +2,26 @@ import type { DBAdapter } from "better-auth/types";
|
|
|
2
2
|
import z from "zod";
|
|
3
3
|
import { type AccountId, type DualNetworkConfig, type ListAccountsResponseT, type ListedNearAccount, type Profile, type SubAccountConfig } from "./types.js";
|
|
4
4
|
export * from "./types.js";
|
|
5
|
-
|
|
6
|
-
accountId?:
|
|
7
|
-
privateKey?:
|
|
5
|
+
interface RelayerEphemeralConfig {
|
|
6
|
+
accountId?: never;
|
|
7
|
+
privateKey?: never;
|
|
8
|
+
whitelistedContracts?: string[];
|
|
9
|
+
maxGasPerTransaction?: string;
|
|
10
|
+
maxDepositPerTransaction?: string;
|
|
11
|
+
}
|
|
12
|
+
interface RelayerExplicitConfig {
|
|
13
|
+
accountId: string;
|
|
14
|
+
privateKey: string;
|
|
8
15
|
privateKeys?: string[];
|
|
9
16
|
whitelistedContracts?: string[];
|
|
10
17
|
maxGasPerTransaction?: string;
|
|
11
18
|
maxDepositPerTransaction?: string;
|
|
12
19
|
}
|
|
20
|
+
interface RelayerDualNetworkConfig {
|
|
21
|
+
mainnet?: RelayerEphemeralConfig | RelayerExplicitConfig;
|
|
22
|
+
testnet?: RelayerEphemeralConfig | RelayerExplicitConfig;
|
|
23
|
+
}
|
|
24
|
+
export type RelayerConfig = true | RelayerEphemeralConfig | RelayerExplicitConfig | RelayerDualNetworkConfig;
|
|
13
25
|
export interface SIWNPluginOptions {
|
|
14
26
|
recipient?: string;
|
|
15
27
|
recipients?: DualNetworkConfig<string>;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -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,EAqBrB,MAAM,YAAY,CAAC;AACpB,cAAc,YAAY,CAAC;AA8D3B,MAAM,
|
|
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,EAqBrB,MAAM,YAAY,CAAC;AACpB,cAAc,YAAY,CAAC;AA8D3B,UAAU,sBAAsB;IAC/B,SAAS,CAAC,EAAE,KAAK,CAAC;IAClB,UAAU,CAAC,EAAE,KAAK,CAAC;IACnB,oBAAoB,CAAC,EAAE,MAAM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;iCAEV,CAAC;;;;;;;;;6BAQ4B,CAAC;;;;;;;;;;;;;;;;;;;iCAVrB,CAAC;iCAEV,CAAC;;;;;;;;;6BAQ4B,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;iCAVrB,CAAC;iCAEV,CAAC;;;;;;;;;6BAQ4B,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iCAVrB,CAAC;iCAEV,CAAC;;;;;;;;;6BAQ4B,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iCAVrB,CAAC;iCAEV,CAAC;;;;;;;;;6BAQ4B,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;iCAVrB,CAAC;iCAEV,CAAC;;;;;;;;;6BAQ4B,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iCAVrB,CAAC;iCAEV,CAAC;;;;;;;;;6BAQ4B,CAAC;;;;;;;;;;;CAgkDpC,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -376,19 +376,29 @@ async function initRelayer(relayerConfig, network, adapter, secret, apiKey, rpcU
|
|
|
376
376
|
if (!relayerConfig) return null;
|
|
377
377
|
const headers = {};
|
|
378
378
|
if (apiKey) headers["Authorization"] = `Bearer ${apiKey}`;
|
|
379
|
-
|
|
380
|
-
|
|
379
|
+
let networkConfig;
|
|
380
|
+
if (relayerConfig === true) networkConfig = {};
|
|
381
|
+
else if ("mainnet" in relayerConfig || "testnet" in relayerConfig) {
|
|
382
|
+
const dualConfig = relayerConfig;
|
|
383
|
+
networkConfig = network === "mainnet" ? dualConfig.mainnet : dualConfig.testnet;
|
|
384
|
+
if (!networkConfig) return null;
|
|
385
|
+
} else networkConfig = relayerConfig;
|
|
386
|
+
if ("accountId" in networkConfig && networkConfig.accountId && (networkConfig.privateKey || networkConfig.privateKeys)) {
|
|
387
|
+
const keys = networkConfig.privateKeys ?? (networkConfig.privateKey ? [networkConfig.privateKey] : []);
|
|
381
388
|
let keyStore;
|
|
382
|
-
if (keys.length === 1) keyStore = new InMemoryKeyStore({ [
|
|
383
|
-
else keyStore = new RotatingKeyStore({ [
|
|
389
|
+
if (keys.length === 1) keyStore = new InMemoryKeyStore({ [networkConfig.accountId]: keys[0] });
|
|
390
|
+
else keyStore = new RotatingKeyStore({ [networkConfig.accountId]: keys });
|
|
384
391
|
const near = createNear(network, headers, rpcUrl, keyStore);
|
|
385
392
|
const explicitPublicKey = parseKey(keys[0]);
|
|
386
393
|
return {
|
|
387
394
|
near,
|
|
388
|
-
accountId:
|
|
395
|
+
accountId: networkConfig.accountId,
|
|
389
396
|
network,
|
|
390
397
|
mode: "explicit",
|
|
391
|
-
publicKey: explicitPublicKey.publicKey.toString()
|
|
398
|
+
publicKey: explicitPublicKey.publicKey.toString(),
|
|
399
|
+
whitelistedContracts: networkConfig.whitelistedContracts,
|
|
400
|
+
maxGasPerTransaction: networkConfig.maxGasPerTransaction,
|
|
401
|
+
maxDepositPerTransaction: networkConfig.maxDepositPerTransaction
|
|
392
402
|
};
|
|
393
403
|
}
|
|
394
404
|
const existing = await adapter.findOne({
|
|
@@ -413,6 +423,9 @@ async function initRelayer(relayerConfig, network, adapter, secret, apiKey, rpcU
|
|
|
413
423
|
network,
|
|
414
424
|
mode: "ephemeral",
|
|
415
425
|
publicKey: keyPair.publicKey.toString(),
|
|
426
|
+
whitelistedContracts: networkConfig.whitelistedContracts,
|
|
427
|
+
maxGasPerTransaction: networkConfig.maxGasPerTransaction,
|
|
428
|
+
maxDepositPerTransaction: networkConfig.maxDepositPerTransaction,
|
|
416
429
|
createdAt: existing.createdAt,
|
|
417
430
|
lastUsedAt: existing.lastUsedAt
|
|
418
431
|
};
|
|
@@ -447,6 +460,9 @@ async function initRelayer(relayerConfig, network, adapter, secret, apiKey, rpcU
|
|
|
447
460
|
network,
|
|
448
461
|
mode: "ephemeral",
|
|
449
462
|
publicKey: keyPair.publicKey.toString(),
|
|
463
|
+
whitelistedContracts: networkConfig.whitelistedContracts,
|
|
464
|
+
maxGasPerTransaction: networkConfig.maxGasPerTransaction,
|
|
465
|
+
maxDepositPerTransaction: networkConfig.maxDepositPerTransaction,
|
|
450
466
|
createdAt,
|
|
451
467
|
lastUsedAt: createdAt
|
|
452
468
|
};
|
|
@@ -494,7 +510,8 @@ const siwn = (options) => {
|
|
|
494
510
|
};
|
|
495
511
|
const getRelayerConfig = (network) => {
|
|
496
512
|
if (!options.relayer) return void 0;
|
|
497
|
-
if (
|
|
513
|
+
if (options.relayer === true) return true;
|
|
514
|
+
if ("mainnet" in options.relayer || "testnet" in options.relayer) return options.relayer[network];
|
|
498
515
|
return options.relayer;
|
|
499
516
|
};
|
|
500
517
|
const getRpcUrl = (network) => {
|
|
@@ -516,8 +533,12 @@ const siwn = (options) => {
|
|
|
516
533
|
const fromSecrets = getParentKey(network);
|
|
517
534
|
if (fromSecrets) return fromSecrets;
|
|
518
535
|
const relayerCfg = getRelayerConfig(network);
|
|
519
|
-
const
|
|
520
|
-
if (
|
|
536
|
+
const subAccountCfg = getSubAccountConfig(network);
|
|
537
|
+
if (!relayerCfg || relayerCfg === true) return void 0;
|
|
538
|
+
if ("mainnet" in relayerCfg || "testnet" in relayerCfg) return void 0;
|
|
539
|
+
const explicitCfg = relayerCfg;
|
|
540
|
+
const parent = subAccountCfg?.parentAccount ?? explicitCfg.accountId;
|
|
541
|
+
if (parent && parent === explicitCfg.accountId) return explicitCfg.privateKey ?? explicitCfg.privateKeys?.[0];
|
|
521
542
|
};
|
|
522
543
|
const primaryNetwork = getSupportedNetworks()[0];
|
|
523
544
|
const relayerStates = /* @__PURE__ */ new Map();
|
|
@@ -528,12 +549,21 @@ const siwn = (options) => {
|
|
|
528
549
|
if (relayerStates.has(network)) return relayerStates.get(network) ?? null;
|
|
529
550
|
const existingInit = relayerInitPromises.get(network);
|
|
530
551
|
if (existingInit) return existingInit;
|
|
531
|
-
const
|
|
552
|
+
const relayerCfg = getRelayerConfig(network);
|
|
553
|
+
const initPromise = initRelayer(relayerCfg, network, adapter, secret, apiKey, getRpcUrl(network)).then((state) => {
|
|
532
554
|
relayerStates.set(network, state);
|
|
533
555
|
relayerInitPromises.delete(network);
|
|
556
|
+
if (state) {
|
|
557
|
+
console.log(`[siwn] Relayer initialized: ${state.accountId} (${network}, ${state.mode})`);
|
|
558
|
+
if (state.mode === "ephemeral") {
|
|
559
|
+
console.log(`[siwn] Fund this account with NEAR to enable gasless relay`);
|
|
560
|
+
console.log(`[siwn] Private key is encrypted in DB — persists across restarts`);
|
|
561
|
+
}
|
|
562
|
+
} else if (relayerCfg) console.warn(`[siwn] Relayer config provided but not initialized for ${network}. Check BETTER_AUTH_SECRET for ephemeral mode.`);
|
|
534
563
|
return state;
|
|
535
564
|
}).catch((error) => {
|
|
536
565
|
relayerInitPromises.delete(network);
|
|
566
|
+
console.error(`[siwn] Failed to initialize relayer for ${network}:`, error);
|
|
537
567
|
throw error;
|
|
538
568
|
});
|
|
539
569
|
relayerInitPromises.set(network, initPromise);
|
|
@@ -1148,29 +1178,34 @@ const siwn = (options) => {
|
|
|
1148
1178
|
status: 401
|
|
1149
1179
|
});
|
|
1150
1180
|
const relayerConfigForNetwork = getRelayerConfig(network);
|
|
1151
|
-
|
|
1152
|
-
|
|
1181
|
+
const isDualNetwork = relayerConfigForNetwork && typeof relayerConfigForNetwork === "object" && ("mainnet" in relayerConfigForNetwork || "testnet" in relayerConfigForNetwork);
|
|
1182
|
+
const configWithLimits = relayerConfigForNetwork && typeof relayerConfigForNetwork === "object" && !isDualNetwork ? relayerConfigForNetwork : void 0;
|
|
1183
|
+
const whitelistedContracts = configWithLimits?.whitelistedContracts;
|
|
1184
|
+
if (whitelistedContracts?.length) {
|
|
1185
|
+
if (!whitelistedContracts.includes(delegateAction.receiverId)) throw new APIError("FORBIDDEN", {
|
|
1153
1186
|
message: `Contract ${delegateAction.receiverId} is not whitelisted for relay`,
|
|
1154
1187
|
status: 403
|
|
1155
1188
|
});
|
|
1156
1189
|
}
|
|
1157
|
-
|
|
1190
|
+
const maxGasPerTransaction = configWithLimits?.maxGasPerTransaction;
|
|
1191
|
+
if (maxGasPerTransaction) {
|
|
1158
1192
|
const totalGas = delegateAction.actions.reduce((sum, a) => {
|
|
1159
1193
|
return sum + ("functionCall" in a ? a.functionCall.gas : 0n);
|
|
1160
1194
|
}, 0n);
|
|
1161
|
-
if (totalGas > BigInt(
|
|
1162
|
-
message: `Transaction gas (${totalGas}) exceeds relayer limit (${
|
|
1195
|
+
if (totalGas > BigInt(maxGasPerTransaction)) throw new APIError("BAD_REQUEST", {
|
|
1196
|
+
message: `Transaction gas (${totalGas}) exceeds relayer limit (${maxGasPerTransaction})`,
|
|
1163
1197
|
status: 400
|
|
1164
1198
|
});
|
|
1165
1199
|
}
|
|
1166
|
-
|
|
1200
|
+
const maxDepositPerTransaction = configWithLimits?.maxDepositPerTransaction;
|
|
1201
|
+
if (maxDepositPerTransaction) {
|
|
1167
1202
|
const totalDeposit = delegateAction.actions.reduce((sum, a) => {
|
|
1168
1203
|
if ("functionCall" in a) return sum + a.functionCall.deposit;
|
|
1169
1204
|
if ("transfer" in a) return sum + a.transfer.deposit;
|
|
1170
1205
|
return sum;
|
|
1171
1206
|
}, 0n);
|
|
1172
|
-
if (totalDeposit > BigInt(
|
|
1173
|
-
message: `Transaction deposit (${totalDeposit}) exceeds relayer limit (${
|
|
1207
|
+
if (totalDeposit > BigInt(maxDepositPerTransaction)) throw new APIError("BAD_REQUEST", {
|
|
1208
|
+
message: `Transaction deposit (${totalDeposit}) exceeds relayer limit (${maxDepositPerTransaction})`,
|
|
1174
1209
|
status: 400
|
|
1175
1210
|
});
|
|
1176
1211
|
}
|