@synqauth/plugin-siws 0.0.0-stage → 0.0.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 +35 -2
- package/dist/index.d.ts +47 -0
- package/dist/index.js +56 -0
- package/dist/server.d.ts +16 -0
- package/dist/server.js +13 -0
- package/package.json +43 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Aerosol
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,36 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @synqauth/plugin-siws
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A Synq plugin for Sign In With Solana from your own UI.
|
|
4
|
+
|
|
5
|
+
Synq is customer identity for businesses: an OpenID Connect issuer for each of your brands, with Solana wallet, social, email and passkey sign-in. The documentation is at [docs.synq.build](https://docs.synq.build).
|
|
6
|
+
|
|
7
|
+
This package is at 0.x and hasn't been published yet: its API can change in any release until Synq's first customer depends on it.
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
With `@synqauth/nextjs`, for the brand's own apps. On the server:
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { siwsServerPlugin } from '@synqauth/plugin-siws/server'
|
|
15
|
+
|
|
16
|
+
export const synq = synqAuth({ plugins: [siwsServerPlugin()] })
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
In the page:
|
|
20
|
+
|
|
21
|
+
```tsx
|
|
22
|
+
'use client'
|
|
23
|
+
import { mountRequest } from '@synqauth/nextjs/client'
|
|
24
|
+
import { siwsPlugin } from '@synqauth/plugin-siws'
|
|
25
|
+
import { useSolanaWallets } from '@synqauth/solana/react'
|
|
26
|
+
|
|
27
|
+
const siws = siwsPlugin().actions(mountRequest())
|
|
28
|
+
const wallets = useSolanaWallets()
|
|
29
|
+
const { error } = await siws.signIn(wallets[0], { returnTo: '/account' })
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
The wallet signs the issuer's own request on your page, and your server pushes the signature to Synq, which checks it. Your server verifies nothing.
|
|
33
|
+
|
|
34
|
+
## License
|
|
35
|
+
|
|
36
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { SynqError } from "@synqauth/js";
|
|
2
|
+
import { Wallet, WalletAccount } from "@synqauth/solana";
|
|
3
|
+
//#region src/index.d.ts
|
|
4
|
+
/** The plugin's id: its server half's routes are under it, and its actions under it in `usePlugin`. */
|
|
5
|
+
export declare const SIWS_PLUGIN_ID = "siws";
|
|
6
|
+
/** A call's outcome: its data, or the `SynqError` it failed with. */
|
|
7
|
+
export type SiwsResult<T> = {
|
|
8
|
+
readonly data: T;
|
|
9
|
+
readonly error: null;
|
|
10
|
+
} | {
|
|
11
|
+
readonly data: null;
|
|
12
|
+
readonly error: SynqError;
|
|
13
|
+
};
|
|
14
|
+
/** Calls the app's route mount, from its own page: what @synqauth/react and @synqauth/nextjs/client hand a plugin. */
|
|
15
|
+
export type MountRequest = (path: string, init?: RequestInit) => Promise<Response>;
|
|
16
|
+
/** What `signIn` takes besides the wallet. */
|
|
17
|
+
export interface SiwsSignInOptions {
|
|
18
|
+
/** Where on the app the person lands afterwards. */
|
|
19
|
+
returnTo?: string;
|
|
20
|
+
/** The account to sign with; the wallet's choice when left out. */
|
|
21
|
+
account?: WalletAccount;
|
|
22
|
+
}
|
|
23
|
+
/** The browser half's actions. */
|
|
24
|
+
export interface SiwsActions {
|
|
25
|
+
/**
|
|
26
|
+
* Signs in with `wallet`: the issuer's request, the wallet's signature,
|
|
27
|
+
* then off to Synq and back to `returnTo`. Answers `{ data, error }`
|
|
28
|
+
* instead of navigating when something fails: `wallet_rejected` when the
|
|
29
|
+
* person declines.
|
|
30
|
+
*/
|
|
31
|
+
signIn: (wallet: Wallet, options?: SiwsSignInOptions) => Promise<SiwsResult<null>>;
|
|
32
|
+
}
|
|
33
|
+
/** The SIWS plugin's browser half, in `SynqClientPlugin`'s shape: for `<SynqProvider plugins>` or `@synqauth/nextjs/client`. */
|
|
34
|
+
export interface SiwsPlugin {
|
|
35
|
+
readonly id: typeof SIWS_PLUGIN_ID;
|
|
36
|
+
actions: (request: MountRequest) => SiwsActions;
|
|
37
|
+
}
|
|
38
|
+
/** What `siwsPlugin()` takes. */
|
|
39
|
+
export interface SiwsPluginOptions {
|
|
40
|
+
/** Where the browser goes: `location.assign` by default. */
|
|
41
|
+
navigate?: (url: string) => void;
|
|
42
|
+
/** The `fetch` the page asks the issuer with: the global one by default. */
|
|
43
|
+
fetch?: typeof fetch;
|
|
44
|
+
}
|
|
45
|
+
/** The SIWS plugin's browser half: a wallet's sign-in from the app's own page, through the route mount. */
|
|
46
|
+
export declare function siwsPlugin(options?: SiwsPluginOptions): SiwsPlugin;
|
|
47
|
+
//#endregion
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { SynqError, problemError } from "@synqauth/js";
|
|
2
|
+
import { encodeSiws, requestSignIn, signWithWallet } from "@synqauth/solana";
|
|
3
|
+
//#region src/index.ts
|
|
4
|
+
/** The plugin's id: its server half's routes are under it, and its actions under it in `usePlugin`. */
|
|
5
|
+
const SIWS_PLUGIN_ID = "siws";
|
|
6
|
+
async function mountJson(request, path, init) {
|
|
7
|
+
let response;
|
|
8
|
+
try {
|
|
9
|
+
response = await request(path, init);
|
|
10
|
+
} catch (error) {
|
|
11
|
+
throw new SynqError("network_error", `The app couldn't be reached: ${String(error)}`, { cause: error });
|
|
12
|
+
}
|
|
13
|
+
const json = await response.json().catch(() => void 0);
|
|
14
|
+
if (!response.ok) throw problemError(response.status, json !== null && typeof json === "object" ? json : {});
|
|
15
|
+
return json;
|
|
16
|
+
}
|
|
17
|
+
/** The SIWS plugin's browser half: a wallet's sign-in from the app's own page, through the route mount. */
|
|
18
|
+
function siwsPlugin(options = {}) {
|
|
19
|
+
const navigate = options.navigate ?? ((url) => {
|
|
20
|
+
globalThis.location?.assign(url);
|
|
21
|
+
});
|
|
22
|
+
return {
|
|
23
|
+
id: SIWS_PLUGIN_ID,
|
|
24
|
+
actions: (request) => ({ signIn: async (wallet, signInOptions = {}) => {
|
|
25
|
+
try {
|
|
26
|
+
const { issuer, clientId } = await mountJson(request, `${SIWS_PLUGIN_ID}/config`);
|
|
27
|
+
const signInRequest = await requestSignIn({
|
|
28
|
+
issuer,
|
|
29
|
+
clientId,
|
|
30
|
+
fetch: options.fetch
|
|
31
|
+
});
|
|
32
|
+
const signed = await signWithWallet(wallet, signInRequest, signInOptions.account);
|
|
33
|
+
const { redirect } = await mountJson(request, "sign-in", {
|
|
34
|
+
method: "POST",
|
|
35
|
+
headers: { "content-type": "application/json" },
|
|
36
|
+
body: JSON.stringify({
|
|
37
|
+
siws: encodeSiws(signed),
|
|
38
|
+
returnTo: signInOptions.returnTo
|
|
39
|
+
})
|
|
40
|
+
});
|
|
41
|
+
navigate(redirect);
|
|
42
|
+
return {
|
|
43
|
+
data: null,
|
|
44
|
+
error: null
|
|
45
|
+
};
|
|
46
|
+
} catch (error) {
|
|
47
|
+
return {
|
|
48
|
+
data: null,
|
|
49
|
+
error: error instanceof SynqError ? error : new SynqError("network_error", String(error), { cause: error })
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
} })
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
//#endregion
|
|
56
|
+
export { SIWS_PLUGIN_ID, siwsPlugin };
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//#region src/server.d.ts
|
|
2
|
+
/** What a server plugin's route is handed: the part of @synqauth/nextjs's plugin context it reads. */
|
|
3
|
+
export interface SiwsRouteContext {
|
|
4
|
+
readonly issuer: string;
|
|
5
|
+
readonly clientId: string;
|
|
6
|
+
}
|
|
7
|
+
/** The server half, in @synqauth/nextjs's `SynqPlugin` shape. */
|
|
8
|
+
export interface SiwsServerPlugin {
|
|
9
|
+
readonly id: 'siws';
|
|
10
|
+
readonly routes: {
|
|
11
|
+
readonly 'GET /config': (context: SiwsRouteContext, request: Request) => Response;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
/** The SIWS plugin's server half, for `synqAuth({ plugins })`: it tells the page which issuer and app to ask for a sign-in request. */
|
|
15
|
+
export declare function siwsServerPlugin(): SiwsServerPlugin;
|
|
16
|
+
//#endregion
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region src/server.ts
|
|
2
|
+
/** The SIWS plugin's server half, for `synqAuth({ plugins })`: it tells the page which issuer and app to ask for a sign-in request. */
|
|
3
|
+
function siwsServerPlugin() {
|
|
4
|
+
return {
|
|
5
|
+
id: "siws",
|
|
6
|
+
routes: { "GET /config": (context) => Response.json({
|
|
7
|
+
issuer: context.issuer,
|
|
8
|
+
clientId: context.clientId
|
|
9
|
+
}, { headers: { "cache-control": "no-store" } }) }
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
13
|
+
export { siwsServerPlugin };
|
package/package.json
CHANGED
|
@@ -1,6 +1,46 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@synqauth/plugin-siws",
|
|
3
|
-
"version": "0.0.0
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "A Synq plugin for Sign In With Solana from your own UI.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/aerosol-build/synq.git",
|
|
9
|
+
"directory": "packages/plugin-siws"
|
|
10
|
+
},
|
|
11
|
+
"type": "module",
|
|
12
|
+
"sideEffects": false,
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": ">=22"
|
|
15
|
+
},
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"default": "./dist/index.js"
|
|
20
|
+
},
|
|
21
|
+
"./server": {
|
|
22
|
+
"types": "./dist/server.d.ts",
|
|
23
|
+
"default": "./dist/server.js"
|
|
24
|
+
},
|
|
25
|
+
"./package.json": "./package.json"
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"dist"
|
|
29
|
+
],
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@synqauth/js": "0.0.0",
|
|
35
|
+
"@synqauth/solana": "0.0.0"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"vitest": "5.0.2"
|
|
39
|
+
},
|
|
40
|
+
"scripts": {
|
|
41
|
+
"build": "tsdown",
|
|
42
|
+
"lint": "eslint .",
|
|
43
|
+
"typecheck": "tsc",
|
|
44
|
+
"test": "vitest run"
|
|
45
|
+
}
|
|
6
46
|
}
|