@solana/kit-plugin-wallet 0.0.0 → 0.12.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.
@@ -0,0 +1,133 @@
1
+ import { type ClientWithIdentity, type ClientWithPayer, type ClientWithSubscribeToIdentity, type ClientWithSubscribeToPayer } from '@solana/kit';
2
+ import type { ClientWithWallet, WalletPluginConfig } from './types';
3
+ /**
4
+ * A framework-agnostic Kit plugin that manages wallet discovery, connection
5
+ * lifecycle, and signer creation using wallet-standard — and syncs the
6
+ * connected wallet's signer to both `client.payer` and `client.identity`.
7
+ *
8
+ * This is the most common entrypoint for dApps. When a signing-capable
9
+ * wallet is connected, `client.payer` and `client.identity` both return the
10
+ * wallet signer. When disconnected or read-only, accessing either throws.
11
+ *
12
+ * Because the signer is dynamic, both `client.subscribeToPayer` and
13
+ * `client.subscribeToIdentity` are installed so reactive consumers can observe
14
+ * changes (the Kit reactive-capability convention).
15
+ *
16
+ * **SSR-safe.** Can be included in a shared client chain that runs on both
17
+ * server and browser.
18
+ *
19
+ * ```ts
20
+ * const client = createClient()
21
+ * .use(walletSigner({ chain: 'solana:mainnet' }))
22
+ * .use(solanaRpc({ rpcUrl: 'https://api.mainnet-beta.solana.com' }))
23
+ * .use(planAndSendTransactions());
24
+ * ```
25
+ *
26
+ * @param config - Plugin configuration.
27
+ *
28
+ * @see {@link walletPayer}
29
+ * @see {@link walletIdentity}
30
+ * @see {@link walletWithoutSigner}
31
+ * @see {@link WalletPluginConfig}
32
+ */
33
+ export declare function walletSigner(config: WalletPluginConfig): <T extends object & {
34
+ wallet?: never;
35
+ }>(client: T) => Disposable & Omit<T, "wallet" | "payer" | "identity" | "subscribeToIdentity" | "subscribeToPayer"> & ClientWithIdentity & ClientWithPayer & ClientWithSubscribeToIdentity & ClientWithSubscribeToPayer & ClientWithWallet;
36
+ /**
37
+ * A framework-agnostic Kit plugin that manages wallet discovery, connection
38
+ * lifecycle, and signer creation using wallet-standard — and syncs the
39
+ * connected wallet's signer to `client.identity`.
40
+ *
41
+ * Use this when `client.payer` is controlled by a separate `payer()` plugin
42
+ * (e.g. a backend relayer pays fees, but the user's wallet is the identity).
43
+ *
44
+ * Because the signer is dynamic, `client.subscribeToIdentity` is installed so
45
+ * reactive consumers can observe changes (the Kit reactive-capability convention).
46
+ *
47
+ * **SSR-safe.** Can be included in a shared client chain that runs on both
48
+ * server and browser.
49
+ *
50
+ * ```ts
51
+ * const client = createClient()
52
+ * .use(payer(relayerKeypair))
53
+ * .use(walletIdentity({ chain: 'solana:mainnet' }))
54
+ * .use(solanaRpc({ rpcUrl: 'https://api.mainnet-beta.solana.com' }))
55
+ * .use(planAndSendTransactions());
56
+ * ```
57
+ *
58
+ * @param config - Plugin configuration.
59
+ *
60
+ * @see {@link walletSigner}
61
+ * @see {@link walletPayer}
62
+ * @see {@link walletWithoutSigner}
63
+ * @see {@link WalletPluginConfig}
64
+ */
65
+ export declare function walletIdentity(config: WalletPluginConfig): <T extends object & {
66
+ wallet?: never;
67
+ }>(client: T) => Disposable & Omit<T, "wallet" | "identity" | "subscribeToIdentity"> & ClientWithIdentity & ClientWithSubscribeToIdentity & ClientWithWallet;
68
+ /**
69
+ * A framework-agnostic Kit plugin that manages wallet discovery, connection
70
+ * lifecycle, and signer creation using wallet-standard — and syncs the
71
+ * connected wallet's signer to `client.payer`.
72
+ *
73
+ * Use this when you need the wallet as the fee payer but don't need
74
+ * `client.identity`. For most dApps, prefer {@link walletSigner} which
75
+ * sets both.
76
+ *
77
+ * Because the signer is dynamic, `client.subscribeToPayer` is installed so
78
+ * reactive consumers can observe changes (the Kit reactive-capability convention).
79
+ *
80
+ * **SSR-safe.** Can be included in a shared client chain that runs on both
81
+ * server and browser.
82
+ *
83
+ * ```ts
84
+ * const client = createClient()
85
+ * .use(walletPayer({ chain: 'solana:mainnet' }))
86
+ * .use(solanaRpc({ rpcUrl: 'https://api.mainnet-beta.solana.com' }))
87
+ * .use(planAndSendTransactions());
88
+ * ```
89
+ *
90
+ * @param config - Plugin configuration.
91
+ *
92
+ * @see {@link walletSigner}
93
+ * @see {@link walletIdentity}
94
+ * @see {@link walletWithoutSigner}
95
+ * @see {@link WalletPluginConfig}
96
+ */
97
+ export declare function walletPayer(config: WalletPluginConfig): <T extends object & {
98
+ wallet?: never;
99
+ }>(client: T) => Disposable & Omit<T, "wallet" | "payer" | "subscribeToPayer"> & ClientWithPayer & ClientWithSubscribeToPayer & ClientWithWallet;
100
+ /**
101
+ * A framework-agnostic Kit plugin that manages wallet discovery, connection
102
+ * lifecycle, and signer creation using wallet-standard.
103
+ *
104
+ * Adds the `wallet` namespace to the client without setting `client.payer`
105
+ * or `client.identity`. Use this alongside separate `payer()` and/or
106
+ * `identity()` plugins, or when the wallet's signer is used explicitly in
107
+ * instructions. For most dApps, prefer {@link walletSigner} instead.
108
+ *
109
+ * **SSR-safe.** Can be included in a shared client chain that runs on both
110
+ * server and browser.
111
+ *
112
+ * ```ts
113
+ * const client = createClient()
114
+ * .use(payer(backendKeypair))
115
+ * .use(walletWithoutSigner({ chain: 'solana:mainnet' }))
116
+ * .use(solanaRpc({ rpcUrl: 'https://api.mainnet-beta.solana.com' }))
117
+ * .use(planAndSendTransactions());
118
+ *
119
+ * // client.payer is always backendKeypair
120
+ * // client.wallet.getState().connected?.signer for manual use
121
+ * ```
122
+ *
123
+ * @param config - Plugin configuration.
124
+ *
125
+ * @see {@link walletSigner}
126
+ * @see {@link walletPayer}
127
+ * @see {@link walletIdentity}
128
+ * @see {@link WalletPluginConfig}
129
+ */
130
+ export declare function walletWithoutSigner(config: WalletPluginConfig): <T extends object & {
131
+ wallet?: never;
132
+ }>(client: T) => Disposable & Omit<T, "wallet"> & ClientWithWallet;
133
+ //# sourceMappingURL=wallet.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../../src/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,KAAK,6BAA6B,EAClC,KAAK,0BAA0B,EAMlC,MAAM,aAAa,CAAC;AAGrB,OAAO,KAAK,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAgEpE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,kBAAkB,IAtD3C,CAAC;aAA6B,KAAK;2OA8D9C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,kBAAkB,IA7F7C,CAAC;aAA6B,KAAK;6JA+F9C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,kBAAkB,IA9H1C,CAAC;aAA6B,KAAK;iJAgI9C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,kBAAkB,IAhKlD,CAAC;aAA6B,KAAK;mEAkK9C"}
package/package.json CHANGED
@@ -1,12 +1,78 @@
1
1
  {
2
2
  "name": "@solana/kit-plugin-wallet",
3
- "version": "0.0.0",
4
- "description": "",
5
- "license": "ISC",
6
- "author": "",
3
+ "version": "0.12.0",
4
+ "description": "Wallet connection plugin for Kit clients",
5
+ "keywords": [
6
+ "kit",
7
+ "plugin",
8
+ "signer",
9
+ "solana",
10
+ "wallet",
11
+ "wallet-adapter",
12
+ "wallet-standard"
13
+ ],
14
+ "bugs": {
15
+ "url": "http://github.com/anza-xyz/kit-plugins/issues"
16
+ },
17
+ "license": "MIT",
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "https://github.com/anza-xyz/kit-plugins"
21
+ },
22
+ "files": [
23
+ "./dist/types",
24
+ "./dist/index.*",
25
+ "./src/"
26
+ ],
7
27
  "type": "commonjs",
