@naculus/connector-reown 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/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +136 -0
- package/dist/index.d.ts +136 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/package.json +39 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Naculus
|
|
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/dist/index.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var u=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var l=Object.prototype.hasOwnProperty;var g=(r,n)=>{for(var e in n)u(r,e,{get:n[e],enumerable:!0})},m=(r,n,e,s)=>{if(n&&typeof n=="object"||typeof n=="function")for(let t of p(n))!l.call(r,t)&&t!==e&&u(r,t,{get:()=>n[t],enumerable:!(s=d(n,t))||s.enumerable});return r};var v=r=>m(u({},"__esModule",{value:!0}),r);var C={};g(C,{NaculusAppKitAdapter:()=>o,createNaculusAppKitAdapter:()=>w,isNaculusAppKitAdapter:()=>f});module.exports=v(C);var i=require("@naculus/connect-core"),h=require("@naculus/connector-walletconnect");function w(r){return new o(r)}var o=class{id="naculus";name="Naculus";connector;currentSession;currentChainId;listeners=new Map;constructor(n){this.connector=new h.WalletConnectConnector(n)}async connect(n){let e=await this.connector.connect(n);this.currentSession=e;let s=(0,i.extractAccounts)(e.namespaces).map(a=>a.split(":").pop()),t=e.namespaces.eip155?.chains;t&&t.length>0?this.currentChainId=t[0]:this.currentChainId="eip155:1";let c=Number(this.currentChainId.split(":")[1]);return{provider:this.createProvider(),accounts:s,chainId:c}}async disconnect(){this.currentSession&&(await this.connector.disconnect(this.currentSession),this.currentSession=void 0,this.currentChainId=void 0)}async reconnect(n){let e=await this.connector.reconnect(n);this.currentSession=e;let s=(0,i.extractAccounts)(e.namespaces).map(a=>a.split(":").pop()),t=e.namespaces.eip155?.chains,c=t?Number(t[0].split(":")[1]):1;return{provider:this.createProvider(),accounts:s,chainId:c}}async getAccounts(){if(!this.currentSession)return[];let n=(0,i.extractAccounts)(this.currentSession.namespaces).map(e=>e.split(":").pop());return[...new Set(n)]}async getChainId(){return this.currentChainId?Number(this.currentChainId.split(":")[1]):this.currentSession?.namespaces.eip155?.chains[0]?Number(this.currentSession.namespaces.eip155.chains[0].split(":")[1]):1}getProvider(){return this.createProvider()}async switchChain(n){let e=`eip155:${n}`;if(this.currentSession)try{await this.connector.switchChain(this.currentSession,e)}catch(s){throw new i.WalletError("chain_switch_rejected",`Failed to switch to chain ${n}: ${s}`)}this.currentChainId=e}async signMessage(n,e,s){if(!this.currentSession)throw new i.WalletError("session_expired","No active session.");let t=await this.connector.signMessage(this.currentSession,{message:n,address:e,chainId:s?`eip155:${s}`:void 0});return String(t)}async sendTransaction(n,e){if(!this.currentSession)throw new i.WalletError("session_expired","No active session.");let s=await this.connector.sendTransaction(this.currentSession,{transaction:n,chainId:e?`eip155:${e}`:void 0});return String(s)}async signTypedData(n,e,s){if(!this.currentSession)throw new i.WalletError("session_expired","No active session.");let t=await this.connector.signTypedData(this.currentSession,{typedData:n,address:e,chainId:s?`eip155:${s}`:void 0});return String(t)}getSession(){return this.currentSession}on(n,e){this.listeners.has(n)||this.listeners.set(n,new Set),this.listeners.get(n).add(e)}removeListener(n,e){this.listeners.get(n)?.delete(e)}emit(n,...e){let s=this.listeners.get(n);s&&s.forEach(t=>t(...e))}createProvider(){return{request:async({method:n,params:e})=>{if(!this.currentSession)throw new i.WalletError("session_expired","No active session.");return this.connector.request({method:n,params:e??[]})},on:(n,e)=>{this.on(n,e)},removeListener:(n,e)=>{this.removeListener(n,e)}}}};function f(r){return r instanceof o}0&&(module.exports={NaculusAppKitAdapter,createNaculusAppKitAdapter,isNaculusAppKitAdapter});
|
|
2
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { UniversalWalletSession } from \"@naculus/connect-core\";\nimport { extractAccounts, WalletError } from \"@naculus/connect-core\";\nimport {\n type WalletConnectConfig,\n WalletConnectConnector,\n} from \"@naculus/connector-walletconnect\";\n\nexport type {\n WalletConnectConfig,\n WalletConnectConnectInput,\n WalletConnectConnector,\n WalletConnectMetadata,\n} from \"@naculus/connector-walletconnect\";\n\n/**\n * Reown AppKit-compatible adapter for @naculus/connector-walletconnect.\n *\n * Provides `createNaculusAppKitAdapter()` which returns an adapter object\n * that can be used with Reown AppKit's `adapters` option. This allows any\n * dApp using Reown AppKit to integrate Naculus's WalletConnect connector\n * as a first-class wallet option.\n *\n * The adapter wraps a WalletConnectConnector and exposes AppKit-compatible\n * connect, disconnect, and reconnection flows.\n *\n * @example\n * ```typescript\n * import { createNaculusAppKitAdapter } from \"@naculus/connector-reown\";\n * import { createAppKit } from \"@reown/appkit\";\n *\n * const naculusAdapter = createNaculusAppKitAdapter({\n * projectId: \"your-project-id\",\n * metadata: { name: \"My DApp\", description: \"...\", url: \"...\", icons: [] },\n * });\n *\n * const appKit = createAppKit({\n * projectId: \"your-project-id\",\n * adapters: [naculusAdapter],\n * networks: [mainnet, polygon],\n * metadata: { name: \"My DApp\", description: \"...\", url: \"...\", icons: [] },\n * });\n * ```\n */\nexport function createNaculusAppKitAdapter(\n config: WalletConnectConfig,\n): NaculusAppKitAdapter {\n return new NaculusAppKitAdapter(config);\n}\n\n/**\n * Naculus AppKit adapter class.\n *\n * Provides an interface compatible with Reown AppKit's expected adapter shape.\n * Each instance wraps a WalletConnectConnector and exposes:\n * - `connect()` / `disconnect()` / `reconnect()`\n * - `getAccounts()` / `getChainId()`\n * - EIP-1193 provider via `getProvider()`\n * - Standard event emitter interface\n */\nexport class NaculusAppKitAdapter {\n /** Adapter identity */\n readonly id = \"naculus\";\n readonly name = \"Naculus\";\n\n /** Underlying Naculus WalletConnect connector */\n readonly connector: WalletConnectConnector;\n\n private currentSession?: UniversalWalletSession;\n private currentChainId?: string;\n private listeners: Map<string, Set<(...args: unknown[]) => void>> = new Map();\n\n constructor(config: WalletConnectConfig) {\n this.connector = new WalletConnectConnector(config);\n }\n\n /**\n * Connect to a wallet.\n * Returns EIP-1193 provider and account info.\n */\n async connect(input?: unknown): Promise<{\n provider: NaculusProvider;\n accounts: string[];\n chainId: number;\n }> {\n const session = await this.connector.connect(input);\n this.currentSession = session;\n\n const accounts = extractAccounts(session.namespaces).map(\n (a: string) => a.split(\":\").pop()!,\n );\n\n // Determine chain ID from session\n const evmChains = session.namespaces.eip155?.chains;\n if (evmChains && evmChains.length > 0) {\n this.currentChainId = evmChains[0];\n } else {\n this.currentChainId = \"eip155:1\";\n }\n\n const chainId = Number(this.currentChainId.split(\":\")[1]);\n\n return {\n provider: this.createProvider(),\n accounts,\n chainId,\n };\n }\n\n /**\n * Disconnect the current session.\n */\n async disconnect(): Promise<void> {\n if (this.currentSession) {\n await this.connector.disconnect(this.currentSession);\n this.currentSession = undefined;\n this.currentChainId = undefined;\n }\n }\n\n /**\n * Reconnect to an existing session.\n */\n async reconnect(session: UniversalWalletSession): Promise<{\n provider: NaculusProvider;\n accounts: string[];\n chainId: number;\n }> {\n const restored = await this.connector.reconnect(session);\n this.currentSession = restored;\n\n const accounts = extractAccounts(restored.namespaces).map(\n (a: string) => a.split(\":\").pop()!,\n );\n\n const evmChains = restored.namespaces.eip155?.chains;\n const chainId = evmChains ? Number(evmChains[0].split(\":\")[1]) : 1;\n\n return {\n provider: this.createProvider(),\n accounts,\n chainId,\n };\n }\n\n /**\n * Get connected accounts.\n */\n async getAccounts(): Promise<string[]> {\n if (!this.currentSession) return [];\n const accounts = extractAccounts(this.currentSession.namespaces).map(\n (a: string) => a.split(\":\").pop()!,\n );\n return [...new Set(accounts)];\n }\n\n /**\n * Get the current chain ID.\n */\n async getChainId(): Promise<number> {\n if (this.currentChainId) {\n return Number(this.currentChainId.split(\":\")[1]);\n }\n\n if (this.currentSession?.namespaces.eip155?.chains[0]) {\n return Number(\n this.currentSession.namespaces.eip155.chains[0].split(\":\")[1],\n );\n }\n\n return 1;\n }\n\n /**\n * Get EIP-1193 provider.\n */\n getProvider(): NaculusProvider {\n return this.createProvider();\n }\n\n /**\n * Switch to a different chain.\n */\n async switchChain(chainId: number): Promise<void> {\n const caip2Chain = `eip155:${chainId}`;\n\n if (this.currentSession) {\n try {\n await this.connector.switchChain(this.currentSession, caip2Chain);\n } catch (error) {\n throw new WalletError(\n \"chain_switch_rejected\",\n `Failed to switch to chain ${chainId}: ${error}`,\n );\n }\n }\n\n this.currentChainId = caip2Chain;\n }\n\n /**\n * Sign a message.\n */\n async signMessage(\n message: string,\n address: string,\n chainId?: number,\n ): Promise<string> {\n if (!this.currentSession) {\n throw new WalletError(\"session_expired\", \"No active session.\");\n }\n\n const result = await this.connector.signMessage(this.currentSession, {\n message,\n address,\n chainId: chainId ? `eip155:${chainId}` : undefined,\n });\n\n return String(result);\n }\n\n /**\n * Send a transaction.\n */\n async sendTransaction(\n transaction: Record<string, unknown>,\n chainId?: number,\n ): Promise<string> {\n if (!this.currentSession) {\n throw new WalletError(\"session_expired\", \"No active session.\");\n }\n\n const result = await this.connector.sendTransaction(this.currentSession, {\n transaction,\n chainId: chainId ? `eip155:${chainId}` : undefined,\n });\n\n return String(result);\n }\n\n /**\n * Sign typed data (EIP-712)\n */\n async signTypedData(\n typedData: string,\n address: string,\n chainId?: number,\n ): Promise<string> {\n if (!this.currentSession) {\n throw new WalletError(\"session_expired\", \"No active session.\");\n }\n\n const result = await this.connector.signTypedData(this.currentSession, {\n typedData,\n address,\n chainId: chainId ? `eip155:${chainId}` : undefined,\n });\n\n return String(result);\n }\n\n /**\n * Get the current session, if any.\n */\n getSession(): UniversalWalletSession | undefined {\n return this.currentSession;\n }\n\n /**\n * Listen for events.\n */\n on(event: string, handler: (...args: unknown[]) => void): void {\n if (!this.listeners.has(event)) {\n this.listeners.set(event, new Set());\n }\n this.listeners.get(event)!.add(handler);\n }\n\n /**\n * Remove event listener.\n */\n removeListener(event: string, handler: (...args: unknown[]) => void): void {\n this.listeners.get(event)?.delete(handler);\n }\n\n /**\n * Emit an event to all listeners.\n */\n private emit(event: string, ...args: unknown[]): void {\n const handlers = this.listeners.get(event);\n if (handlers) {\n handlers.forEach((handler) => handler(...args));\n }\n }\n\n private createProvider(): NaculusProvider {\n return {\n request: async ({\n method,\n params,\n }: {\n method: string;\n params?: unknown[];\n }) => {\n if (!this.currentSession) {\n throw new WalletError(\"session_expired\", \"No active session.\");\n }\n return this.connector.request({\n method,\n params: params ?? [],\n });\n },\n on: (event: string, handler: (...args: unknown[]) => void) => {\n this.on(event, handler);\n },\n removeListener: (\n event: string,\n handler: (...args: unknown[]) => void,\n ) => {\n this.removeListener(event, handler);\n },\n };\n }\n}\n\n/** Minimal EIP-1193 provider interface */\nexport interface NaculusProvider {\n request(args: { method: string; params?: unknown[] }): Promise<unknown>;\n on(event: string, handler: (...args: unknown[]) => void): void;\n removeListener(event: string, handler: (...args: unknown[]) => void): void;\n}\n\n/**\n * Type guard: check if an object is a NaculusAppKitAdapter.\n */\nexport function isNaculusAppKitAdapter(\n obj: unknown,\n): obj is NaculusAppKitAdapter {\n return obj instanceof NaculusAppKitAdapter;\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,0BAAAE,EAAA,+BAAAC,EAAA,2BAAAC,IAAA,eAAAC,EAAAL,GACA,IAAAM,EAA6C,iCAC7CC,EAGO,4CAsCA,SAASJ,EACdK,EACsB,CACtB,OAAO,IAAIN,EAAqBM,CAAM,CACxC,CAYO,IAAMN,EAAN,KAA2B,CAEvB,GAAK,UACL,KAAO,UAGP,UAED,eACA,eACA,UAA4D,IAAI,IAExE,YAAYM,EAA6B,CACvC,KAAK,UAAY,IAAI,yBAAuBA,CAAM,CACpD,CAMA,MAAM,QAAQC,EAIX,CACD,IAAMC,EAAU,MAAM,KAAK,UAAU,QAAQD,CAAK,EAClD,KAAK,eAAiBC,EAEtB,IAAMC,KAAW,mBAAgBD,EAAQ,UAAU,EAAE,IAClD,GAAc,EAAE,MAAM,GAAG,EAAE,IAAI,CAClC,EAGME,EAAYF,EAAQ,WAAW,QAAQ,OACzCE,GAAaA,EAAU,OAAS,EAClC,KAAK,eAAiBA,EAAU,CAAC,EAEjC,KAAK,eAAiB,WAGxB,IAAMC,EAAU,OAAO,KAAK,eAAe,MAAM,GAAG,EAAE,CAAC,CAAC,EAExD,MAAO,CACL,SAAU,KAAK,eAAe,EAC9B,SAAAF,EACA,QAAAE,CACF,CACF,CAKA,MAAM,YAA4B,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S,MAAO,CACd,OAAAE,EACA,OAAAC,CACF,IAGM,CACJ,GAAI,CAAC,KAAK,eACR,MAAM,IAAI,cAAY,kBAAmB,oBAAoB,EAE/D,OAAO,KAAK,UAAU,QAAQ,CAC5B,OAAAD,EACA,OAAQC,GAAU,CAAC,CACrB,CAAC,CACH,EACA,GAAI,CAACL,EAAeC,IAA0C,CAC5D,KAAK,GAAGD,EAAOC,CAAO,CACxB,EACA,eAAgB,CACdD,EACAC,IACG,CACH,KAAK,eAAeD,EAAOC,CAAO,CACpC,CACF,CACF,CACF,EAYO,SAASpB,EACdyB,EAC6B,CAC7B,OAAOA,aAAe3B,CACxB","names":["index_exports","__export","NaculusAppKitAdapter","createNaculusAppKitAdapter","isNaculusAppKitAdapter","__toCommonJS","import_connect_core","import_connector_walletconnect","config","input","session","accounts","evmChains","chainId","restored","a","caip2Chain","error","message","address","result","transaction","typedData","event","handler","args","handlers","method","params","obj"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { UniversalWalletSession } from '@naculus/connect-core';
|
|
2
|
+
import { WalletConnectConnector, WalletConnectConfig } from '@naculus/connector-walletconnect';
|
|
3
|
+
export { WalletConnectConfig, WalletConnectConnectInput, WalletConnectConnector, WalletConnectMetadata } from '@naculus/connector-walletconnect';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Reown AppKit-compatible adapter for @naculus/connector-walletconnect.
|
|
7
|
+
*
|
|
8
|
+
* Provides `createNaculusAppKitAdapter()` which returns an adapter object
|
|
9
|
+
* that can be used with Reown AppKit's `adapters` option. This allows any
|
|
10
|
+
* dApp using Reown AppKit to integrate Naculus's WalletConnect connector
|
|
11
|
+
* as a first-class wallet option.
|
|
12
|
+
*
|
|
13
|
+
* The adapter wraps a WalletConnectConnector and exposes AppKit-compatible
|
|
14
|
+
* connect, disconnect, and reconnection flows.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* import { createNaculusAppKitAdapter } from "@naculus/connector-reown";
|
|
19
|
+
* import { createAppKit } from "@reown/appkit";
|
|
20
|
+
*
|
|
21
|
+
* const naculusAdapter = createNaculusAppKitAdapter({
|
|
22
|
+
* projectId: "your-project-id",
|
|
23
|
+
* metadata: { name: "My DApp", description: "...", url: "...", icons: [] },
|
|
24
|
+
* });
|
|
25
|
+
*
|
|
26
|
+
* const appKit = createAppKit({
|
|
27
|
+
* projectId: "your-project-id",
|
|
28
|
+
* adapters: [naculusAdapter],
|
|
29
|
+
* networks: [mainnet, polygon],
|
|
30
|
+
* metadata: { name: "My DApp", description: "...", url: "...", icons: [] },
|
|
31
|
+
* });
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
declare function createNaculusAppKitAdapter(config: WalletConnectConfig): NaculusAppKitAdapter;
|
|
35
|
+
/**
|
|
36
|
+
* Naculus AppKit adapter class.
|
|
37
|
+
*
|
|
38
|
+
* Provides an interface compatible with Reown AppKit's expected adapter shape.
|
|
39
|
+
* Each instance wraps a WalletConnectConnector and exposes:
|
|
40
|
+
* - `connect()` / `disconnect()` / `reconnect()`
|
|
41
|
+
* - `getAccounts()` / `getChainId()`
|
|
42
|
+
* - EIP-1193 provider via `getProvider()`
|
|
43
|
+
* - Standard event emitter interface
|
|
44
|
+
*/
|
|
45
|
+
declare class NaculusAppKitAdapter {
|
|
46
|
+
/** Adapter identity */
|
|
47
|
+
readonly id = "naculus";
|
|
48
|
+
readonly name = "Naculus";
|
|
49
|
+
/** Underlying Naculus WalletConnect connector */
|
|
50
|
+
readonly connector: WalletConnectConnector;
|
|
51
|
+
private currentSession?;
|
|
52
|
+
private currentChainId?;
|
|
53
|
+
private listeners;
|
|
54
|
+
constructor(config: WalletConnectConfig);
|
|
55
|
+
/**
|
|
56
|
+
* Connect to a wallet.
|
|
57
|
+
* Returns EIP-1193 provider and account info.
|
|
58
|
+
*/
|
|
59
|
+
connect(input?: unknown): Promise<{
|
|
60
|
+
provider: NaculusProvider;
|
|
61
|
+
accounts: string[];
|
|
62
|
+
chainId: number;
|
|
63
|
+
}>;
|
|
64
|
+
/**
|
|
65
|
+
* Disconnect the current session.
|
|
66
|
+
*/
|
|
67
|
+
disconnect(): Promise<void>;
|
|
68
|
+
/**
|
|
69
|
+
* Reconnect to an existing session.
|
|
70
|
+
*/
|
|
71
|
+
reconnect(session: UniversalWalletSession): Promise<{
|
|
72
|
+
provider: NaculusProvider;
|
|
73
|
+
accounts: string[];
|
|
74
|
+
chainId: number;
|
|
75
|
+
}>;
|
|
76
|
+
/**
|
|
77
|
+
* Get connected accounts.
|
|
78
|
+
*/
|
|
79
|
+
getAccounts(): Promise<string[]>;
|
|
80
|
+
/**
|
|
81
|
+
* Get the current chain ID.
|
|
82
|
+
*/
|
|
83
|
+
getChainId(): Promise<number>;
|
|
84
|
+
/**
|
|
85
|
+
* Get EIP-1193 provider.
|
|
86
|
+
*/
|
|
87
|
+
getProvider(): NaculusProvider;
|
|
88
|
+
/**
|
|
89
|
+
* Switch to a different chain.
|
|
90
|
+
*/
|
|
91
|
+
switchChain(chainId: number): Promise<void>;
|
|
92
|
+
/**
|
|
93
|
+
* Sign a message.
|
|
94
|
+
*/
|
|
95
|
+
signMessage(message: string, address: string, chainId?: number): Promise<string>;
|
|
96
|
+
/**
|
|
97
|
+
* Send a transaction.
|
|
98
|
+
*/
|
|
99
|
+
sendTransaction(transaction: Record<string, unknown>, chainId?: number): Promise<string>;
|
|
100
|
+
/**
|
|
101
|
+
* Sign typed data (EIP-712)
|
|
102
|
+
*/
|
|
103
|
+
signTypedData(typedData: string, address: string, chainId?: number): Promise<string>;
|
|
104
|
+
/**
|
|
105
|
+
* Get the current session, if any.
|
|
106
|
+
*/
|
|
107
|
+
getSession(): UniversalWalletSession | undefined;
|
|
108
|
+
/**
|
|
109
|
+
* Listen for events.
|
|
110
|
+
*/
|
|
111
|
+
on(event: string, handler: (...args: unknown[]) => void): void;
|
|
112
|
+
/**
|
|
113
|
+
* Remove event listener.
|
|
114
|
+
*/
|
|
115
|
+
removeListener(event: string, handler: (...args: unknown[]) => void): void;
|
|
116
|
+
/**
|
|
117
|
+
* Emit an event to all listeners.
|
|
118
|
+
*/
|
|
119
|
+
private emit;
|
|
120
|
+
private createProvider;
|
|
121
|
+
}
|
|
122
|
+
/** Minimal EIP-1193 provider interface */
|
|
123
|
+
interface NaculusProvider {
|
|
124
|
+
request(args: {
|
|
125
|
+
method: string;
|
|
126
|
+
params?: unknown[];
|
|
127
|
+
}): Promise<unknown>;
|
|
128
|
+
on(event: string, handler: (...args: unknown[]) => void): void;
|
|
129
|
+
removeListener(event: string, handler: (...args: unknown[]) => void): void;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Type guard: check if an object is a NaculusAppKitAdapter.
|
|
133
|
+
*/
|
|
134
|
+
declare function isNaculusAppKitAdapter(obj: unknown): obj is NaculusAppKitAdapter;
|
|
135
|
+
|
|
136
|
+
export { NaculusAppKitAdapter, type NaculusProvider, createNaculusAppKitAdapter, isNaculusAppKitAdapter };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { UniversalWalletSession } from '@naculus/connect-core';
|
|
2
|
+
import { WalletConnectConnector, WalletConnectConfig } from '@naculus/connector-walletconnect';
|
|
3
|
+
export { WalletConnectConfig, WalletConnectConnectInput, WalletConnectConnector, WalletConnectMetadata } from '@naculus/connector-walletconnect';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Reown AppKit-compatible adapter for @naculus/connector-walletconnect.
|
|
7
|
+
*
|
|
8
|
+
* Provides `createNaculusAppKitAdapter()` which returns an adapter object
|
|
9
|
+
* that can be used with Reown AppKit's `adapters` option. This allows any
|
|
10
|
+
* dApp using Reown AppKit to integrate Naculus's WalletConnect connector
|
|
11
|
+
* as a first-class wallet option.
|
|
12
|
+
*
|
|
13
|
+
* The adapter wraps a WalletConnectConnector and exposes AppKit-compatible
|
|
14
|
+
* connect, disconnect, and reconnection flows.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* import { createNaculusAppKitAdapter } from "@naculus/connector-reown";
|
|
19
|
+
* import { createAppKit } from "@reown/appkit";
|
|
20
|
+
*
|
|
21
|
+
* const naculusAdapter = createNaculusAppKitAdapter({
|
|
22
|
+
* projectId: "your-project-id",
|
|
23
|
+
* metadata: { name: "My DApp", description: "...", url: "...", icons: [] },
|
|
24
|
+
* });
|
|
25
|
+
*
|
|
26
|
+
* const appKit = createAppKit({
|
|
27
|
+
* projectId: "your-project-id",
|
|
28
|
+
* adapters: [naculusAdapter],
|
|
29
|
+
* networks: [mainnet, polygon],
|
|
30
|
+
* metadata: { name: "My DApp", description: "...", url: "...", icons: [] },
|
|
31
|
+
* });
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
declare function createNaculusAppKitAdapter(config: WalletConnectConfig): NaculusAppKitAdapter;
|
|
35
|
+
/**
|
|
36
|
+
* Naculus AppKit adapter class.
|
|
37
|
+
*
|
|
38
|
+
* Provides an interface compatible with Reown AppKit's expected adapter shape.
|
|
39
|
+
* Each instance wraps a WalletConnectConnector and exposes:
|
|
40
|
+
* - `connect()` / `disconnect()` / `reconnect()`
|
|
41
|
+
* - `getAccounts()` / `getChainId()`
|
|
42
|
+
* - EIP-1193 provider via `getProvider()`
|
|
43
|
+
* - Standard event emitter interface
|
|
44
|
+
*/
|
|
45
|
+
declare class NaculusAppKitAdapter {
|
|
46
|
+
/** Adapter identity */
|
|
47
|
+
readonly id = "naculus";
|
|
48
|
+
readonly name = "Naculus";
|
|
49
|
+
/** Underlying Naculus WalletConnect connector */
|
|
50
|
+
readonly connector: WalletConnectConnector;
|
|
51
|
+
private currentSession?;
|
|
52
|
+
private currentChainId?;
|
|
53
|
+
private listeners;
|
|
54
|
+
constructor(config: WalletConnectConfig);
|
|
55
|
+
/**
|
|
56
|
+
* Connect to a wallet.
|
|
57
|
+
* Returns EIP-1193 provider and account info.
|
|
58
|
+
*/
|
|
59
|
+
connect(input?: unknown): Promise<{
|
|
60
|
+
provider: NaculusProvider;
|
|
61
|
+
accounts: string[];
|
|
62
|
+
chainId: number;
|
|
63
|
+
}>;
|
|
64
|
+
/**
|
|
65
|
+
* Disconnect the current session.
|
|
66
|
+
*/
|
|
67
|
+
disconnect(): Promise<void>;
|
|
68
|
+
/**
|
|
69
|
+
* Reconnect to an existing session.
|
|
70
|
+
*/
|
|
71
|
+
reconnect(session: UniversalWalletSession): Promise<{
|
|
72
|
+
provider: NaculusProvider;
|
|
73
|
+
accounts: string[];
|
|
74
|
+
chainId: number;
|
|
75
|
+
}>;
|
|
76
|
+
/**
|
|
77
|
+
* Get connected accounts.
|
|
78
|
+
*/
|
|
79
|
+
getAccounts(): Promise<string[]>;
|
|
80
|
+
/**
|
|
81
|
+
* Get the current chain ID.
|
|
82
|
+
*/
|
|
83
|
+
getChainId(): Promise<number>;
|
|
84
|
+
/**
|
|
85
|
+
* Get EIP-1193 provider.
|
|
86
|
+
*/
|
|
87
|
+
getProvider(): NaculusProvider;
|
|
88
|
+
/**
|
|
89
|
+
* Switch to a different chain.
|
|
90
|
+
*/
|
|
91
|
+
switchChain(chainId: number): Promise<void>;
|
|
92
|
+
/**
|
|
93
|
+
* Sign a message.
|
|
94
|
+
*/
|
|
95
|
+
signMessage(message: string, address: string, chainId?: number): Promise<string>;
|
|
96
|
+
/**
|
|
97
|
+
* Send a transaction.
|
|
98
|
+
*/
|
|
99
|
+
sendTransaction(transaction: Record<string, unknown>, chainId?: number): Promise<string>;
|
|
100
|
+
/**
|
|
101
|
+
* Sign typed data (EIP-712)
|
|
102
|
+
*/
|
|
103
|
+
signTypedData(typedData: string, address: string, chainId?: number): Promise<string>;
|
|
104
|
+
/**
|
|
105
|
+
* Get the current session, if any.
|
|
106
|
+
*/
|
|
107
|
+
getSession(): UniversalWalletSession | undefined;
|
|
108
|
+
/**
|
|
109
|
+
* Listen for events.
|
|
110
|
+
*/
|
|
111
|
+
on(event: string, handler: (...args: unknown[]) => void): void;
|
|
112
|
+
/**
|
|
113
|
+
* Remove event listener.
|
|
114
|
+
*/
|
|
115
|
+
removeListener(event: string, handler: (...args: unknown[]) => void): void;
|
|
116
|
+
/**
|
|
117
|
+
* Emit an event to all listeners.
|
|
118
|
+
*/
|
|
119
|
+
private emit;
|
|
120
|
+
private createProvider;
|
|
121
|
+
}
|
|
122
|
+
/** Minimal EIP-1193 provider interface */
|
|
123
|
+
interface NaculusProvider {
|
|
124
|
+
request(args: {
|
|
125
|
+
method: string;
|
|
126
|
+
params?: unknown[];
|
|
127
|
+
}): Promise<unknown>;
|
|
128
|
+
on(event: string, handler: (...args: unknown[]) => void): void;
|
|
129
|
+
removeListener(event: string, handler: (...args: unknown[]) => void): void;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Type guard: check if an object is a NaculusAppKitAdapter.
|
|
133
|
+
*/
|
|
134
|
+
declare function isNaculusAppKitAdapter(obj: unknown): obj is NaculusAppKitAdapter;
|
|
135
|
+
|
|
136
|
+
export { NaculusAppKitAdapter, type NaculusProvider, createNaculusAppKitAdapter, isNaculusAppKitAdapter };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{extractAccounts as u,WalletError as r}from"@naculus/connect-core";import{WalletConnectConnector as h}from"@naculus/connector-walletconnect";function l(i){return new o(i)}var o=class{id="naculus";name="Naculus";connector;currentSession;currentChainId;listeners=new Map;constructor(e){this.connector=new h(e)}async connect(e){let n=await this.connector.connect(e);this.currentSession=n;let s=u(n.namespaces).map(a=>a.split(":").pop()),t=n.namespaces.eip155?.chains;t&&t.length>0?this.currentChainId=t[0]:this.currentChainId="eip155:1";let c=Number(this.currentChainId.split(":")[1]);return{provider:this.createProvider(),accounts:s,chainId:c}}async disconnect(){this.currentSession&&(await this.connector.disconnect(this.currentSession),this.currentSession=void 0,this.currentChainId=void 0)}async reconnect(e){let n=await this.connector.reconnect(e);this.currentSession=n;let s=u(n.namespaces).map(a=>a.split(":").pop()),t=n.namespaces.eip155?.chains,c=t?Number(t[0].split(":")[1]):1;return{provider:this.createProvider(),accounts:s,chainId:c}}async getAccounts(){if(!this.currentSession)return[];let e=u(this.currentSession.namespaces).map(n=>n.split(":").pop());return[...new Set(e)]}async getChainId(){return this.currentChainId?Number(this.currentChainId.split(":")[1]):this.currentSession?.namespaces.eip155?.chains[0]?Number(this.currentSession.namespaces.eip155.chains[0].split(":")[1]):1}getProvider(){return this.createProvider()}async switchChain(e){let n=`eip155:${e}`;if(this.currentSession)try{await this.connector.switchChain(this.currentSession,n)}catch(s){throw new r("chain_switch_rejected",`Failed to switch to chain ${e}: ${s}`)}this.currentChainId=n}async signMessage(e,n,s){if(!this.currentSession)throw new r("session_expired","No active session.");let t=await this.connector.signMessage(this.currentSession,{message:e,address:n,chainId:s?`eip155:${s}`:void 0});return String(t)}async sendTransaction(e,n){if(!this.currentSession)throw new r("session_expired","No active session.");let s=await this.connector.sendTransaction(this.currentSession,{transaction:e,chainId:n?`eip155:${n}`:void 0});return String(s)}async signTypedData(e,n,s){if(!this.currentSession)throw new r("session_expired","No active session.");let t=await this.connector.signTypedData(this.currentSession,{typedData:e,address:n,chainId:s?`eip155:${s}`:void 0});return String(t)}getSession(){return this.currentSession}on(e,n){this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(n)}removeListener(e,n){this.listeners.get(e)?.delete(n)}emit(e,...n){let s=this.listeners.get(e);s&&s.forEach(t=>t(...n))}createProvider(){return{request:async({method:e,params:n})=>{if(!this.currentSession)throw new r("session_expired","No active session.");return this.connector.request({method:e,params:n??[]})},on:(e,n)=>{this.on(e,n)},removeListener:(e,n)=>{this.removeListener(e,n)}}}};function g(i){return i instanceof o}export{o as NaculusAppKitAdapter,l as createNaculusAppKitAdapter,g as isNaculusAppKitAdapter};
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { UniversalWalletSession } from \"@naculus/connect-core\";\nimport { extractAccounts, WalletError } from \"@naculus/connect-core\";\nimport {\n type WalletConnectConfig,\n WalletConnectConnector,\n} from \"@naculus/connector-walletconnect\";\n\nexport type {\n WalletConnectConfig,\n WalletConnectConnectInput,\n WalletConnectConnector,\n WalletConnectMetadata,\n} from \"@naculus/connector-walletconnect\";\n\n/**\n * Reown AppKit-compatible adapter for @naculus/connector-walletconnect.\n *\n * Provides `createNaculusAppKitAdapter()` which returns an adapter object\n * that can be used with Reown AppKit's `adapters` option. This allows any\n * dApp using Reown AppKit to integrate Naculus's WalletConnect connector\n * as a first-class wallet option.\n *\n * The adapter wraps a WalletConnectConnector and exposes AppKit-compatible\n * connect, disconnect, and reconnection flows.\n *\n * @example\n * ```typescript\n * import { createNaculusAppKitAdapter } from \"@naculus/connector-reown\";\n * import { createAppKit } from \"@reown/appkit\";\n *\n * const naculusAdapter = createNaculusAppKitAdapter({\n * projectId: \"your-project-id\",\n * metadata: { name: \"My DApp\", description: \"...\", url: \"...\", icons: [] },\n * });\n *\n * const appKit = createAppKit({\n * projectId: \"your-project-id\",\n * adapters: [naculusAdapter],\n * networks: [mainnet, polygon],\n * metadata: { name: \"My DApp\", description: \"...\", url: \"...\", icons: [] },\n * });\n * ```\n */\nexport function createNaculusAppKitAdapter(\n config: WalletConnectConfig,\n): NaculusAppKitAdapter {\n return new NaculusAppKitAdapter(config);\n}\n\n/**\n * Naculus AppKit adapter class.\n *\n * Provides an interface compatible with Reown AppKit's expected adapter shape.\n * Each instance wraps a WalletConnectConnector and exposes:\n * - `connect()` / `disconnect()` / `reconnect()`\n * - `getAccounts()` / `getChainId()`\n * - EIP-1193 provider via `getProvider()`\n * - Standard event emitter interface\n */\nexport class NaculusAppKitAdapter {\n /** Adapter identity */\n readonly id = \"naculus\";\n readonly name = \"Naculus\";\n\n /** Underlying Naculus WalletConnect connector */\n readonly connector: WalletConnectConnector;\n\n private currentSession?: UniversalWalletSession;\n private currentChainId?: string;\n private listeners: Map<string, Set<(...args: unknown[]) => void>> = new Map();\n\n constructor(config: WalletConnectConfig) {\n this.connector = new WalletConnectConnector(config);\n }\n\n /**\n * Connect to a wallet.\n * Returns EIP-1193 provider and account info.\n */\n async connect(input?: unknown): Promise<{\n provider: NaculusProvider;\n accounts: string[];\n chainId: number;\n }> {\n const session = await this.connector.connect(input);\n this.currentSession = session;\n\n const accounts = extractAccounts(session.namespaces).map(\n (a: string) => a.split(\":\").pop()!,\n );\n\n // Determine chain ID from session\n const evmChains = session.namespaces.eip155?.chains;\n if (evmChains && evmChains.length > 0) {\n this.currentChainId = evmChains[0];\n } else {\n this.currentChainId = \"eip155:1\";\n }\n\n const chainId = Number(this.currentChainId.split(\":\")[1]);\n\n return {\n provider: this.createProvider(),\n accounts,\n chainId,\n };\n }\n\n /**\n * Disconnect the current session.\n */\n async disconnect(): Promise<void> {\n if (this.currentSession) {\n await this.connector.disconnect(this.currentSession);\n this.currentSession = undefined;\n this.currentChainId = undefined;\n }\n }\n\n /**\n * Reconnect to an existing session.\n */\n async reconnect(session: UniversalWalletSession): Promise<{\n provider: NaculusProvider;\n accounts: string[];\n chainId: number;\n }> {\n const restored = await this.connector.reconnect(session);\n this.currentSession = restored;\n\n const accounts = extractAccounts(restored.namespaces).map(\n (a: string) => a.split(\":\").pop()!,\n );\n\n const evmChains = restored.namespaces.eip155?.chains;\n const chainId = evmChains ? Number(evmChains[0].split(\":\")[1]) : 1;\n\n return {\n provider: this.createProvider(),\n accounts,\n chainId,\n };\n }\n\n /**\n * Get connected accounts.\n */\n async getAccounts(): Promise<string[]> {\n if (!this.currentSession) return [];\n const accounts = extractAccounts(this.currentSession.namespaces).map(\n (a: string) => a.split(\":\").pop()!,\n );\n return [...new Set(accounts)];\n }\n\n /**\n * Get the current chain ID.\n */\n async getChainId(): Promise<number> {\n if (this.currentChainId) {\n return Number(this.currentChainId.split(\":\")[1]);\n }\n\n if (this.currentSession?.namespaces.eip155?.chains[0]) {\n return Number(\n this.currentSession.namespaces.eip155.chains[0].split(\":\")[1],\n );\n }\n\n return 1;\n }\n\n /**\n * Get EIP-1193 provider.\n */\n getProvider(): NaculusProvider {\n return this.createProvider();\n }\n\n /**\n * Switch to a different chain.\n */\n async switchChain(chainId: number): Promise<void> {\n const caip2Chain = `eip155:${chainId}`;\n\n if (this.currentSession) {\n try {\n await this.connector.switchChain(this.currentSession, caip2Chain);\n } catch (error) {\n throw new WalletError(\n \"chain_switch_rejected\",\n `Failed to switch to chain ${chainId}: ${error}`,\n );\n }\n }\n\n this.currentChainId = caip2Chain;\n }\n\n /**\n * Sign a message.\n */\n async signMessage(\n message: string,\n address: string,\n chainId?: number,\n ): Promise<string> {\n if (!this.currentSession) {\n throw new WalletError(\"session_expired\", \"No active session.\");\n }\n\n const result = await this.connector.signMessage(this.currentSession, {\n message,\n address,\n chainId: chainId ? `eip155:${chainId}` : undefined,\n });\n\n return String(result);\n }\n\n /**\n * Send a transaction.\n */\n async sendTransaction(\n transaction: Record<string, unknown>,\n chainId?: number,\n ): Promise<string> {\n if (!this.currentSession) {\n throw new WalletError(\"session_expired\", \"No active session.\");\n }\n\n const result = await this.connector.sendTransaction(this.currentSession, {\n transaction,\n chainId: chainId ? `eip155:${chainId}` : undefined,\n });\n\n return String(result);\n }\n\n /**\n * Sign typed data (EIP-712)\n */\n async signTypedData(\n typedData: string,\n address: string,\n chainId?: number,\n ): Promise<string> {\n if (!this.currentSession) {\n throw new WalletError(\"session_expired\", \"No active session.\");\n }\n\n const result = await this.connector.signTypedData(this.currentSession, {\n typedData,\n address,\n chainId: chainId ? `eip155:${chainId}` : undefined,\n });\n\n return String(result);\n }\n\n /**\n * Get the current session, if any.\n */\n getSession(): UniversalWalletSession | undefined {\n return this.currentSession;\n }\n\n /**\n * Listen for events.\n */\n on(event: string, handler: (...args: unknown[]) => void): void {\n if (!this.listeners.has(event)) {\n this.listeners.set(event, new Set());\n }\n this.listeners.get(event)!.add(handler);\n }\n\n /**\n * Remove event listener.\n */\n removeListener(event: string, handler: (...args: unknown[]) => void): void {\n this.listeners.get(event)?.delete(handler);\n }\n\n /**\n * Emit an event to all listeners.\n */\n private emit(event: string, ...args: unknown[]): void {\n const handlers = this.listeners.get(event);\n if (handlers) {\n handlers.forEach((handler) => handler(...args));\n }\n }\n\n private createProvider(): NaculusProvider {\n return {\n request: async ({\n method,\n params,\n }: {\n method: string;\n params?: unknown[];\n }) => {\n if (!this.currentSession) {\n throw new WalletError(\"session_expired\", \"No active session.\");\n }\n return this.connector.request({\n method,\n params: params ?? [],\n });\n },\n on: (event: string, handler: (...args: unknown[]) => void) => {\n this.on(event, handler);\n },\n removeListener: (\n event: string,\n handler: (...args: unknown[]) => void,\n ) => {\n this.removeListener(event, handler);\n },\n };\n }\n}\n\n/** Minimal EIP-1193 provider interface */\nexport interface NaculusProvider {\n request(args: { method: string; params?: unknown[] }): Promise<unknown>;\n on(event: string, handler: (...args: unknown[]) => void): void;\n removeListener(event: string, handler: (...args: unknown[]) => void): void;\n}\n\n/**\n * Type guard: check if an object is a NaculusAppKitAdapter.\n */\nexport function isNaculusAppKitAdapter(\n obj: unknown,\n): obj is NaculusAppKitAdapter {\n return obj instanceof NaculusAppKitAdapter;\n}\n"],"mappings":"AACA,OAAS,mBAAAA,EAAiB,eAAAC,MAAmB,wBAC7C,OAEE,0BAAAC,MACK,mCAsCA,SAASC,EACdC,EACsB,CACtB,OAAO,IAAIC,EAAqBD,CAAM,CACxC,CAYO,IAAMC,EAAN,KAA2B,CAEvB,GAAK,UACL,KAAO,UAGP,UAED,eACA,eACA,UAA4D,IAAI,IAExE,YAAYD,EAA6B,CACvC,KAAK,UAAY,IAAIF,EAAuBE,CAAM,CACpD,CAMA,MAAM,QAAQE,EAIX,CACD,IAAMC,EAAU,MAAM,KAAK,UAAU,QAAQD,CAAK,EAClD,KAAK,eAAiBC,EAEtB,IAAMC,EAAWR,EAAgBO,EAAQ,UAAU,EAAE,IAClD,GAAc,EAAE,MAAM,GAAG,EAAE,IAAI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,EAAG,IAAIC,CAAO,CACxC,CAKA,eAAeD,EAAeC,EAA6C,CACzE,KAAK,UAAU,IAAID,CAAK,GAAG,OAAOC,CAAO,CAC3C,CAKQ,KAAKD,KAAkBE,EAAuB,CACpD,IAAMC,EAAW,KAAK,UAAU,IAAIH,CAAK,EACrCG,GACFA,EAAS,QAASF,GAAYA,EAAQ,GAAGC,CAAI,CAAC,CAElD,CAEQ,gBAAkC,CACxC,MAAO,CACL,QAAS,MAAO,CACd,OAAAE,EACA,OAAAC,CACF,IAGM,CACJ,GAAI,CAAC,KAAK,eACR,MAAM,IAAIxB,EAAY,kBAAmB,oBAAoB,EAE/D,OAAO,KAAK,UAAU,QAAQ,CAC5B,OAAAuB,EACA,OAAQC,GAAU,CAAC,CACrB,CAAC,CACH,EACA,GAAI,CAACL,EAAeC,IAA0C,CAC5D,KAAK,GAAGD,EAAOC,CAAO,CACxB,EACA,eAAgB,CACdD,EACAC,IACG,CACH,KAAK,eAAeD,EAAOC,CAAO,CACpC,CACF,CACF,CACF,EAYO,SAASK,EACdC,EAC6B,CAC7B,OAAOA,aAAetB,CACxB","names":["extractAccounts","WalletError","WalletConnectConnector","createNaculusAppKitAdapter","config","NaculusAppKitAdapter","input","session","accounts","evmChains","chainId","restored","a","caip2Chain","error","message","address","result","transaction","typedData","event","handler","args","handlers","method","params","isNaculusAppKitAdapter","obj"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@naculus/connector-reown",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"default": "./dist/index.js"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@naculus/connect-core": "0.1.0",
|
|
18
|
+
"@naculus/connector-walletconnect": "0.1.0"
|
|
19
|
+
},
|
|
20
|
+
"peerDependencies": {
|
|
21
|
+
"@reown/appkit": "^1.0.0",
|
|
22
|
+
"viem": "^2.0.0"
|
|
23
|
+
},
|
|
24
|
+
"peerDependenciesMeta": {
|
|
25
|
+
"@reown/appkit": {
|
|
26
|
+
"optional": true
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"tsup": "^8.3.6",
|
|
31
|
+
"typescript": "^5.9.3",
|
|
32
|
+
"viem": "^2.21.0"
|
|
33
|
+
},
|
|
34
|
+
"sideEffects": false,
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "tsup",
|
|
37
|
+
"clean": "rm -rf dist"
|
|
38
|
+
}
|
|
39
|
+
}
|