@pinklemon8/better-auth-siws 0.1.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/LICENSE +21 -0
- package/README.md +183 -0
- package/dist/chunk-AUDIM6MZ.js +30 -0
- package/dist/chunk-AUDIM6MZ.js.map +1 -0
- package/dist/chunk-Q7TSFSYW.js +42 -0
- package/dist/chunk-Q7TSFSYW.js.map +1 -0
- package/dist/client.cjs +106 -0
- package/dist/client.cjs.map +1 -0
- package/dist/client.d.cts +86 -0
- package/dist/client.d.ts +86 -0
- package/dist/client.js +69 -0
- package/dist/client.js.map +1 -0
- package/dist/crypto-BQgenqov.d.cts +90 -0
- package/dist/crypto-BQgenqov.d.ts +90 -0
- package/dist/index.cjs +262 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +54 -0
- package/dist/index.d.ts +54 -0
- package/dist/index.js +189 -0
- package/dist/index.js.map +1 -0
- package/dist/link.cjs +208 -0
- package/dist/link.cjs.map +1 -0
- package/dist/link.d.cts +46 -0
- package/dist/link.d.ts +46 -0
- package/dist/link.js +148 -0
- package/dist/link.js.map +1 -0
- package/dist/react/index.cjs +361 -0
- package/dist/react/index.cjs.map +1 -0
- package/dist/react/index.js +335 -0
- package/dist/react/index.js.map +1 -0
- package/package.json +87 -0
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { SolanaSignInOutput, SolanaSignInInput } from '@solana/wallet-standard-features';
|
|
2
|
+
|
|
3
|
+
interface SiwsPluginOptions {
|
|
4
|
+
statement?: string;
|
|
5
|
+
chainId?: string;
|
|
6
|
+
nonceExpiryMs?: number;
|
|
7
|
+
anonymous?: boolean;
|
|
8
|
+
}
|
|
9
|
+
interface SiwsNonceResponse {
|
|
10
|
+
nonce: string;
|
|
11
|
+
domain: string;
|
|
12
|
+
uri: string;
|
|
13
|
+
statement: string;
|
|
14
|
+
chainId: string;
|
|
15
|
+
issuedAt: string;
|
|
16
|
+
}
|
|
17
|
+
interface SiwsVerifyRequest {
|
|
18
|
+
output: {
|
|
19
|
+
account: {
|
|
20
|
+
address: string;
|
|
21
|
+
publicKey: number[];
|
|
22
|
+
};
|
|
23
|
+
signature: number[];
|
|
24
|
+
signedMessage: number[];
|
|
25
|
+
};
|
|
26
|
+
input: {
|
|
27
|
+
domain: string;
|
|
28
|
+
address?: string;
|
|
29
|
+
statement?: string;
|
|
30
|
+
uri?: string;
|
|
31
|
+
version?: string;
|
|
32
|
+
chainId?: string;
|
|
33
|
+
nonce?: string;
|
|
34
|
+
issuedAt?: string;
|
|
35
|
+
expirationTime?: string;
|
|
36
|
+
notBefore?: string;
|
|
37
|
+
requestId?: string;
|
|
38
|
+
resources?: string[];
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
interface SiwsVerifyResponse {
|
|
42
|
+
success: boolean;
|
|
43
|
+
user: {
|
|
44
|
+
id: string;
|
|
45
|
+
name: string;
|
|
46
|
+
email: string;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
interface SiwsLinkRequest {
|
|
50
|
+
input: SolanaSignInInput;
|
|
51
|
+
output: {
|
|
52
|
+
account: {
|
|
53
|
+
address: string;
|
|
54
|
+
publicKey: number[];
|
|
55
|
+
};
|
|
56
|
+
signature: number[];
|
|
57
|
+
signedMessage: number[];
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
interface SiwsLinkedWallet {
|
|
61
|
+
walletAddress: string;
|
|
62
|
+
createdAt: Date;
|
|
63
|
+
}
|
|
64
|
+
interface SerializedSolanaOutput {
|
|
65
|
+
account: {
|
|
66
|
+
address: string;
|
|
67
|
+
publicKey: number[];
|
|
68
|
+
};
|
|
69
|
+
signature: number[];
|
|
70
|
+
signedMessage: number[];
|
|
71
|
+
signatureType?: string;
|
|
72
|
+
}
|
|
73
|
+
declare function serializeOutput(output: SolanaSignInOutput): SerializedSolanaOutput;
|
|
74
|
+
declare function deserializeOutput(data: SerializedSolanaOutput): SolanaSignInOutput;
|
|
75
|
+
|
|
76
|
+
declare function generateNonce(): string;
|
|
77
|
+
declare function createSignInInput(domain: string, nonce: string, options?: {
|
|
78
|
+
statement?: string;
|
|
79
|
+
chainId?: string;
|
|
80
|
+
}): SolanaSignInInput;
|
|
81
|
+
declare function verifySIWS(input: SolanaSignInInput, output: SolanaSignInOutput | {
|
|
82
|
+
account: {
|
|
83
|
+
publicKey: number[] | Uint8Array;
|
|
84
|
+
address: string;
|
|
85
|
+
};
|
|
86
|
+
signature: number[] | Uint8Array;
|
|
87
|
+
signedMessage: number[] | Uint8Array;
|
|
88
|
+
}): boolean;
|
|
89
|
+
|
|
90
|
+
export { type SerializedSolanaOutput as S, type SiwsNonceResponse as a, type SiwsPluginOptions as b, type SiwsLinkedWallet as c, type SiwsVerifyRequest as d, type SiwsVerifyResponse as e, deserializeOutput as f, generateNonce as g, type SiwsLinkRequest as h, createSignInInput as i, serializeOutput as s, verifySIWS as v };
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { SolanaSignInOutput, SolanaSignInInput } from '@solana/wallet-standard-features';
|
|
2
|
+
|
|
3
|
+
interface SiwsPluginOptions {
|
|
4
|
+
statement?: string;
|
|
5
|
+
chainId?: string;
|
|
6
|
+
nonceExpiryMs?: number;
|
|
7
|
+
anonymous?: boolean;
|
|
8
|
+
}
|
|
9
|
+
interface SiwsNonceResponse {
|
|
10
|
+
nonce: string;
|
|
11
|
+
domain: string;
|
|
12
|
+
uri: string;
|
|
13
|
+
statement: string;
|
|
14
|
+
chainId: string;
|
|
15
|
+
issuedAt: string;
|
|
16
|
+
}
|
|
17
|
+
interface SiwsVerifyRequest {
|
|
18
|
+
output: {
|
|
19
|
+
account: {
|
|
20
|
+
address: string;
|
|
21
|
+
publicKey: number[];
|
|
22
|
+
};
|
|
23
|
+
signature: number[];
|
|
24
|
+
signedMessage: number[];
|
|
25
|
+
};
|
|
26
|
+
input: {
|
|
27
|
+
domain: string;
|
|
28
|
+
address?: string;
|
|
29
|
+
statement?: string;
|
|
30
|
+
uri?: string;
|
|
31
|
+
version?: string;
|
|
32
|
+
chainId?: string;
|
|
33
|
+
nonce?: string;
|
|
34
|
+
issuedAt?: string;
|
|
35
|
+
expirationTime?: string;
|
|
36
|
+
notBefore?: string;
|
|
37
|
+
requestId?: string;
|
|
38
|
+
resources?: string[];
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
interface SiwsVerifyResponse {
|
|
42
|
+
success: boolean;
|
|
43
|
+
user: {
|
|
44
|
+
id: string;
|
|
45
|
+
name: string;
|
|
46
|
+
email: string;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
interface SiwsLinkRequest {
|
|
50
|
+
input: SolanaSignInInput;
|
|
51
|
+
output: {
|
|
52
|
+
account: {
|
|
53
|
+
address: string;
|
|
54
|
+
publicKey: number[];
|
|
55
|
+
};
|
|
56
|
+
signature: number[];
|
|
57
|
+
signedMessage: number[];
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
interface SiwsLinkedWallet {
|
|
61
|
+
walletAddress: string;
|
|
62
|
+
createdAt: Date;
|
|
63
|
+
}
|
|
64
|
+
interface SerializedSolanaOutput {
|
|
65
|
+
account: {
|
|
66
|
+
address: string;
|
|
67
|
+
publicKey: number[];
|
|
68
|
+
};
|
|
69
|
+
signature: number[];
|
|
70
|
+
signedMessage: number[];
|
|
71
|
+
signatureType?: string;
|
|
72
|
+
}
|
|
73
|
+
declare function serializeOutput(output: SolanaSignInOutput): SerializedSolanaOutput;
|
|
74
|
+
declare function deserializeOutput(data: SerializedSolanaOutput): SolanaSignInOutput;
|
|
75
|
+
|
|
76
|
+
declare function generateNonce(): string;
|
|
77
|
+
declare function createSignInInput(domain: string, nonce: string, options?: {
|
|
78
|
+
statement?: string;
|
|
79
|
+
chainId?: string;
|
|
80
|
+
}): SolanaSignInInput;
|
|
81
|
+
declare function verifySIWS(input: SolanaSignInInput, output: SolanaSignInOutput | {
|
|
82
|
+
account: {
|
|
83
|
+
publicKey: number[] | Uint8Array;
|
|
84
|
+
address: string;
|
|
85
|
+
};
|
|
86
|
+
signature: number[] | Uint8Array;
|
|
87
|
+
signedMessage: number[] | Uint8Array;
|
|
88
|
+
}): boolean;
|
|
89
|
+
|
|
90
|
+
export { type SerializedSolanaOutput as S, type SiwsNonceResponse as a, type SiwsPluginOptions as b, type SiwsLinkedWallet as c, type SiwsVerifyRequest as d, type SiwsVerifyResponse as e, deserializeOutput as f, generateNonce as g, type SiwsLinkRequest as h, createSignInInput as i, serializeOutput as s, verifySIWS as v };
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
deserializeOutput: () => deserializeOutput,
|
|
24
|
+
generateNonce: () => generateNonce,
|
|
25
|
+
serializeOutput: () => serializeOutput,
|
|
26
|
+
siws: () => siws,
|
|
27
|
+
verifySIWS: () => verifySIWS
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(src_exports);
|
|
30
|
+
var import_api = require("better-auth/api");
|
|
31
|
+
var import_cookies = require("better-auth/cookies");
|
|
32
|
+
var import_zod = require("zod");
|
|
33
|
+
|
|
34
|
+
// src/crypto.ts
|
|
35
|
+
var import_wallet_standard_util = require("@solana/wallet-standard-util");
|
|
36
|
+
function generateNonce() {
|
|
37
|
+
const array = new Uint8Array(16);
|
|
38
|
+
crypto.getRandomValues(array);
|
|
39
|
+
return Array.from(array, (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
40
|
+
}
|
|
41
|
+
function verifySIWS(input, output) {
|
|
42
|
+
try {
|
|
43
|
+
const reconstructed = {
|
|
44
|
+
account: {
|
|
45
|
+
...output.account,
|
|
46
|
+
publicKey: output.account.publicKey instanceof Uint8Array ? output.account.publicKey : new Uint8Array(output.account.publicKey),
|
|
47
|
+
chains: output.account.chains ?? [],
|
|
48
|
+
features: output.account.features ?? []
|
|
49
|
+
},
|
|
50
|
+
signature: output.signature instanceof Uint8Array ? output.signature : new Uint8Array(output.signature),
|
|
51
|
+
signedMessage: output.signedMessage instanceof Uint8Array ? output.signedMessage : new Uint8Array(output.signedMessage)
|
|
52
|
+
};
|
|
53
|
+
return (0, import_wallet_standard_util.verifySignIn)(input, reconstructed);
|
|
54
|
+
} catch (error) {
|
|
55
|
+
console.error("SIWS verification error:", error);
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// src/types.ts
|
|
61
|
+
function serializeOutput(output) {
|
|
62
|
+
return {
|
|
63
|
+
account: {
|
|
64
|
+
address: output.account.address,
|
|
65
|
+
publicKey: Array.from(output.account.publicKey)
|
|
66
|
+
},
|
|
67
|
+
signature: Array.from(output.signature),
|
|
68
|
+
signedMessage: Array.from(output.signedMessage),
|
|
69
|
+
signatureType: output.signatureType
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
function deserializeOutput(data) {
|
|
73
|
+
return {
|
|
74
|
+
account: {
|
|
75
|
+
address: data.account.address,
|
|
76
|
+
publicKey: new Uint8Array(data.account.publicKey),
|
|
77
|
+
chains: [],
|
|
78
|
+
features: []
|
|
79
|
+
},
|
|
80
|
+
signature: new Uint8Array(data.signature),
|
|
81
|
+
signedMessage: new Uint8Array(data.signedMessage)
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// src/index.ts
|
|
86
|
+
var siws = (options) => ({
|
|
87
|
+
id: "siws",
|
|
88
|
+
endpoints: {
|
|
89
|
+
getSiwsNonce: (0, import_api.createAuthEndpoint)(
|
|
90
|
+
"/siws/nonce",
|
|
91
|
+
{
|
|
92
|
+
method: "POST",
|
|
93
|
+
body: import_zod.z.object({
|
|
94
|
+
walletAddress: import_zod.z.string().min(32).max(44)
|
|
95
|
+
})
|
|
96
|
+
},
|
|
97
|
+
async (ctx) => {
|
|
98
|
+
const { walletAddress } = ctx.body;
|
|
99
|
+
const nonce = generateNonce();
|
|
100
|
+
const expiryMs = options?.nonceExpiryMs ?? 5 * 60 * 1e3;
|
|
101
|
+
await ctx.context.internalAdapter.createVerificationValue({
|
|
102
|
+
identifier: `siws:${walletAddress}`,
|
|
103
|
+
value: nonce,
|
|
104
|
+
expiresAt: new Date(Date.now() + expiryMs)
|
|
105
|
+
});
|
|
106
|
+
const host = ctx.headers?.get("host") || "localhost:3000";
|
|
107
|
+
const protocol = host.includes("localhost") ? "http" : "https";
|
|
108
|
+
const domain = host;
|
|
109
|
+
const uri = `${protocol}://${host}`;
|
|
110
|
+
return ctx.json({
|
|
111
|
+
nonce,
|
|
112
|
+
domain,
|
|
113
|
+
uri,
|
|
114
|
+
statement: options?.statement ?? "Sign in with your Solana wallet. This will not trigger a blockchain transaction or cost any gas fee.",
|
|
115
|
+
chainId: options?.chainId ?? "mainnet",
|
|
116
|
+
issuedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
),
|
|
120
|
+
verifySiwsSignature: (0, import_api.createAuthEndpoint)(
|
|
121
|
+
"/siws/verify",
|
|
122
|
+
{
|
|
123
|
+
method: "POST",
|
|
124
|
+
body: import_zod.z.object({
|
|
125
|
+
output: import_zod.z.object({
|
|
126
|
+
account: import_zod.z.object({
|
|
127
|
+
address: import_zod.z.string(),
|
|
128
|
+
publicKey: import_zod.z.array(import_zod.z.number())
|
|
129
|
+
}),
|
|
130
|
+
signature: import_zod.z.array(import_zod.z.number()),
|
|
131
|
+
signedMessage: import_zod.z.array(import_zod.z.number())
|
|
132
|
+
}),
|
|
133
|
+
input: import_zod.z.object({
|
|
134
|
+
domain: import_zod.z.string(),
|
|
135
|
+
address: import_zod.z.string().optional(),
|
|
136
|
+
statement: import_zod.z.string().optional(),
|
|
137
|
+
uri: import_zod.z.string().optional(),
|
|
138
|
+
version: import_zod.z.string().optional(),
|
|
139
|
+
chainId: import_zod.z.string().optional(),
|
|
140
|
+
nonce: import_zod.z.string().optional(),
|
|
141
|
+
issuedAt: import_zod.z.string().optional(),
|
|
142
|
+
expirationTime: import_zod.z.string().optional(),
|
|
143
|
+
notBefore: import_zod.z.string().optional(),
|
|
144
|
+
requestId: import_zod.z.string().optional(),
|
|
145
|
+
resources: import_zod.z.array(import_zod.z.string()).optional()
|
|
146
|
+
})
|
|
147
|
+
}),
|
|
148
|
+
requireRequest: true
|
|
149
|
+
},
|
|
150
|
+
async (ctx) => {
|
|
151
|
+
const { output, input } = ctx.body;
|
|
152
|
+
const walletAddress = output.account.address;
|
|
153
|
+
const verification = await ctx.context.internalAdapter.findVerificationValue(
|
|
154
|
+
`siws:${walletAddress}`
|
|
155
|
+
);
|
|
156
|
+
if (!verification || /* @__PURE__ */ new Date() > verification.expiresAt) {
|
|
157
|
+
throw new import_api.APIError("UNAUTHORIZED", {
|
|
158
|
+
message: "Invalid or expired nonce"
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
const solanaOutput = deserializeOutput(output);
|
|
162
|
+
const isValid = verifySIWS(input, solanaOutput);
|
|
163
|
+
if (!isValid) {
|
|
164
|
+
throw new import_api.APIError("UNAUTHORIZED", {
|
|
165
|
+
message: "Invalid signature"
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
await ctx.context.internalAdapter.deleteVerificationValue(
|
|
169
|
+
verification.id
|
|
170
|
+
);
|
|
171
|
+
const linkedAccount = await ctx.context.adapter.findOne({
|
|
172
|
+
model: "account",
|
|
173
|
+
where: [
|
|
174
|
+
{ field: "providerId", operator: "eq", value: "solana" },
|
|
175
|
+
{ field: "accountId", operator: "eq", value: walletAddress }
|
|
176
|
+
]
|
|
177
|
+
});
|
|
178
|
+
if (!linkedAccount) {
|
|
179
|
+
if (options?.anonymous) {
|
|
180
|
+
const user2 = await ctx.context.internalAdapter.createUser({
|
|
181
|
+
name: walletAddress,
|
|
182
|
+
email: `${walletAddress}@solana.wallet`,
|
|
183
|
+
image: ""
|
|
184
|
+
});
|
|
185
|
+
await ctx.context.internalAdapter.createAccount({
|
|
186
|
+
userId: user2.id,
|
|
187
|
+
providerId: "solana",
|
|
188
|
+
accountId: walletAddress,
|
|
189
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
190
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
191
|
+
});
|
|
192
|
+
const session2 = await ctx.context.internalAdapter.createSession(
|
|
193
|
+
user2.id,
|
|
194
|
+
ctx
|
|
195
|
+
);
|
|
196
|
+
if (!session2) {
|
|
197
|
+
throw new import_api.APIError("INTERNAL_SERVER_ERROR", {
|
|
198
|
+
message: "Failed to create session"
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
await (0, import_cookies.setSessionCookie)(ctx, { session: session2, user: user2 });
|
|
202
|
+
return ctx.json({
|
|
203
|
+
success: true,
|
|
204
|
+
user: {
|
|
205
|
+
id: user2.id,
|
|
206
|
+
name: user2.name,
|
|
207
|
+
email: user2.email
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
throw new import_api.APIError("UNAUTHORIZED", {
|
|
212
|
+
message: "No account linked to this wallet. Please sign in with email first and link your wallet.",
|
|
213
|
+
code: "WALLET_NOT_LINKED"
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
const user = await ctx.context.adapter.findOne({
|
|
217
|
+
model: "user",
|
|
218
|
+
where: [
|
|
219
|
+
{ field: "id", operator: "eq", value: linkedAccount.userId }
|
|
220
|
+
]
|
|
221
|
+
});
|
|
222
|
+
if (!user) {
|
|
223
|
+
throw new import_api.APIError("UNAUTHORIZED", {
|
|
224
|
+
message: "User not found"
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
if (user.banned) {
|
|
228
|
+
throw new import_api.APIError("FORBIDDEN", {
|
|
229
|
+
message: "Your account has been banned"
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
const session = await ctx.context.internalAdapter.createSession(
|
|
233
|
+
user.id,
|
|
234
|
+
ctx
|
|
235
|
+
);
|
|
236
|
+
if (!session) {
|
|
237
|
+
throw new import_api.APIError("INTERNAL_SERVER_ERROR", {
|
|
238
|
+
message: "Failed to create session"
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
await (0, import_cookies.setSessionCookie)(ctx, { session, user });
|
|
242
|
+
return ctx.json({
|
|
243
|
+
success: true,
|
|
244
|
+
user: {
|
|
245
|
+
id: user.id,
|
|
246
|
+
name: user.name,
|
|
247
|
+
email: user.email
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
)
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
255
|
+
0 && (module.exports = {
|
|
256
|
+
deserializeOutput,
|
|
257
|
+
generateNonce,
|
|
258
|
+
serializeOutput,
|
|
259
|
+
siws,
|
|
260
|
+
verifySIWS
|
|
261
|
+
});
|
|
262
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/crypto.ts","../src/types.ts"],"sourcesContent":["import { createAuthEndpoint, APIError } from \"better-auth/api\";\nimport { setSessionCookie } from \"better-auth/cookies\";\nimport { z } from \"zod\";\nimport { generateNonce, verifySIWS } from \"./crypto\";\nimport { deserializeOutput } from \"./types\";\nimport type { SiwsPluginOptions } from \"./types\";\n\nexport type { SiwsPluginOptions };\nexport { generateNonce, verifySIWS } from \"./crypto\";\nexport { serializeOutput, deserializeOutput } from \"./types\";\nexport type {\n SiwsNonceResponse,\n SiwsVerifyRequest,\n SiwsVerifyResponse,\n SiwsLinkedWallet,\n SerializedSolanaOutput,\n} from \"./types\";\n\nexport const siws = (options?: SiwsPluginOptions) => ({\n id: \"siws\" as const,\n endpoints: {\n getSiwsNonce: createAuthEndpoint(\n \"/siws/nonce\",\n {\n method: \"POST\",\n body: z.object({\n walletAddress: z.string().min(32).max(44),\n }),\n },\n async (ctx) => {\n const { walletAddress } = ctx.body;\n const nonce = generateNonce();\n const expiryMs = options?.nonceExpiryMs ?? 5 * 60 * 1000;\n\n await ctx.context.internalAdapter.createVerificationValue({\n identifier: `siws:${walletAddress}`,\n value: nonce,\n expiresAt: new Date(Date.now() + expiryMs),\n });\n\n const host = ctx.headers?.get(\"host\") || \"localhost:3000\";\n const protocol = host.includes(\"localhost\") ? \"http\" : \"https\";\n const domain = host;\n const uri = `${protocol}://${host}`;\n\n return ctx.json({\n nonce,\n domain,\n uri,\n statement:\n options?.statement ??\n \"Sign in with your Solana wallet. This will not trigger a blockchain transaction or cost any gas fee.\",\n chainId: options?.chainId ?? \"mainnet\",\n issuedAt: new Date().toISOString(),\n });\n }\n ),\n\n verifySiwsSignature: createAuthEndpoint(\n \"/siws/verify\",\n {\n method: \"POST\",\n body: z.object({\n output: z.object({\n account: z.object({\n address: z.string(),\n publicKey: z.array(z.number()),\n }),\n signature: z.array(z.number()),\n signedMessage: z.array(z.number()),\n }),\n input: z.object({\n domain: z.string(),\n address: z.string().optional(),\n statement: z.string().optional(),\n uri: z.string().optional(),\n version: z.string().optional(),\n chainId: z.string().optional(),\n nonce: z.string().optional(),\n issuedAt: z.string().optional(),\n expirationTime: z.string().optional(),\n notBefore: z.string().optional(),\n requestId: z.string().optional(),\n resources: z.array(z.string()).optional(),\n }),\n }),\n requireRequest: true,\n },\n async (ctx: any) => {\n const { output, input } = ctx.body;\n const walletAddress = output.account.address;\n\n const verification =\n await ctx.context.internalAdapter.findVerificationValue(\n `siws:${walletAddress}`\n );\n\n if (!verification || new Date() > verification.expiresAt) {\n throw new APIError(\"UNAUTHORIZED\", {\n message: \"Invalid or expired nonce\",\n });\n }\n\n const solanaOutput = deserializeOutput(output);\n const isValid = verifySIWS(input, solanaOutput);\n\n if (!isValid) {\n throw new APIError(\"UNAUTHORIZED\", {\n message: \"Invalid signature\",\n });\n }\n\n await ctx.context.internalAdapter.deleteVerificationValue(\n verification.id\n );\n\n const linkedAccount = (await ctx.context.adapter.findOne({\n model: \"account\",\n where: [\n { field: \"providerId\", operator: \"eq\", value: \"solana\" },\n { field: \"accountId\", operator: \"eq\", value: walletAddress },\n ],\n })) as { userId: string } | null;\n\n if (!linkedAccount) {\n if (options?.anonymous) {\n const user = await ctx.context.internalAdapter.createUser({\n name: walletAddress,\n email: `${walletAddress}@solana.wallet`,\n image: \"\",\n });\n\n await ctx.context.internalAdapter.createAccount({\n userId: user.id,\n providerId: \"solana\",\n accountId: walletAddress,\n createdAt: new Date(),\n updatedAt: new Date(),\n });\n\n const session = await ctx.context.internalAdapter.createSession(\n user.id,\n ctx\n );\n\n if (!session) {\n throw new APIError(\"INTERNAL_SERVER_ERROR\", {\n message: \"Failed to create session\",\n });\n }\n\n await setSessionCookie(ctx, { session, user });\n\n return ctx.json({\n success: true,\n user: {\n id: user.id,\n name: user.name,\n email: user.email,\n },\n });\n }\n\n throw new APIError(\"UNAUTHORIZED\", {\n message:\n \"No account linked to this wallet. Please sign in with email first and link your wallet.\",\n code: \"WALLET_NOT_LINKED\",\n });\n }\n\n const user = (await ctx.context.adapter.findOne({\n model: \"user\",\n where: [\n { field: \"id\", operator: \"eq\", value: linkedAccount.userId },\n ],\n })) as {\n id: string;\n name: string;\n email: string;\n emailVerified: boolean;\n image?: string | null;\n banned?: boolean;\n createdAt: Date;\n updatedAt: Date;\n } | null;\n\n if (!user) {\n throw new APIError(\"UNAUTHORIZED\", {\n message: \"User not found\",\n });\n }\n\n if (user.banned) {\n throw new APIError(\"FORBIDDEN\", {\n message: \"Your account has been banned\",\n });\n }\n\n const session = await ctx.context.internalAdapter.createSession(\n user.id,\n ctx\n );\n\n if (!session) {\n throw new APIError(\"INTERNAL_SERVER_ERROR\", {\n message: \"Failed to create session\",\n });\n }\n\n await setSessionCookie(ctx, { session, user });\n\n return ctx.json({\n success: true,\n user: {\n id: user.id,\n name: user.name,\n email: user.email,\n },\n });\n }\n ),\n },\n});\n","import type { SolanaSignInInput, SolanaSignInOutput } from \"@solana/wallet-standard-features\";\nimport { verifySignIn } from \"@solana/wallet-standard-util\";\n\nexport function generateNonce(): string {\n const array = new Uint8Array(16);\n crypto.getRandomValues(array);\n return Array.from(array, (byte) => byte.toString(16).padStart(2, \"0\")).join(\"\");\n}\n\nexport function createSignInInput(\n domain: string,\n nonce: string,\n options?: { statement?: string; chainId?: string }\n): SolanaSignInInput {\n return {\n domain,\n statement:\n options?.statement ??\n \"Sign in with your Solana wallet. This will not trigger a blockchain transaction or cost any gas fee.\",\n version: \"1\",\n nonce,\n chainId: options?.chainId ?? \"mainnet\",\n issuedAt: new Date().toISOString(),\n };\n}\n\nexport function verifySIWS(\n input: SolanaSignInInput,\n output: SolanaSignInOutput | { account: { publicKey: number[] | Uint8Array; address: string }; signature: number[] | Uint8Array; signedMessage: number[] | Uint8Array }\n): boolean {\n try {\n const reconstructed: SolanaSignInOutput = {\n account: {\n ...output.account,\n publicKey:\n output.account.publicKey instanceof Uint8Array\n ? output.account.publicKey\n : new Uint8Array(output.account.publicKey),\n chains: (output.account as any).chains ?? [],\n features: (output.account as any).features ?? [],\n },\n signature:\n output.signature instanceof Uint8Array\n ? output.signature\n : new Uint8Array(output.signature),\n signedMessage:\n output.signedMessage instanceof Uint8Array\n ? output.signedMessage\n : new Uint8Array(output.signedMessage),\n };\n return verifySignIn(input, reconstructed);\n } catch (error) {\n console.error(\"SIWS verification error:\", error);\n return false;\n }\n}\n","import type { SolanaSignInInput, SolanaSignInOutput } from \"@solana/wallet-standard-features\";\n\nexport type { SolanaSignInInput, SolanaSignInOutput };\n\nexport interface SiwsPluginOptions {\n statement?: string;\n chainId?: string;\n nonceExpiryMs?: number;\n anonymous?: boolean;\n}\n\nexport interface SiwsNonceResponse {\n nonce: string;\n domain: string;\n uri: string;\n statement: string;\n chainId: string;\n issuedAt: string;\n}\n\nexport interface SiwsVerifyRequest {\n output: {\n account: {\n address: string;\n publicKey: number[];\n };\n signature: number[];\n signedMessage: number[];\n };\n input: {\n domain: string;\n address?: string;\n statement?: string;\n uri?: string;\n version?: string;\n chainId?: string;\n nonce?: string;\n issuedAt?: string;\n expirationTime?: string;\n notBefore?: string;\n requestId?: string;\n resources?: string[];\n };\n}\n\nexport interface SiwsVerifyResponse {\n success: boolean;\n user: {\n id: string;\n name: string;\n email: string;\n };\n}\n\nexport interface SiwsLinkRequest {\n input: SolanaSignInInput;\n output: {\n account: {\n address: string;\n publicKey: number[];\n };\n signature: number[];\n signedMessage: number[];\n };\n}\n\nexport interface SiwsLinkedWallet {\n walletAddress: string;\n createdAt: Date;\n}\n\nexport interface SerializedSolanaOutput {\n account: {\n address: string;\n publicKey: number[];\n };\n signature: number[];\n signedMessage: number[];\n signatureType?: string;\n}\n\nexport function serializeOutput(output: SolanaSignInOutput): SerializedSolanaOutput {\n return {\n account: {\n address: output.account.address,\n publicKey: Array.from(output.account.publicKey),\n },\n signature: Array.from(output.signature),\n signedMessage: Array.from(output.signedMessage),\n signatureType: (output as any).signatureType,\n };\n}\n\nexport function deserializeOutput(data: SerializedSolanaOutput): SolanaSignInOutput {\n return {\n account: {\n address: data.account.address,\n publicKey: new Uint8Array(data.account.publicKey),\n chains: [],\n features: [],\n },\n signature: new Uint8Array(data.signature),\n signedMessage: new Uint8Array(data.signedMessage),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAA6C;AAC7C,qBAAiC;AACjC,iBAAkB;;;ACDlB,kCAA6B;AAEtB,SAAS,gBAAwB;AACtC,QAAM,QAAQ,IAAI,WAAW,EAAE;AAC/B,SAAO,gBAAgB,KAAK;AAC5B,SAAO,MAAM,KAAK,OAAO,CAAC,SAAS,KAAK,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG,CAAC,EAAE,KAAK,EAAE;AAChF;AAmBO,SAAS,WACd,OACA,QACS;AACT,MAAI;AACF,UAAM,gBAAoC;AAAA,MACxC,SAAS;AAAA,QACP,GAAG,OAAO;AAAA,QACV,WACE,OAAO,QAAQ,qBAAqB,aAChC,OAAO,QAAQ,YACf,IAAI,WAAW,OAAO,QAAQ,SAAS;AAAA,QAC7C,QAAS,OAAO,QAAgB,UAAU,CAAC;AAAA,QAC3C,UAAW,OAAO,QAAgB,YAAY,CAAC;AAAA,MACjD;AAAA,MACA,WACE,OAAO,qBAAqB,aACxB,OAAO,YACP,IAAI,WAAW,OAAO,SAAS;AAAA,MACrC,eACE,OAAO,yBAAyB,aAC5B,OAAO,gBACP,IAAI,WAAW,OAAO,aAAa;AAAA,IAC3C;AACA,eAAO,0CAAa,OAAO,aAAa;AAAA,EAC1C,SAAS,OAAO;AACd,YAAQ,MAAM,4BAA4B,KAAK;AAC/C,WAAO;AAAA,EACT;AACF;;;AC0BO,SAAS,gBAAgB,QAAoD;AAClF,SAAO;AAAA,IACL,SAAS;AAAA,MACP,SAAS,OAAO,QAAQ;AAAA,MACxB,WAAW,MAAM,KAAK,OAAO,QAAQ,SAAS;AAAA,IAChD;AAAA,IACA,WAAW,MAAM,KAAK,OAAO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O,IAAI,KAAK;AAAA,cACd,SAAS;AAAA,cACT,MAAM;AAAA,gBACJ,IAAIA,MAAK;AAAA,gBACT,MAAMA,MAAK;AAAA,gBACX,OAAOA,MAAK;AAAA,cACd;AAAA,YACF,CAAC;AAAA,UACH;AAEA,gBAAM,IAAI,oBAAS,gBAAgB;AAAA,YACjC,SACE;AAAA,YACF,MAAM;AAAA,UACR,CAAC;AAAA,QACH;AAEA,cAAM,OAAQ,MAAM,IAAI,QAAQ,QAAQ,QAAQ;AAAA,UAC9C,OAAO;AAAA,UACP,OAAO;AAAA,YACL,EAAE,OAAO,MAAM,UAAU,MAAM,OAAO,cAAc,OAAO;AAAA,UAC7D;AAAA,QACF,CAAC;AAWD,YAAI,CAAC,MAAM;AACT,gBAAM,IAAI,oBAAS,gBAAgB;AAAA,YACjC,SAAS;AAAA,UACX,CAAC;AAAA,QACH;AAEA,YAAI,KAAK,QAAQ;AACf,gBAAM,IAAI,oBAAS,aAAa;AAAA,YAC9B,SAAS;AAAA,UACX,CAAC;AAAA,QACH;AAEA,cAAM,UAAU,MAAM,IAAI,QAAQ,gBAAgB;AAAA,UAChD,KAAK;AAAA,UACL;AAAA,QACF;AAEA,YAAI,CAAC,SAAS;AACZ,gBAAM,IAAI,oBAAS,yBAAyB;AAAA,YAC1C,SAAS;AAAA,UACX,CAAC;AAAA,QACH;AAEA,kBAAM,iCAAiB,KAAK,EAAE,SAAS,KAAK,CAAC;AAE7C,eAAO,IAAI,KAAK;AAAA,UACd,SAAS;AAAA,UACT,MAAM;AAAA,YACJ,IAAI,KAAK;AAAA,YACT,MAAM,KAAK;AAAA,YACX,OAAO,KAAK;AAAA,UACd;AAAA,QACF,CAAC;AAAA,MACH;AAAA,IACF;AAAA,EACF;AACF;","names":["user","session"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import * as better_call from 'better-call';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { b as SiwsPluginOptions } from './crypto-BQgenqov.cjs';
|
|
4
|
+
export { S as SerializedSolanaOutput, c as SiwsLinkedWallet, a as SiwsNonceResponse, d as SiwsVerifyRequest, e as SiwsVerifyResponse, f as deserializeOutput, g as generateNonce, s as serializeOutput, v as verifySIWS } from './crypto-BQgenqov.cjs';
|
|
5
|
+
import '@solana/wallet-standard-features';
|
|
6
|
+
|
|
7
|
+
declare const siws: (options?: SiwsPluginOptions) => {
|
|
8
|
+
id: "siws";
|
|
9
|
+
endpoints: {
|
|
10
|
+
getSiwsNonce: better_call.StrictEndpoint<"/siws/nonce", {
|
|
11
|
+
method: "POST";
|
|
12
|
+
body: z.ZodObject<{
|
|
13
|
+
walletAddress: z.ZodString;
|
|
14
|
+
}, z.core.$strip>;
|
|
15
|
+
}, {
|
|
16
|
+
nonce: string;
|
|
17
|
+
domain: string;
|
|
18
|
+
uri: string;
|
|
19
|
+
statement: string;
|
|
20
|
+
chainId: string;
|
|
21
|
+
issuedAt: string;
|
|
22
|
+
}>;
|
|
23
|
+
verifySiwsSignature: better_call.StrictEndpoint<"/siws/verify", {
|
|
24
|
+
method: "POST";
|
|
25
|
+
body: z.ZodObject<{
|
|
26
|
+
output: z.ZodObject<{
|
|
27
|
+
account: z.ZodObject<{
|
|
28
|
+
address: z.ZodString;
|
|
29
|
+
publicKey: z.ZodArray<z.ZodNumber>;
|
|
30
|
+
}, z.core.$strip>;
|
|
31
|
+
signature: z.ZodArray<z.ZodNumber>;
|
|
32
|
+
signedMessage: z.ZodArray<z.ZodNumber>;
|
|
33
|
+
}, z.core.$strip>;
|
|
34
|
+
input: z.ZodObject<{
|
|
35
|
+
domain: z.ZodString;
|
|
36
|
+
address: z.ZodOptional<z.ZodString>;
|
|
37
|
+
statement: z.ZodOptional<z.ZodString>;
|
|
38
|
+
uri: z.ZodOptional<z.ZodString>;
|
|
39
|
+
version: z.ZodOptional<z.ZodString>;
|
|
40
|
+
chainId: z.ZodOptional<z.ZodString>;
|
|
41
|
+
nonce: z.ZodOptional<z.ZodString>;
|
|
42
|
+
issuedAt: z.ZodOptional<z.ZodString>;
|
|
43
|
+
expirationTime: z.ZodOptional<z.ZodString>;
|
|
44
|
+
notBefore: z.ZodOptional<z.ZodString>;
|
|
45
|
+
requestId: z.ZodOptional<z.ZodString>;
|
|
46
|
+
resources: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
47
|
+
}, z.core.$strip>;
|
|
48
|
+
}, z.core.$strip>;
|
|
49
|
+
requireRequest: true;
|
|
50
|
+
}, any>;
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export { SiwsPluginOptions, siws };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import * as better_call from 'better-call';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { b as SiwsPluginOptions } from './crypto-BQgenqov.js';
|
|
4
|
+
export { S as SerializedSolanaOutput, c as SiwsLinkedWallet, a as SiwsNonceResponse, d as SiwsVerifyRequest, e as SiwsVerifyResponse, f as deserializeOutput, g as generateNonce, s as serializeOutput, v as verifySIWS } from './crypto-BQgenqov.js';
|
|
5
|
+
import '@solana/wallet-standard-features';
|
|
6
|
+
|
|
7
|
+
declare const siws: (options?: SiwsPluginOptions) => {
|
|
8
|
+
id: "siws";
|
|
9
|
+
endpoints: {
|
|
10
|
+
getSiwsNonce: better_call.StrictEndpoint<"/siws/nonce", {
|
|
11
|
+
method: "POST";
|
|
12
|
+
body: z.ZodObject<{
|
|
13
|
+
walletAddress: z.ZodString;
|
|
14
|
+
}, z.core.$strip>;
|
|
15
|
+
}, {
|
|
16
|
+
nonce: string;
|
|
17
|
+
domain: string;
|
|
18
|
+
uri: string;
|
|
19
|
+
statement: string;
|
|
20
|
+
chainId: string;
|
|
21
|
+
issuedAt: string;
|
|
22
|
+
}>;
|
|
23
|
+
verifySiwsSignature: better_call.StrictEndpoint<"/siws/verify", {
|
|
24
|
+
method: "POST";
|
|
25
|
+
body: z.ZodObject<{
|
|
26
|
+
output: z.ZodObject<{
|
|
27
|
+
account: z.ZodObject<{
|
|
28
|
+
address: z.ZodString;
|
|
29
|
+
publicKey: z.ZodArray<z.ZodNumber>;
|
|
30
|
+
}, z.core.$strip>;
|
|
31
|
+
signature: z.ZodArray<z.ZodNumber>;
|
|
32
|
+
signedMessage: z.ZodArray<z.ZodNumber>;
|
|
33
|
+
}, z.core.$strip>;
|
|
34
|
+
input: z.ZodObject<{
|
|
35
|
+
domain: z.ZodString;
|
|
36
|
+
address: z.ZodOptional<z.ZodString>;
|
|
37
|
+
statement: z.ZodOptional<z.ZodString>;
|
|
38
|
+
uri: z.ZodOptional<z.ZodString>;
|
|
39
|
+
version: z.ZodOptional<z.ZodString>;
|
|
40
|
+
chainId: z.ZodOptional<z.ZodString>;
|
|
41
|
+
nonce: z.ZodOptional<z.ZodString>;
|
|
42
|
+
issuedAt: z.ZodOptional<z.ZodString>;
|
|
43
|
+
expirationTime: z.ZodOptional<z.ZodString>;
|
|
44
|
+
notBefore: z.ZodOptional<z.ZodString>;
|
|
45
|
+
requestId: z.ZodOptional<z.ZodString>;
|
|
46
|
+
resources: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
47
|
+
}, z.core.$strip>;
|
|
48
|
+
}, z.core.$strip>;
|
|
49
|
+
requireRequest: true;
|
|
50
|
+
}, any>;
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export { SiwsPluginOptions, siws };
|