8
- "main": "index.js",
28
+ "sideEffects": false,
29
+ "main": "./dist/index.node.cjs",
30
+ "module": "./dist/index.node.mjs",
31
+ "browser": {
32
+ "./dist/index.node.cjs": "./dist/index.browser.cjs",
33
+ "./dist/index.node.mjs": "./dist/index.browser.mjs"
34
+ },
35
+ "types": "./dist/types/index.d.ts",
36
+ "react-native": "./dist/index.react-native.mjs",
37
+ "exports": {
38
+ "types": "./dist/types/index.d.ts",
39
+ "react-native": "./dist/index.react-native.mjs",
40
+ "browser": {
41
+ "import": "./dist/index.browser.mjs",
42
+ "require": "./dist/index.browser.cjs"
43
+ },
44
+ "node": {
45
+ "import": "./dist/index.node.mjs",
46
+ "require": "./dist/index.node.cjs"
47
+ }
48
+ },
49
+ "dependencies": {
50
+ "@solana/wallet-account-signer": "^6.10.0",
51
+ "@solana/wallet-standard-chains": "^1.1.2",
52
+ "@solana/wallet-standard-features": "^1.4.0",
53
+ "@wallet-standard/app": "^1.1.1",
54
+ "@wallet-standard/base": "^1.1.1",
55
+ "@wallet-standard/features": "^1.1.1",
56
+ "@wallet-standard/ui": "^1.0.3",
57
+ "@wallet-standard/ui-features": "^1.0.3",
58
+ "@wallet-standard/ui-registry": "^1.1.1"
59
+ },
60
+ "devDependencies": {
61
+ "@wallet-standard/errors": "^0.1.2"
62
+ },
63
+ "peerDependencies": {
64
+ "@solana/kit": "^6.10.0"
65
+ },
66
+ "browserslist": [
67
+ "supports bigint and not dead",
68
+ "maintained node versions"
69
+ ],
9
70
  "scripts": {
10
- "test": "echo \"Error: no test specified\" && exit 1"
71
+ "build": "rimraf dist && tsup && tsc -p ./tsconfig.declarations.json",
72
+ "dev": "vitest --project node",
73
+ "test": "pnpm test:types && pnpm test:treeshakability && pnpm test:unit",
74
+ "test:treeshakability": "for file in dist/index.*.mjs; do agadoo $file; done",
75
+ "test:types": "tsc --noEmit",
76
+ "test:unit": "vitest run"
11
77
  }
