@miden-sdk/use-miden-para-react 0.10.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +98 -0
- package/dist/index.d.mts +28 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.js +106 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +71 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +64 -0
- package/src/index.ts +1 -0
- package/src/useParaMiden.ts +104 -0
package/README.md
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# @miden-sdk/use-miden-para-react
|
|
2
|
+
|
|
3
|
+
React hook that wires Para accounts into a Miden client.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @miden-sdk/use-miden-para-react
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Peer Dependencies
|
|
12
|
+
|
|
13
|
+
`@miden-sdk/use-miden-para-react` expects these packages to be provided by the consuming app. Install matching versions alongside this package to avoid duplicate copies:
|
|
14
|
+
|
|
15
|
+
- `@demox-labs/miden-sdk@^0.12.5`
|
|
16
|
+
- `@getpara/react-sdk-lite@^2.2.0`
|
|
17
|
+
- `@miden-sdk/miden-para@^0.10.10`
|
|
18
|
+
- `react@^18.0.0 || ^19.0.0`
|
|
19
|
+
|
|
20
|
+
Example install:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
yarn add @miden-sdk/use-miden-para-react @demox-labs/miden-sdk@^0.12.5 @getpara/react-sdk-lite@^2.2.0 @miden-sdk/miden-para@^0.10.10 react@^18.0.0
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
```tsx
|
|
29
|
+
import '@getpara/react-sdk-lite/styles.css';
|
|
30
|
+
import { ParaProvider, useAccount, useModal } from '@getpara/react-sdk-lite';
|
|
31
|
+
import { useParaMiden } from '@miden-sdk/use-miden-para-react';
|
|
32
|
+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
|
33
|
+
|
|
34
|
+
const queryClient = new QueryClient();
|
|
35
|
+
|
|
36
|
+
function App() {
|
|
37
|
+
return (
|
|
38
|
+
<QueryClientProvider client={queryClient}>
|
|
39
|
+
<ParaProvider
|
|
40
|
+
paraClientConfig={{
|
|
41
|
+
apiKey: import.meta.env.VITE_PARA_API_KEY,
|
|
42
|
+
}}
|
|
43
|
+
config={{ appName: 'Starter for MidenxPara' }}
|
|
44
|
+
>
|
|
45
|
+
<Content />
|
|
46
|
+
</ParaProvider>
|
|
47
|
+
</QueryClientProvider>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function Content() {
|
|
52
|
+
const { client, accountId, para } = useParaMiden('https://rpc.testnet.miden.io');
|
|
53
|
+
const { isConnected } = useAccount();
|
|
54
|
+
const { openModal } = useModal();
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<div>
|
|
58
|
+
<button onClick={() => isConnected ? para.logout() : openModal?.()}>
|
|
59
|
+
{isConnected ? 'Disconnect Para' : 'Connect with Para'}
|
|
60
|
+
</button>
|
|
61
|
+
{isConnected &&
|
|
62
|
+
<>
|
|
63
|
+
<p>Account: {accountId ?? '—'}</p>
|
|
64
|
+
<p>Client ready: {client ? 'yes' : 'no'}</p>
|
|
65
|
+
</>
|
|
66
|
+
}
|
|
67
|
+
</div>
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
For production apps, you must use a Para **production** API key. Use a non-prod key for local/dev environments.
|
|
73
|
+
|
|
74
|
+
Pass a custom transaction confirmation step as the optional fourth argument if you want to show your own popup before Para signs:
|
|
75
|
+
|
|
76
|
+
```tsx
|
|
77
|
+
const confirmTx = async (summary) => {
|
|
78
|
+
await openCustomModal(summary);
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const { client } = useParaMiden(
|
|
82
|
+
'https://rpc.testnet.miden.io',
|
|
83
|
+
'public',
|
|
84
|
+
{},
|
|
85
|
+
true, // set to false to skip the built-in modal
|
|
86
|
+
confirmTx
|
|
87
|
+
);
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
If you switch the hook to `storageMode` set to `private`, pass an `accountSeed` via the third argument so the underlying client can initialize; this is required for private accounts and the hook will throw if it is omitted.
|
|
91
|
+
|
|
92
|
+
## Build
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
npm run build
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Outputs `dist/index.mjs`, `dist/index.cjs`, and `dist/index.d.ts`. Use `npm pack` to inspect the tarball before publishing.
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import * as _getpara_react_sdk_lite from '@getpara/react-sdk-lite';
|
|
2
|
+
import * as _demox_labs_miden_sdk from '@demox-labs/miden-sdk';
|
|
3
|
+
import { MidenAccountStorageMode, Opts, CustomSignConfirmStep } from '@miden-sdk/miden-para';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* React hook that converts Para React SDK context into a ready-to-use Miden WebClient.
|
|
7
|
+
* Spawns the client once a Para session with at least one EVM wallet is active.
|
|
8
|
+
*
|
|
9
|
+
* Returns:
|
|
10
|
+
* - client: WebClient instance backed by the active Para session (or null while loading)
|
|
11
|
+
* - accountId: Miden account id derived for the selected EVM wallet
|
|
12
|
+
* - para: Para client instance from context
|
|
13
|
+
* - evmWallets: filtered list of Para wallets with type === 'EVM'
|
|
14
|
+
* - nodeUrl: Miden node endpoint used for the client
|
|
15
|
+
* - opts: forwarded options used when creating the client
|
|
16
|
+
* - showSigningModal: toggles the built-in signing modal
|
|
17
|
+
* - customSignConfirmStep: optional callback for custom transaction confirmation flows
|
|
18
|
+
*/
|
|
19
|
+
declare function useParaMiden(nodeUrl: string, storageMode?: MidenAccountStorageMode, opts?: Omit<Opts, 'endpoint' | 'type' | 'storageMode'>, showSigningModal?: boolean, customSignConfirmStep?: CustomSignConfirmStep): {
|
|
20
|
+
client: _demox_labs_miden_sdk.WebClient | null;
|
|
21
|
+
accountId: string;
|
|
22
|
+
para: _getpara_react_sdk_lite.default | undefined;
|
|
23
|
+
evmWallets: _getpara_react_sdk_lite.AvailableWallet[] | undefined;
|
|
24
|
+
nodeUrl: string;
|
|
25
|
+
opts: Omit<Opts, "type" | "endpoint" | "storageMode">;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export { useParaMiden };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import * as _getpara_react_sdk_lite from '@getpara/react-sdk-lite';
|
|
2
|
+
import * as _demox_labs_miden_sdk from '@demox-labs/miden-sdk';
|
|
3
|
+
import { MidenAccountStorageMode, Opts, CustomSignConfirmStep } from '@miden-sdk/miden-para';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* React hook that converts Para React SDK context into a ready-to-use Miden WebClient.
|
|
7
|
+
* Spawns the client once a Para session with at least one EVM wallet is active.
|
|
8
|
+
*
|
|
9
|
+
* Returns:
|
|
10
|
+
* - client: WebClient instance backed by the active Para session (or null while loading)
|
|
11
|
+
* - accountId: Miden account id derived for the selected EVM wallet
|
|
12
|
+
* - para: Para client instance from context
|
|
13
|
+
* - evmWallets: filtered list of Para wallets with type === 'EVM'
|
|
14
|
+
* - nodeUrl: Miden node endpoint used for the client
|
|
15
|
+
* - opts: forwarded options used when creating the client
|
|
16
|
+
* - showSigningModal: toggles the built-in signing modal
|
|
17
|
+
* - customSignConfirmStep: optional callback for custom transaction confirmation flows
|
|
18
|
+
*/
|
|
19
|
+
declare function useParaMiden(nodeUrl: string, storageMode?: MidenAccountStorageMode, opts?: Omit<Opts, 'endpoint' | 'type' | 'storageMode'>, showSigningModal?: boolean, customSignConfirmStep?: CustomSignConfirmStep): {
|
|
20
|
+
client: _demox_labs_miden_sdk.WebClient | null;
|
|
21
|
+
accountId: string;
|
|
22
|
+
para: _getpara_react_sdk_lite.default | undefined;
|
|
23
|
+
evmWallets: _getpara_react_sdk_lite.AvailableWallet[] | undefined;
|
|
24
|
+
nodeUrl: string;
|
|
25
|
+
opts: Omit<Opts, "type" | "endpoint" | "storageMode">;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export { useParaMiden };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
useParaMiden: () => useParaMiden
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(index_exports);
|
|
36
|
+
|
|
37
|
+
// src/useParaMiden.ts
|
|
38
|
+
var import_react_sdk_lite = require("@getpara/react-sdk-lite");
|
|
39
|
+
var import_react = require("react");
|
|
40
|
+
var import_miden_para = require("@miden-sdk/miden-para");
|
|
41
|
+
function useParaMiden(nodeUrl, storageMode = "public", opts = {}, showSigningModal = true, customSignConfirmStep) {
|
|
42
|
+
const para = (0, import_react_sdk_lite.useClient)();
|
|
43
|
+
const { isConnected, embedded } = (0, import_react_sdk_lite.useAccount)();
|
|
44
|
+
const clientRef = (0, import_react.useRef)(
|
|
45
|
+
null
|
|
46
|
+
);
|
|
47
|
+
const [accountId, setAccountId] = (0, import_react.useState)("");
|
|
48
|
+
const evmWallets = (0, import_react.useMemo)(
|
|
49
|
+
() => {
|
|
50
|
+
var _a;
|
|
51
|
+
return (_a = embedded.wallets) == null ? void 0 : _a.filter((wallet) => wallet.type === "EVM");
|
|
52
|
+
},
|
|
53
|
+
[embedded.wallets]
|
|
54
|
+
);
|
|
55
|
+
(0, import_react.useEffect)(() => {
|
|
56
|
+
let cancelled = false;
|
|
57
|
+
async function setupClient() {
|
|
58
|
+
var _a;
|
|
59
|
+
if (!isConnected || !para || !((_a = embedded.wallets) == null ? void 0 : _a.length) || clientRef.current) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const { AccountType } = await import("@demox-labs/miden-sdk");
|
|
63
|
+
const { client: midenParaClient, accountId: aId } = await (0, import_miden_para.createParaMidenClient)(
|
|
64
|
+
para,
|
|
65
|
+
evmWallets,
|
|
66
|
+
{
|
|
67
|
+
...opts,
|
|
68
|
+
endpoint: nodeUrl,
|
|
69
|
+
type: AccountType.RegularAccountImmutableCode,
|
|
70
|
+
storageMode
|
|
71
|
+
},
|
|
72
|
+
showSigningModal,
|
|
73
|
+
customSignConfirmStep
|
|
74
|
+
);
|
|
75
|
+
if (cancelled) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
clientRef.current = midenParaClient;
|
|
79
|
+
setAccountId(aId);
|
|
80
|
+
}
|
|
81
|
+
setupClient();
|
|
82
|
+
return () => {
|
|
83
|
+
cancelled = true;
|
|
84
|
+
};
|
|
85
|
+
}, [
|
|
86
|
+
isConnected,
|
|
87
|
+
evmWallets,
|
|
88
|
+
para,
|
|
89
|
+
nodeUrl,
|
|
90
|
+
showSigningModal,
|
|
91
|
+
customSignConfirmStep
|
|
92
|
+
]);
|
|
93
|
+
return {
|
|
94
|
+
client: clientRef.current,
|
|
95
|
+
accountId,
|
|
96
|
+
para,
|
|
97
|
+
evmWallets,
|
|
98
|
+
nodeUrl,
|
|
99
|
+
opts
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
103
|
+
0 && (module.exports = {
|
|
104
|
+
useParaMiden
|
|
105
|
+
});
|
|
106
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/useParaMiden.ts"],"sourcesContent":["export { useParaMiden } from './useParaMiden';\n","'use client';\n\nimport { useClient, useAccount, type Wallet } from '@getpara/react-sdk-lite';\nimport { useEffect, useMemo, useRef, useState } from 'react';\nimport {\n createParaMidenClient,\n type Opts,\n type MidenAccountStorageMode,\n type CustomSignConfirmStep,\n} from '@miden-sdk/miden-para';\n\n/**\n * React hook that converts Para React SDK context into a ready-to-use Miden WebClient.\n * Spawns the client once a Para session with at least one EVM wallet is active.\n *\n * Returns:\n * - client: WebClient instance backed by the active Para session (or null while loading)\n * - accountId: Miden account id derived for the selected EVM wallet\n * - para: Para client instance from context\n * - evmWallets: filtered list of Para wallets with type === 'EVM'\n * - nodeUrl: Miden node endpoint used for the client\n * - opts: forwarded options used when creating the client\n * - showSigningModal: toggles the built-in signing modal\n * - customSignConfirmStep: optional callback for custom transaction confirmation flows\n */\nexport function useParaMiden(\n nodeUrl: string,\n storageMode: MidenAccountStorageMode = 'public',\n opts: Omit<Opts, 'endpoint' | 'type' | 'storageMode'> = {},\n showSigningModal: boolean = true,\n customSignConfirmStep?: CustomSignConfirmStep\n) {\n const para = useClient();\n const { isConnected, embedded } = useAccount();\n const clientRef = useRef<import('@demox-labs/miden-sdk').WebClient | null>(\n null\n );\n const [accountId, setAccountId] = useState<string>('');\n\n const evmWallets = useMemo(\n () => embedded.wallets?.filter((wallet) => wallet.type === 'EVM'),\n [embedded.wallets]\n );\n\n useEffect(() => {\n let cancelled = false;\n\n async function setupClient() {\n if (\n !isConnected ||\n !para ||\n !embedded.wallets?.length ||\n clientRef.current\n ) {\n return;\n }\n\n const { AccountType } = await import('@demox-labs/miden-sdk');\n\n const { client: midenParaClient, accountId: aId } =\n await createParaMidenClient(\n para,\n evmWallets as Wallet[],\n {\n ...opts,\n endpoint: nodeUrl,\n type: AccountType.RegularAccountImmutableCode,\n storageMode,\n },\n showSigningModal,\n customSignConfirmStep\n );\n\n if (cancelled) {\n return;\n }\n\n clientRef.current = midenParaClient;\n setAccountId(aId);\n }\n\n setupClient();\n\n return () => {\n cancelled = true;\n };\n }, [\n isConnected,\n evmWallets,\n para,\n nodeUrl,\n showSigningModal,\n customSignConfirmStep,\n ]);\n\n return {\n client: clientRef.current,\n accountId,\n para,\n evmWallets,\n nodeUrl,\n opts,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEA,4BAAmD;AACnD,mBAAqD;AACrD,wBAKO;AAgBA,SAAS,aACd,SACA,cAAuC,UACvC,OAAwD,CAAC,GACzD,mBAA4B,MAC5B,uBACA;AACA,QAAM,WAAO,iCAAU;AACvB,QAAM,EAAE,aAAa,SAAS,QAAI,kCAAW;AAC7C,QAAM,gBAAY;AAAA,IAChB;AAAA,EACF;AACA,QAAM,CAAC,WAAW,YAAY,QAAI,uBAAiB,EAAE;AAErD,QAAM,iBAAa;AAAA,IACjB,MAAG;AAxCP;AAwCU,4BAAS,YAAT,mBAAkB,OAAO,CAAC,WAAW,OAAO,SAAS;AAAA;AAAA,IAC3D,CAAC,SAAS,OAAO;AAAA,EACnB;AAEA,8BAAU,MAAM;AACd,QAAI,YAAY;AAEhB,mBAAe,cAAc;AA/CjC;AAgDM,UACE,CAAC,eACD,CAAC,QACD,GAAC,cAAS,YAAT,mBAAkB,WACnB,UAAU,SACV;AACA;AAAA,MACF;AAEA,YAAM,EAAE,YAAY,IAAI,MAAM,OAAO,uBAAuB;AAE5D,YAAM,EAAE,QAAQ,iBAAiB,WAAW,IAAI,IAC9C,UAAM;AAAA,QACJ;AAAA,QACA;AAAA,QACA;AAAA,UACE,GAAG;AAAA,UACH,UAAU;AAAA,UACV,MAAM,YAAY;AAAA,UAClB;AAAA,QACF;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAEF,UAAI,WAAW;AACb;AAAA,MACF;AAEA,gBAAU,UAAU;AACpB,mBAAa,GAAG;AAAA,IAClB;AAEA,gBAAY;AAEZ,WAAO,MAAM;AACX,kBAAY;AAAA,IACd;AAAA,EACF,GAAG;AAAA,IACD;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AAED,SAAO;AAAA,IACL,QAAQ,UAAU;AAAA,IAClB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// src/useParaMiden.ts
|
|
2
|
+
import { useClient, useAccount } from "@getpara/react-sdk-lite";
|
|
3
|
+
import { useEffect, useMemo, useRef, useState } from "react";
|
|
4
|
+
import {
|
|
5
|
+
createParaMidenClient
|
|
6
|
+
} from "@miden-sdk/miden-para";
|
|
7
|
+
function useParaMiden(nodeUrl, storageMode = "public", opts = {}, showSigningModal = true, customSignConfirmStep) {
|
|
8
|
+
const para = useClient();
|
|
9
|
+
const { isConnected, embedded } = useAccount();
|
|
10
|
+
const clientRef = useRef(
|
|
11
|
+
null
|
|
12
|
+
);
|
|
13
|
+
const [accountId, setAccountId] = useState("");
|
|
14
|
+
const evmWallets = useMemo(
|
|
15
|
+
() => {
|
|
16
|
+
var _a;
|
|
17
|
+
return (_a = embedded.wallets) == null ? void 0 : _a.filter((wallet) => wallet.type === "EVM");
|
|
18
|
+
},
|
|
19
|
+
[embedded.wallets]
|
|
20
|
+
);
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
let cancelled = false;
|
|
23
|
+
async function setupClient() {
|
|
24
|
+
var _a;
|
|
25
|
+
if (!isConnected || !para || !((_a = embedded.wallets) == null ? void 0 : _a.length) || clientRef.current) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const { AccountType } = await import("@demox-labs/miden-sdk");
|
|
29
|
+
const { client: midenParaClient, accountId: aId } = await createParaMidenClient(
|
|
30
|
+
para,
|
|
31
|
+
evmWallets,
|
|
32
|
+
{
|
|
33
|
+
...opts,
|
|
34
|
+
endpoint: nodeUrl,
|
|
35
|
+
type: AccountType.RegularAccountImmutableCode,
|
|
36
|
+
storageMode
|
|
37
|
+
},
|
|
38
|
+
showSigningModal,
|
|
39
|
+
customSignConfirmStep
|
|
40
|
+
);
|
|
41
|
+
if (cancelled) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
clientRef.current = midenParaClient;
|
|
45
|
+
setAccountId(aId);
|
|
46
|
+
}
|
|
47
|
+
setupClient();
|
|
48
|
+
return () => {
|
|
49
|
+
cancelled = true;
|
|
50
|
+
};
|
|
51
|
+
}, [
|
|
52
|
+
isConnected,
|
|
53
|
+
evmWallets,
|
|
54
|
+
para,
|
|
55
|
+
nodeUrl,
|
|
56
|
+
showSigningModal,
|
|
57
|
+
customSignConfirmStep
|
|
58
|
+
]);
|
|
59
|
+
return {
|
|
60
|
+
client: clientRef.current,
|
|
61
|
+
accountId,
|
|
62
|
+
para,
|
|
63
|
+
evmWallets,
|
|
64
|
+
nodeUrl,
|
|
65
|
+
opts
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
export {
|
|
69
|
+
useParaMiden
|
|
70
|
+
};
|
|
71
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/useParaMiden.ts"],"sourcesContent":["'use client';\n\nimport { useClient, useAccount, type Wallet } from '@getpara/react-sdk-lite';\nimport { useEffect, useMemo, useRef, useState } from 'react';\nimport {\n createParaMidenClient,\n type Opts,\n type MidenAccountStorageMode,\n type CustomSignConfirmStep,\n} from '@miden-sdk/miden-para';\n\n/**\n * React hook that converts Para React SDK context into a ready-to-use Miden WebClient.\n * Spawns the client once a Para session with at least one EVM wallet is active.\n *\n * Returns:\n * - client: WebClient instance backed by the active Para session (or null while loading)\n * - accountId: Miden account id derived for the selected EVM wallet\n * - para: Para client instance from context\n * - evmWallets: filtered list of Para wallets with type === 'EVM'\n * - nodeUrl: Miden node endpoint used for the client\n * - opts: forwarded options used when creating the client\n * - showSigningModal: toggles the built-in signing modal\n * - customSignConfirmStep: optional callback for custom transaction confirmation flows\n */\nexport function useParaMiden(\n nodeUrl: string,\n storageMode: MidenAccountStorageMode = 'public',\n opts: Omit<Opts, 'endpoint' | 'type' | 'storageMode'> = {},\n showSigningModal: boolean = true,\n customSignConfirmStep?: CustomSignConfirmStep\n) {\n const para = useClient();\n const { isConnected, embedded } = useAccount();\n const clientRef = useRef<import('@demox-labs/miden-sdk').WebClient | null>(\n null\n );\n const [accountId, setAccountId] = useState<string>('');\n\n const evmWallets = useMemo(\n () => embedded.wallets?.filter((wallet) => wallet.type === 'EVM'),\n [embedded.wallets]\n );\n\n useEffect(() => {\n let cancelled = false;\n\n async function setupClient() {\n if (\n !isConnected ||\n !para ||\n !embedded.wallets?.length ||\n clientRef.current\n ) {\n return;\n }\n\n const { AccountType } = await import('@demox-labs/miden-sdk');\n\n const { client: midenParaClient, accountId: aId } =\n await createParaMidenClient(\n para,\n evmWallets as Wallet[],\n {\n ...opts,\n endpoint: nodeUrl,\n type: AccountType.RegularAccountImmutableCode,\n storageMode,\n },\n showSigningModal,\n customSignConfirmStep\n );\n\n if (cancelled) {\n return;\n }\n\n clientRef.current = midenParaClient;\n setAccountId(aId);\n }\n\n setupClient();\n\n return () => {\n cancelled = true;\n };\n }, [\n isConnected,\n evmWallets,\n para,\n nodeUrl,\n showSigningModal,\n customSignConfirmStep,\n ]);\n\n return {\n client: clientRef.current,\n accountId,\n para,\n evmWallets,\n nodeUrl,\n opts,\n };\n}\n"],"mappings":";AAEA,SAAS,WAAW,kBAA+B;AACnD,SAAS,WAAW,SAAS,QAAQ,gBAAgB;AACrD;AAAA,EACE;AAAA,OAIK;AAgBA,SAAS,aACd,SACA,cAAuC,UACvC,OAAwD,CAAC,GACzD,mBAA4B,MAC5B,uBACA;AACA,QAAM,OAAO,UAAU;AACvB,QAAM,EAAE,aAAa,SAAS,IAAI,WAAW;AAC7C,QAAM,YAAY;AAAA,IAChB;AAAA,EACF;AACA,QAAM,CAAC,WAAW,YAAY,IAAI,SAAiB,EAAE;AAErD,QAAM,aAAa;AAAA,IACjB,MAAG;AAxCP;AAwCU,4BAAS,YAAT,mBAAkB,OAAO,CAAC,WAAW,OAAO,SAAS;AAAA;AAAA,IAC3D,CAAC,SAAS,OAAO;AAAA,EACnB;AAEA,YAAU,MAAM;AACd,QAAI,YAAY;AAEhB,mBAAe,cAAc;AA/CjC;AAgDM,UACE,CAAC,eACD,CAAC,QACD,GAAC,cAAS,YAAT,mBAAkB,WACnB,UAAU,SACV;AACA;AAAA,MACF;AAEA,YAAM,EAAE,YAAY,IAAI,MAAM,OAAO,uBAAuB;AAE5D,YAAM,EAAE,QAAQ,iBAAiB,WAAW,IAAI,IAC9C,MAAM;AAAA,QACJ;AAAA,QACA;AAAA,QACA;AAAA,UACE,GAAG;AAAA,UACH,UAAU;AAAA,UACV,MAAM,YAAY;AAAA,UAClB;AAAA,QACF;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAEF,UAAI,WAAW;AACb;AAAA,MACF;AAEA,gBAAU,UAAU;AACpB,mBAAa,GAAG;AAAA,IAClB;AAEA,gBAAY;AAEZ,WAAO,MAAM;AACX,kBAAY;AAAA,IACd;AAAA,EACF,GAAG;AAAA,IACD;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AAED,SAAO;AAAA,IACL,QAAQ,UAAU;AAAA,IAClB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@miden-sdk/use-miden-para-react",
|
|
3
|
+
"version": "0.10.10",
|
|
4
|
+
"description": "React hook that wires Para accounts into a Miden client",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Miden Labs",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/0xMiden/miden-para",
|
|
10
|
+
"directory": "packages/use-miden-para-react"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://miden.xyz/",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/0xMiden/miden-para/issues"
|
|
15
|
+
},
|
|
16
|
+
"main": "dist/index.cjs",
|
|
17
|
+
"module": "dist/index.mjs",
|
|
18
|
+
"types": "dist/index.d.ts",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"import": "./dist/index.mjs",
|
|
23
|
+
"require": "./dist/index.cjs"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"dist",
|
|
28
|
+
"src",
|
|
29
|
+
"README.md",
|
|
30
|
+
"package.json"
|
|
31
|
+
],
|
|
32
|
+
"sideEffects": false,
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "tsup",
|
|
35
|
+
"prepack": "npm run build",
|
|
36
|
+
"publish": "npm run build && npm publish --access public"
|
|
37
|
+
},
|
|
38
|
+
"peerDependencies": {
|
|
39
|
+
"@demox-labs/miden-sdk": "^0.12.5",
|
|
40
|
+
"@getpara/react-sdk-lite": "^2.2.0",
|
|
41
|
+
"@miden-sdk/miden-para": "^0.10.10",
|
|
42
|
+
"react": "^18.0.0 || ^19.0.0"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@demox-labs/miden-sdk": "^0.12.5",
|
|
46
|
+
"@types/react": "^19.2.5",
|
|
47
|
+
"tsup": "^8.3.0",
|
|
48
|
+
"typescript": "^5.9.3",
|
|
49
|
+
"@getpara/react-sdk-lite": "^2.3.0"
|
|
50
|
+
},
|
|
51
|
+
"engines": {
|
|
52
|
+
"node": ">=18"
|
|
53
|
+
},
|
|
54
|
+
"publishConfig": {
|
|
55
|
+
"access": "public"
|
|
56
|
+
},
|
|
57
|
+
"keywords": [
|
|
58
|
+
"miden",
|
|
59
|
+
"para",
|
|
60
|
+
"react",
|
|
61
|
+
"hook",
|
|
62
|
+
"wallet"
|
|
63
|
+
]
|
|
64
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useParaMiden } from './useParaMiden';
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useClient, useAccount, type Wallet } from '@getpara/react-sdk-lite';
|
|
4
|
+
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
5
|
+
import {
|
|
6
|
+
createParaMidenClient,
|
|
7
|
+
type Opts,
|
|
8
|
+
type MidenAccountStorageMode,
|
|
9
|
+
type CustomSignConfirmStep,
|
|
10
|
+
} from '@miden-sdk/miden-para';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* React hook that converts Para React SDK context into a ready-to-use Miden WebClient.
|
|
14
|
+
* Spawns the client once a Para session with at least one EVM wallet is active.
|
|
15
|
+
*
|
|
16
|
+
* Returns:
|
|
17
|
+
* - client: WebClient instance backed by the active Para session (or null while loading)
|
|
18
|
+
* - accountId: Miden account id derived for the selected EVM wallet
|
|
19
|
+
* - para: Para client instance from context
|
|
20
|
+
* - evmWallets: filtered list of Para wallets with type === 'EVM'
|
|
21
|
+
* - nodeUrl: Miden node endpoint used for the client
|
|
22
|
+
* - opts: forwarded options used when creating the client
|
|
23
|
+
* - showSigningModal: toggles the built-in signing modal
|
|
24
|
+
* - customSignConfirmStep: optional callback for custom transaction confirmation flows
|
|
25
|
+
*/
|
|
26
|
+
export function useParaMiden(
|
|
27
|
+
nodeUrl: string,
|
|
28
|
+
storageMode: MidenAccountStorageMode = 'public',
|
|
29
|
+
opts: Omit<Opts, 'endpoint' | 'type' | 'storageMode'> = {},
|
|
30
|
+
showSigningModal: boolean = true,
|
|
31
|
+
customSignConfirmStep?: CustomSignConfirmStep
|
|
32
|
+
) {
|
|
33
|
+
const para = useClient();
|
|
34
|
+
const { isConnected, embedded } = useAccount();
|
|
35
|
+
const clientRef = useRef<import('@demox-labs/miden-sdk').WebClient | null>(
|
|
36
|
+
null
|
|
37
|
+
);
|
|
38
|
+
const [accountId, setAccountId] = useState<string>('');
|
|
39
|
+
|
|
40
|
+
const evmWallets = useMemo(
|
|
41
|
+
() => embedded.wallets?.filter((wallet) => wallet.type === 'EVM'),
|
|
42
|
+
[embedded.wallets]
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
let cancelled = false;
|
|
47
|
+
|
|
48
|
+
async function setupClient() {
|
|
49
|
+
if (
|
|
50
|
+
!isConnected ||
|
|
51
|
+
!para ||
|
|
52
|
+
!embedded.wallets?.length ||
|
|
53
|
+
clientRef.current
|
|
54
|
+
) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const { AccountType } = await import('@demox-labs/miden-sdk');
|
|
59
|
+
|
|
60
|
+
const { client: midenParaClient, accountId: aId } =
|
|
61
|
+
await createParaMidenClient(
|
|
62
|
+
para,
|
|
63
|
+
evmWallets as Wallet[],
|
|
64
|
+
{
|
|
65
|
+
...opts,
|
|
66
|
+
endpoint: nodeUrl,
|
|
67
|
+
type: AccountType.RegularAccountImmutableCode,
|
|
68
|
+
storageMode,
|
|
69
|
+
},
|
|
70
|
+
showSigningModal,
|
|
71
|
+
customSignConfirmStep
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
if (cancelled) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
clientRef.current = midenParaClient;
|
|
79
|
+
setAccountId(aId);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
setupClient();
|
|
83
|
+
|
|
84
|
+
return () => {
|
|
85
|
+
cancelled = true;
|
|
86
|
+
};
|
|
87
|
+
}, [
|
|
88
|
+
isConnected,
|
|
89
|
+
evmWallets,
|
|
90
|
+
para,
|
|
91
|
+
nodeUrl,
|
|
92
|
+
showSigningModal,
|
|
93
|
+
customSignConfirmStep,
|
|
94
|
+
]);
|
|
95
|
+
|
|
96
|
+
return {
|
|
97
|
+
client: clientRef.current,
|
|
98
|
+
accountId,
|
|
99
|
+
para,
|
|
100
|
+
evmWallets,
|
|
101
|
+
nodeUrl,
|
|
102
|
+
opts,
|
|
103
|
+
};
|
|
104
|
+
}
|