better-near-auth 0.2.0 → 0.2.2
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 +1 -1
- package/package.json +5 -5
- package/src/client.ts +3 -3
- package/src/index.ts +6 -6
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
|
|
14
14
|
</div>
|
|
15
15
|
|
|
16
|
-
This [Better Auth](https://better-auth.com) plugin enables secure authentication via NEAR wallets and keypairs by following the [NEP-413 standard](https://github.com/near/NEPs/blob/master/neps/nep-0413.md). It leverages [near-sign-verify](https://github.com/elliotBraem/near-sign-verify) and [fastintear](https://github.com/elliotBraem/fastintear)
|
|
16
|
+
This [Better Auth](https://better-auth.com) plugin enables secure authentication via NEAR wallets and keypairs by following the [NEP-413 standard](https://github.com/near/NEPs/blob/master/neps/nep-0413.md). It leverages [near-sign-verify](https://github.com/elliotBraem/near-sign-verify) and [fastintear](https://github.com/elliotBraem/fastintear) to provide a complete drop-in solution with session management, secure defaults, and automatic profile integration.
|
|
17
17
|
|
|
18
18
|
## Installation
|
|
19
19
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "better-near-auth",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Sign in with NEAR (SIWN) plugin for Better Auth",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"module": "src/index.ts",
|
|
@@ -44,18 +44,18 @@
|
|
|
44
44
|
"homepage": "https://github.com/elliotBraem/better-near-auth#readme",
|
|
45
45
|
"peerDependencies": {
|
|
46
46
|
"better-auth": "^1.0.0",
|
|
47
|
-
"typescript": "^5.
|
|
47
|
+
"typescript": "^5.7.0"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"fastintear": "^0.3.
|
|
50
|
+
"fastintear": "^0.3.8",
|
|
51
51
|
"nanostores": "^1.0.1",
|
|
52
|
-
"near-sign-verify": "^0.4.
|
|
52
|
+
"near-sign-verify": "^0.4.4",
|
|
53
53
|
"zod": "^4.1.12"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@types/bun": "latest",
|
|
57
57
|
"@types/node": "^24.8.1",
|
|
58
|
-
"better-auth": "^1.3.
|
|
58
|
+
"better-auth": "^1.3.34",
|
|
59
59
|
"typescript": "^5.9.3",
|
|
60
60
|
"vitest": "^3.2.4"
|
|
61
61
|
},
|
package/src/client.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { base64ToBytes } from "fastintear/utils";
|
|
2
1
|
import type { BetterAuthClientPlugin, BetterFetch, BetterFetchOption, BetterFetchResponse } from "better-auth/client";
|
|
3
2
|
import { createNearClient } from "fastintear";
|
|
3
|
+
import { base64ToBytes } from "fastintear/utils";
|
|
4
4
|
import { atom } from "nanostores";
|
|
5
5
|
import { parseAuthToken, sign } from "near-sign-verify";
|
|
6
6
|
import type { siwn } from ".";
|
|
@@ -74,12 +74,12 @@ export const siwnClient = (config: SIWNClientConfig): SIWNClientPlugin => {
|
|
|
74
74
|
return {
|
|
75
75
|
id: "siwn",
|
|
76
76
|
$InferServerPlugin: {} as ReturnType<typeof siwn>,
|
|
77
|
-
|
|
77
|
+
|
|
78
78
|
getAtoms: ($fetch) => ({
|
|
79
79
|
nearState,
|
|
80
80
|
cachedNonce,
|
|
81
81
|
}),
|
|
82
|
-
|
|
82
|
+
|
|
83
83
|
getActions: ($fetch): SIWNClientActions => {
|
|
84
84
|
const nearClient = createNearClient({
|
|
85
85
|
networkId: config.networkId || "mainnet",
|
package/src/index.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { bytesToBase64 } from "fastintear/utils";
|
|
2
1
|
import { APIError, createAuthEndpoint, createAuthMiddleware, sessionMiddleware } from "better-auth/api";
|
|
3
2
|
import { setSessionCookie } from "better-auth/cookies";
|
|
4
3
|
import type { Account, BetterAuthPlugin, User } from "better-auth/types";
|
|
5
|
-
import {
|
|
4
|
+
import { bytesToBase64 } from "fastintear/utils";
|
|
5
|
+
import { generateNonce, verify, type VerificationResult, type VerifyOptions } from "near-sign-verify";
|
|
6
|
+
import z from "zod";
|
|
6
7
|
import { defaultGetProfile, getImageUrl, getNetworkFromAccountId } from "./profile";
|
|
7
8
|
import { schema } from "./schema";
|
|
8
9
|
import type {
|
|
@@ -18,7 +19,6 @@ import {
|
|
|
18
19
|
VerifyRequest,
|
|
19
20
|
VerifyResponse
|
|
20
21
|
} from "./types";
|
|
21
|
-
import z from "zod";
|
|
22
22
|
export * from "./types";
|
|
23
23
|
|
|
24
24
|
function getOrigin(baseURL: string): string {
|
|
@@ -84,7 +84,7 @@ export const siwn = (options: SIWNPluginOptions) =>
|
|
|
84
84
|
{ field: "isPrimary", operator: "eq", value: true },
|
|
85
85
|
],
|
|
86
86
|
});
|
|
87
|
-
|
|
87
|
+
|
|
88
88
|
if (nearAccount) {
|
|
89
89
|
// Add NEAR account to session response
|
|
90
90
|
ctx.context.session = {
|
|
@@ -96,7 +96,7 @@ export const siwn = (options: SIWNPluginOptions) =>
|
|
|
96
96
|
};
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
|
-
|
|
99
|
+
|
|
100
100
|
return { context: ctx };
|
|
101
101
|
}),
|
|
102
102
|
},
|
|
@@ -373,7 +373,7 @@ export const siwn = (options: SIWNPluginOptions) =>
|
|
|
373
373
|
async (ctx) => {
|
|
374
374
|
const { accountId, publicKey, networkId } = ctx.body;
|
|
375
375
|
const network = getNetworkFromAccountId(accountId);
|
|
376
|
-
|
|
376
|
+
|
|
377
377
|
if (networkId !== network) {
|
|
378
378
|
throw new APIError("BAD_REQUEST", {
|
|
379
379
|
message: "Network ID mismatch with account ID",
|