12
- }
78
+ }
@@ -0,0 +1,114 @@
1
+ import {
2
+ type ClientWithIdentity,
3
+ type ClientWithPayer,
4
+ type ClientWithSubscribeToIdentity,
5
+ type ClientWithSubscribeToPayer,
6
+ createClient,
7
+ TransactionSigner,
8
+ } from '@solana/kit';
9
+
10
+ import { ClientWithWallet } from '../types';
11
+ import { walletIdentity, walletPayer, walletSigner, walletWithoutSigner } from '../wallet';
12
+
13
+ const config = { chain: 'solana:mainnet' as const };
14
+
15
+ const signer = null as unknown as TransactionSigner;
16
+
17
+ // [DESCRIBE] walletSigner
18
+ {
19
+ // It sets payer, identity, and wallet on the client.
20
+ {
21
+ const client = createClient().use(walletSigner(config));
22
+ client.payer satisfies ClientWithPayer['payer'];
23
+ client.identity satisfies ClientWithIdentity['identity'];
24
+ client.wallet satisfies ClientWithWallet['wallet'];
25
+ client.subscribeToPayer satisfies ClientWithSubscribeToPayer['subscribeToPayer'];
26
+ client.subscribeToIdentity satisfies ClientWithSubscribeToIdentity['subscribeToIdentity'];
27
+ }
28
+ }
29
+
30
+ // [DESCRIBE] walletPayer
31
+ {
32
+ // It sets payer and wallet on the client.
33
+ {
34
+ const client = createClient().use(walletPayer(config));
35
+ client.payer satisfies ClientWithPayer['payer'];
36
+ client.wallet satisfies ClientWithWallet['wallet'];
37
+ client.subscribeToPayer satisfies ClientWithSubscribeToPayer['subscribeToPayer'];
38
+ // @ts-expect-error walletPayer does not install subscribeToIdentity.
39
+ void client.subscribeToIdentity;
40
+ }
41
+ // It does not strip a previously-set identity.
42
+ {
43
+ const base = { identity: signer } as unknown as ClientWithIdentity;
44
+ const result = walletPayer(config)(base);
45
+ result.identity satisfies TransactionSigner;
46
+ }
47
+ }
48
+
49
+ // [DESCRIBE] walletIdentity
50
+ {
51
+ // It sets identity and wallet on the client.
52
+ {
53
+ const client = createClient().use(walletIdentity(config));
54
+ client.identity satisfies ClientWithIdentity['identity'];
55
+ client.wallet satisfies ClientWithWallet['wallet'];
56
+ client.subscribeToIdentity satisfies ClientWithSubscribeToIdentity['subscribeToIdentity'];
57
+ // @ts-expect-error walletIdentity does not install subscribeToPayer.
58
+ void client.subscribeToPayer;
59
+ }
60
+ // It does not strip a previously-set payer.
61
+ {
62
+ const base = { payer: signer } as unknown as ClientWithPayer;
63
+ const result = walletIdentity(config)(base);
64
+ result.payer satisfies TransactionSigner;
65
+ }
66
+ }
67
+
68
+ // [DESCRIBE] walletWithoutSigner
69
+ {
70
+ // It sets wallet on the client.
71
+ {
72
+ const client = createClient().use(walletWithoutSigner(config));
73
+ client.wallet satisfies ClientWithWallet['wallet'];
74
+ // @ts-expect-error walletWithoutSigner does not install subscribeToPayer.
75
+ void client.subscribeToPayer;
76
+ // @ts-expect-error walletWithoutSigner does not install subscribeToIdentity.
77
+ void client.subscribeToIdentity;
78
+ }
79
+ // It does not strip a previously-set payer.
80
+ {
81
+ const base = { payer: signer } as unknown as ClientWithPayer;
82
+ const result = walletWithoutSigner(config)(base);
83
+ result.payer satisfies TransactionSigner;
84
+ }
85
+ // It does not strip a previously-set identity.
86
+ {
87
+ const base = { identity: signer } as unknown as ClientWithIdentity;
88
+ const result = walletWithoutSigner(config)(base);
89
+ result.identity satisfies TransactionSigner;
90
+ }
91
+ // It does not strip a previously-set payer and identity.
92
+ {
93
+ const base = { identity: signer, payer: signer } as unknown as ClientWithIdentity & ClientWithPayer;
94
+ const result = walletWithoutSigner(config)(base);
95
+ result.payer satisfies TransactionSigner;
96
+ result.identity satisfies TransactionSigner;
97
+ }
98
+ }
99
+
100
+ // [DESCRIBE] Only one wallet plugin allowed
101
+ {
102
+ // It fails to typecheck when a wallet plugin is used on a client that already has wallet.
103
+ {
104
+ const client = createClient().use(walletSigner(config));
105
+ // @ts-expect-error Cannot use a second wallet plugin.
106
+ walletSigner(config)(client);
107
+ // @ts-expect-error Cannot use a second wallet plugin.
108
+ walletPayer(config)(client);
109
+ // @ts-expect-error Cannot use a second wallet plugin.
110
+ walletIdentity(config)(client);
111
+ // @ts-expect-error Cannot use a second wallet plugin.
112
+ walletWithoutSigner(config)(client);
113
+ }
114
+ }
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './types';
2
+ export * from './wallet';