@mycelium-ip/react 0.1.0-alpha.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/README.md +952 -0
- package/dist/hooks/derivative/useCreateDerivativeLink.d.ts +30 -0
- package/dist/hooks/derivative/useCreateDerivativeLink.d.ts.map +1 -0
- package/dist/hooks/derivative/useCreateDerivativeLink.js +45 -0
- package/dist/hooks/derivative/useUpdateDerivativeLicense.d.ts +30 -0
- package/dist/hooks/derivative/useUpdateDerivativeLicense.d.ts.map +1 -0
- package/dist/hooks/derivative/useUpdateDerivativeLicense.js +44 -0
- package/dist/hooks/entity/useCreateEntity.d.ts +28 -0
- package/dist/hooks/entity/useCreateEntity.d.ts.map +1 -0
- package/dist/hooks/entity/useCreateEntity.js +42 -0
- package/dist/hooks/entity/useUpdateEntityControllers.d.ts +28 -0
- package/dist/hooks/entity/useUpdateEntityControllers.d.ts.map +1 -0
- package/dist/hooks/entity/useUpdateEntityControllers.js +42 -0
- package/dist/hooks/grant/useCreateLicenseGrant.d.ts +29 -0
- package/dist/hooks/grant/useCreateLicenseGrant.d.ts.map +1 -0
- package/dist/hooks/grant/useCreateLicenseGrant.js +43 -0
- package/dist/hooks/grant/useRevokeLicenseGrant.d.ts +28 -0
- package/dist/hooks/grant/useRevokeLicenseGrant.d.ts.map +1 -0
- package/dist/hooks/grant/useRevokeLicenseGrant.js +42 -0
- package/dist/hooks/internal/useMyceliumClient.d.ts +15 -0
- package/dist/hooks/internal/useMyceliumClient.d.ts.map +1 -0
- package/dist/hooks/internal/useMyceliumClient.js +18 -0
- package/dist/hooks/internal/useMyceliumConnection.d.ts +14 -0
- package/dist/hooks/internal/useMyceliumConnection.d.ts.map +1 -0
- package/dist/hooks/internal/useMyceliumConnection.js +17 -0
- package/dist/hooks/internal/useMyceliumContext.d.ts +14 -0
- package/dist/hooks/internal/useMyceliumContext.d.ts.map +1 -0
- package/dist/hooks/internal/useMyceliumContext.js +22 -0
- package/dist/hooks/internal/useMyceliumWallet.d.ts +14 -0
- package/dist/hooks/internal/useMyceliumWallet.d.ts.map +1 -0
- package/dist/hooks/internal/useMyceliumWallet.js +17 -0
- package/dist/hooks/ip/useCreateIp.d.ts +29 -0
- package/dist/hooks/ip/useCreateIp.d.ts.map +1 -0
- package/dist/hooks/ip/useCreateIp.js +43 -0
- package/dist/hooks/ip/useTransferIp.d.ts +28 -0
- package/dist/hooks/ip/useTransferIp.d.ts.map +1 -0
- package/dist/hooks/ip/useTransferIp.js +42 -0
- package/dist/hooks/license/useCreateLicense.d.ts +28 -0
- package/dist/hooks/license/useCreateLicense.d.ts.map +1 -0
- package/dist/hooks/license/useCreateLicense.js +42 -0
- package/dist/hooks/license/useRevokeLicense.d.ts +27 -0
- package/dist/hooks/license/useRevokeLicense.d.ts.map +1 -0
- package/dist/hooks/license/useRevokeLicense.js +41 -0
- package/dist/hooks/license/useUpdateLicense.d.ts +28 -0
- package/dist/hooks/license/useUpdateLicense.d.ts.map +1 -0
- package/dist/hooks/license/useUpdateLicense.js +42 -0
- package/dist/hooks/metadata/useCreateEntityMetadata.d.ts +30 -0
- package/dist/hooks/metadata/useCreateEntityMetadata.d.ts.map +1 -0
- package/dist/hooks/metadata/useCreateEntityMetadata.js +45 -0
- package/dist/hooks/metadata/useCreateIpMetadata.d.ts +31 -0
- package/dist/hooks/metadata/useCreateIpMetadata.d.ts.map +1 -0
- package/dist/hooks/metadata/useCreateIpMetadata.js +46 -0
- package/dist/hooks/metadata/useCreateMetadataSchema.d.ts +29 -0
- package/dist/hooks/metadata/useCreateMetadataSchema.d.ts.map +1 -0
- package/dist/hooks/metadata/useCreateMetadataSchema.js +43 -0
- package/dist/hooks/queries/queryKeys.d.ts +45 -0
- package/dist/hooks/queries/queryKeys.d.ts.map +1 -0
- package/dist/hooks/queries/queryKeys.js +44 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +33 -0
- package/dist/provider/MyceliumIpProvider.d.ts +56 -0
- package/dist/provider/MyceliumIpProvider.d.ts.map +1 -0
- package/dist/provider/MyceliumIpProvider.js +76 -0
- package/dist/provider/context.d.ts +22 -0
- package/dist/provider/context.d.ts.map +1 -0
- package/dist/provider/context.js +6 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +1 -0
- package/dist/types/wallet.d.ts +54 -0
- package/dist/types/wallet.d.ts.map +1 -0
- package/dist/types/wallet.js +1 -0
- package/dist/utils/transaction.d.ts +40 -0
- package/dist/utils/transaction.d.ts.map +1 -0
- package/dist/utils/transaction.js +82 -0
- package/package.json +59 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Query key factory for TanStack Query.
|
|
3
|
+
*
|
|
4
|
+
* Provides a structured, type-safe way to define query keys
|
|
5
|
+
* for granular cache invalidation.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* // Invalidate all mycelium queries
|
|
10
|
+
* queryClient.invalidateQueries({ queryKey: queryKeys.all });
|
|
11
|
+
*
|
|
12
|
+
* // Invalidate specific entity
|
|
13
|
+
* queryClient.invalidateQueries({ queryKey: queryKeys.entity("123") });
|
|
14
|
+
*
|
|
15
|
+
* // Invalidate all IPs
|
|
16
|
+
* queryClient.invalidateQueries({ queryKey: queryKeys.ips() });
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export const queryKeys = {
|
|
20
|
+
/** Root key for all mycelium queries */
|
|
21
|
+
all: ["mycelium"],
|
|
22
|
+
/** Key for all entity queries */
|
|
23
|
+
entities: () => [...queryKeys.all, "entities"],
|
|
24
|
+
/** Key for a specific entity */
|
|
25
|
+
entity: (id) => [...queryKeys.entities(), id],
|
|
26
|
+
/** Key for all IP queries */
|
|
27
|
+
ips: () => [...queryKeys.all, "ips"],
|
|
28
|
+
/** Key for a specific IP */
|
|
29
|
+
ip: (id) => [...queryKeys.ips(), id],
|
|
30
|
+
/** Key for all license queries */
|
|
31
|
+
licenses: () => [...queryKeys.all, "licenses"],
|
|
32
|
+
/** Key for a specific license */
|
|
33
|
+
license: (id) => [...queryKeys.licenses(), id],
|
|
34
|
+
/** Key for all grant queries */
|
|
35
|
+
grants: () => [...queryKeys.all, "grants"],
|
|
36
|
+
/** Key for a specific grant */
|
|
37
|
+
grant: (id) => [...queryKeys.grants(), id],
|
|
38
|
+
/** Key for all metadata queries */
|
|
39
|
+
metadata: () => [...queryKeys.all, "metadata"],
|
|
40
|
+
/** Key for all derivative queries */
|
|
41
|
+
derivatives: () => [...queryKeys.all, "derivatives"],
|
|
42
|
+
/** Key for a specific derivative */
|
|
43
|
+
derivative: (id) => [...queryKeys.derivatives(), id],
|
|
44
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export { useCreateDerivativeLink } from "./hooks/derivative/useCreateDerivativeLink";
|
|
2
|
+
export { useUpdateDerivativeLicense } from "./hooks/derivative/useUpdateDerivativeLicense";
|
|
3
|
+
export { useCreateEntity } from "./hooks/entity/useCreateEntity";
|
|
4
|
+
export { useUpdateEntityControllers } from "./hooks/entity/useUpdateEntityControllers";
|
|
5
|
+
export { useCreateLicenseGrant } from "./hooks/grant/useCreateLicenseGrant";
|
|
6
|
+
export { useRevokeLicenseGrant } from "./hooks/grant/useRevokeLicenseGrant";
|
|
7
|
+
export { useMyceliumClient } from "./hooks/internal/useMyceliumClient";
|
|
8
|
+
export { useMyceliumConnection } from "./hooks/internal/useMyceliumConnection";
|
|
9
|
+
export { useMyceliumContext } from "./hooks/internal/useMyceliumContext";
|
|
10
|
+
export { useMyceliumWallet } from "./hooks/internal/useMyceliumWallet";
|
|
11
|
+
export { useCreateIp } from "./hooks/ip/useCreateIp";
|
|
12
|
+
export { useTransferIp } from "./hooks/ip/useTransferIp";
|
|
13
|
+
export { useCreateLicense } from "./hooks/license/useCreateLicense";
|
|
14
|
+
export { useRevokeLicense } from "./hooks/license/useRevokeLicense";
|
|
15
|
+
export { useUpdateLicense } from "./hooks/license/useUpdateLicense";
|
|
16
|
+
export { useCreateEntityMetadata } from "./hooks/metadata/useCreateEntityMetadata";
|
|
17
|
+
export { useCreateIpMetadata } from "./hooks/metadata/useCreateIpMetadata";
|
|
18
|
+
export { useCreateMetadataSchema } from "./hooks/metadata/useCreateMetadataSchema";
|
|
19
|
+
export { queryKeys } from "./hooks/queries/queryKeys";
|
|
20
|
+
export type { MyceliumContextValue } from "./provider/context";
|
|
21
|
+
export { MyceliumIpProvider, type MyceliumIpProviderOptions, type MyceliumIpProviderProps, } from "./provider/MyceliumIpProvider";
|
|
22
|
+
export type { MyceliumWallet } from "./types/wallet";
|
|
23
|
+
export { executeTransaction, executeTransactionWithInstructions, type TransactionResult, } from "./utils/transaction";
|
|
24
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,uBAAuB,EAAE,MAAM,4CAA4C,CAAC;AACrF,OAAO,EAAE,0BAA0B,EAAE,MAAM,+CAA+C,CAAC;AAE3F,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,EAAE,0BAA0B,EAAE,MAAM,2CAA2C,CAAC;AAEvF,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AAC5E,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AAE5E,OAAO,EAAE,iBAAiB,EAAE,MAAM,oCAAoC,CAAC;AACvE,OAAO,EAAE,qBAAqB,EAAE,MAAM,wCAAwC,CAAC;AAC/E,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AACzE,OAAO,EAAE,iBAAiB,EAAE,MAAM,oCAAoC,CAAC;AAGvE,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAEzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAE,uBAAuB,EAAE,MAAM,0CAA0C,CAAC;AACnF,OAAO,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;AAE3E,OAAO,EAAE,uBAAuB,EAAE,MAAM,0CAA0C,CAAC;AAEnF,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACtD,YAAY,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EACL,kBAAkB,EAClB,KAAK,yBAAyB,EAC9B,KAAK,uBAAuB,GAC7B,MAAM,+BAA+B,CAAC;AAEvC,YAAY,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAGrD,OAAO,EACL,kBAAkB,EAClB,kCAAkC,EAClC,KAAK,iBAAiB,GACvB,MAAM,qBAAqB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// This file defines the entire public SDK surface.
|
|
2
|
+
// Do not export internal modules directly.
|
|
3
|
+
// Provider
|
|
4
|
+
// Derivative mutation hooks
|
|
5
|
+
export { useCreateDerivativeLink } from "./hooks/derivative/useCreateDerivativeLink";
|
|
6
|
+
export { useUpdateDerivativeLicense } from "./hooks/derivative/useUpdateDerivativeLicense";
|
|
7
|
+
// Entity mutation hooks
|
|
8
|
+
export { useCreateEntity } from "./hooks/entity/useCreateEntity";
|
|
9
|
+
export { useUpdateEntityControllers } from "./hooks/entity/useUpdateEntityControllers";
|
|
10
|
+
// Grant mutation hooks
|
|
11
|
+
export { useCreateLicenseGrant } from "./hooks/grant/useCreateLicenseGrant";
|
|
12
|
+
export { useRevokeLicenseGrant } from "./hooks/grant/useRevokeLicenseGrant";
|
|
13
|
+
// Internal accessor hooks
|
|
14
|
+
export { useMyceliumClient } from "./hooks/internal/useMyceliumClient";
|
|
15
|
+
export { useMyceliumConnection } from "./hooks/internal/useMyceliumConnection";
|
|
16
|
+
export { useMyceliumContext } from "./hooks/internal/useMyceliumContext";
|
|
17
|
+
export { useMyceliumWallet } from "./hooks/internal/useMyceliumWallet";
|
|
18
|
+
// IP mutation hooks
|
|
19
|
+
export { useCreateIp } from "./hooks/ip/useCreateIp";
|
|
20
|
+
export { useTransferIp } from "./hooks/ip/useTransferIp";
|
|
21
|
+
// License mutation hooks
|
|
22
|
+
export { useCreateLicense } from "./hooks/license/useCreateLicense";
|
|
23
|
+
export { useRevokeLicense } from "./hooks/license/useRevokeLicense";
|
|
24
|
+
export { useUpdateLicense } from "./hooks/license/useUpdateLicense";
|
|
25
|
+
export { useCreateEntityMetadata } from "./hooks/metadata/useCreateEntityMetadata";
|
|
26
|
+
export { useCreateIpMetadata } from "./hooks/metadata/useCreateIpMetadata";
|
|
27
|
+
// Metadata mutation hooks
|
|
28
|
+
export { useCreateMetadataSchema } from "./hooks/metadata/useCreateMetadataSchema";
|
|
29
|
+
// Query keys
|
|
30
|
+
export { queryKeys } from "./hooks/queries/queryKeys";
|
|
31
|
+
export { MyceliumIpProvider, } from "./provider/MyceliumIpProvider";
|
|
32
|
+
// Utilities
|
|
33
|
+
export { executeTransaction, executeTransactionWithInstructions, } from "./utils/transaction";
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { Commitment, Connection } from "@solana/web3.js";
|
|
2
|
+
import { QueryClient } from "@tanstack/react-query";
|
|
3
|
+
import { type ReactNode } from "react";
|
|
4
|
+
import type { MyceliumWallet } from "../types/wallet";
|
|
5
|
+
/**
|
|
6
|
+
* Options for the MyceliumIpProvider.
|
|
7
|
+
*/
|
|
8
|
+
export interface MyceliumIpProviderOptions {
|
|
9
|
+
/**
|
|
10
|
+
* Transaction confirmation level.
|
|
11
|
+
* @default "confirmed"
|
|
12
|
+
*/
|
|
13
|
+
confirmation?: Commitment;
|
|
14
|
+
/**
|
|
15
|
+
* Enable TanStack Query devtools.
|
|
16
|
+
* @default true in development, false in production
|
|
17
|
+
*/
|
|
18
|
+
devtools?: boolean;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Props for the MyceliumIpProvider component.
|
|
22
|
+
*/
|
|
23
|
+
export interface MyceliumIpProviderProps {
|
|
24
|
+
/** Solana RPC connection (required) */
|
|
25
|
+
connection: Connection;
|
|
26
|
+
/** Wallet implementing the MyceliumWallet interface (required) */
|
|
27
|
+
wallet: MyceliumWallet;
|
|
28
|
+
/**
|
|
29
|
+
* Existing TanStack Query client.
|
|
30
|
+
* If omitted, the provider creates one.
|
|
31
|
+
*/
|
|
32
|
+
queryClient?: QueryClient;
|
|
33
|
+
/** Provider options */
|
|
34
|
+
options?: MyceliumIpProviderOptions;
|
|
35
|
+
/** Child components */
|
|
36
|
+
children: ReactNode;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Provider component for the Mycelium React SDK.
|
|
40
|
+
*
|
|
41
|
+
* Initializes the core SDK client and provides it via React context.
|
|
42
|
+
* Also wraps children with TanStack Query's QueryClientProvider.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```tsx
|
|
46
|
+
* <MyceliumIpProvider
|
|
47
|
+
* connection={connection}
|
|
48
|
+
* wallet={wallet}
|
|
49
|
+
* options={{ confirmation: "confirmed" }}
|
|
50
|
+
* >
|
|
51
|
+
* <App />
|
|
52
|
+
* </MyceliumIpProvider>
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export declare function MyceliumIpProvider({ connection, wallet, queryClient, options, children, }: MyceliumIpProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
56
|
+
//# sourceMappingURL=MyceliumIpProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MyceliumIpProvider.d.ts","sourceRoot":"","sources":["../../src/provider/MyceliumIpProvider.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAuB,MAAM,uBAAuB,CAAC;AAEzE,OAAO,EAAE,KAAK,SAAS,EAAW,MAAM,OAAO,CAAC;AAChD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAGtD;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC;;;OAGG;IACH,YAAY,CAAC,EAAE,UAAU,CAAC;IAE1B;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,uCAAuC;IACvC,UAAU,EAAE,UAAU,CAAC;IAEvB,kEAAkE;IAClE,MAAM,EAAE,cAAc,CAAC;IAEvB;;;OAGG;IACH,WAAW,CAAC,EAAE,WAAW,CAAC;IAE1B,uBAAuB;IACvB,OAAO,CAAC,EAAE,yBAAyB,CAAC;IAEpC,uBAAuB;IACvB,QAAQ,EAAE,SAAS,CAAC;CACrB;AAaD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,kBAAkB,CAAC,EACjC,UAAU,EACV,MAAM,EACN,WAAW,EACX,OAAO,EACP,QAAQ,GACT,EAAE,uBAAuB,2CA0DzB"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { MyceliumClient } from "@mycelium-ip/core-sdk";
|
|
4
|
+
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
5
|
+
import { ReactQueryDevtools } from "@tanstack/react-query-devtools";
|
|
6
|
+
import { useMemo } from "react";
|
|
7
|
+
import { MyceliumContext } from "./context";
|
|
8
|
+
// Default query client with sensible defaults
|
|
9
|
+
const createDefaultQueryClient = () => new QueryClient({
|
|
10
|
+
defaultOptions: {
|
|
11
|
+
queries: {
|
|
12
|
+
staleTime: 1000 * 60 * 5, // 5 minutes
|
|
13
|
+
retry: 1,
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
/**
|
|
18
|
+
* Provider component for the Mycelium React SDK.
|
|
19
|
+
*
|
|
20
|
+
* Initializes the core SDK client and provides it via React context.
|
|
21
|
+
* Also wraps children with TanStack Query's QueryClientProvider.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```tsx
|
|
25
|
+
* <MyceliumIpProvider
|
|
26
|
+
* connection={connection}
|
|
27
|
+
* wallet={wallet}
|
|
28
|
+
* options={{ confirmation: "confirmed" }}
|
|
29
|
+
* >
|
|
30
|
+
* <App />
|
|
31
|
+
* </MyceliumIpProvider>
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export function MyceliumIpProvider({ connection, wallet, queryClient, options, children, }) {
|
|
35
|
+
var _a, _b;
|
|
36
|
+
const confirmation = (_a = options === null || options === void 0 ? void 0 : options.confirmation) !== null && _a !== void 0 ? _a : "confirmed";
|
|
37
|
+
const showDevtools = (_b = options === null || options === void 0 ? void 0 : options.devtools) !== null && _b !== void 0 ? _b : false;
|
|
38
|
+
// Create a default query client if none provided
|
|
39
|
+
const resolvedQueryClient = useMemo(() => queryClient !== null && queryClient !== void 0 ? queryClient : createDefaultQueryClient(), [queryClient]);
|
|
40
|
+
// Create the core SDK client
|
|
41
|
+
const client = useMemo(() => {
|
|
42
|
+
var _a;
|
|
43
|
+
// Only create client if wallet has a public key
|
|
44
|
+
if (!wallet.publicKey) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
return new MyceliumClient({
|
|
48
|
+
connection,
|
|
49
|
+
wallet: {
|
|
50
|
+
publicKey: wallet.publicKey,
|
|
51
|
+
signTransaction: (tx) => wallet.signTransaction(tx),
|
|
52
|
+
signAllTransactions: (_a = wallet.signAllTransactions) !== null && _a !== void 0 ? _a : (async (txs) => {
|
|
53
|
+
const signed = [];
|
|
54
|
+
for (const tx of txs) {
|
|
55
|
+
signed.push(await wallet.signTransaction(tx));
|
|
56
|
+
}
|
|
57
|
+
return signed;
|
|
58
|
+
}),
|
|
59
|
+
signMessage: wallet.signMessage,
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
}, [connection, wallet]);
|
|
63
|
+
// Create context value
|
|
64
|
+
const contextValue = useMemo(() => {
|
|
65
|
+
if (!client) {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
connection,
|
|
70
|
+
wallet,
|
|
71
|
+
client,
|
|
72
|
+
confirmation,
|
|
73
|
+
};
|
|
74
|
+
}, [connection, wallet, client, confirmation]);
|
|
75
|
+
return (_jsxs(QueryClientProvider, { client: resolvedQueryClient, children: [_jsx(MyceliumContext.Provider, { value: contextValue, children: children }), showDevtools && _jsx(ReactQueryDevtools, { initialIsOpen: false })] }));
|
|
76
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { MyceliumClient } from "@mycelium-ip/core-sdk";
|
|
2
|
+
import type { Commitment, Connection } from "@solana/web3.js";
|
|
3
|
+
import type { MyceliumWallet } from "../types/wallet";
|
|
4
|
+
/**
|
|
5
|
+
* Context value provided by MyceliumIpProvider.
|
|
6
|
+
*/
|
|
7
|
+
export interface MyceliumContextValue {
|
|
8
|
+
/** Solana RPC connection */
|
|
9
|
+
connection: Connection;
|
|
10
|
+
/** Wallet implementing the MyceliumWallet interface */
|
|
11
|
+
wallet: MyceliumWallet;
|
|
12
|
+
/** Core SDK client instance */
|
|
13
|
+
client: MyceliumClient;
|
|
14
|
+
/** Transaction confirmation level */
|
|
15
|
+
confirmation: Commitment;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* React context for Mycelium SDK.
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
21
|
+
export declare const MyceliumContext: import("react").Context<MyceliumContextValue | null>;
|
|
22
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/provider/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE9D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEtD;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,4BAA4B;IAC5B,UAAU,EAAE,UAAU,CAAC;IACvB,uDAAuD;IACvD,MAAM,EAAE,cAAc,CAAC;IACvB,+BAA+B;IAC/B,MAAM,EAAE,cAAc,CAAC;IACvB,qCAAqC;IACrC,YAAY,EAAE,UAAU,CAAC;CAC1B;AAED;;;GAGG;AACH,eAAO,MAAM,eAAe,sDAAmD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { PublicKey, Transaction, VersionedTransaction } from "@solana/web3.js";
|
|
2
|
+
/**
|
|
3
|
+
* Wallet-agnostic interface for transaction signing.
|
|
4
|
+
*
|
|
5
|
+
* This interface allows consumers to adapt any wallet implementation
|
|
6
|
+
* (Solana Wallet Adapter, Privy, embedded wallets) without introducing
|
|
7
|
+
* direct dependencies on specific wallet libraries.
|
|
8
|
+
*
|
|
9
|
+
* @example Solana Wallet Adapter
|
|
10
|
+
* ```ts
|
|
11
|
+
* const wallet: MyceliumWallet = {
|
|
12
|
+
* publicKey: walletAdapter.publicKey,
|
|
13
|
+
* signTransaction: walletAdapter.signTransaction,
|
|
14
|
+
* signAllTransactions: walletAdapter.signAllTransactions,
|
|
15
|
+
* };
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @example Privy Wallet
|
|
19
|
+
* ```ts
|
|
20
|
+
* const wallet: MyceliumWallet = {
|
|
21
|
+
* publicKey: new PublicKey(privyWallet.address),
|
|
22
|
+
* signTransaction: privyWallet.signTransaction,
|
|
23
|
+
* signMessage: privyWallet.signMessage,
|
|
24
|
+
* };
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export interface MyceliumWallet {
|
|
28
|
+
/**
|
|
29
|
+
* The public key of the connected wallet.
|
|
30
|
+
* May be null if no wallet is connected.
|
|
31
|
+
*/
|
|
32
|
+
publicKey: PublicKey | null;
|
|
33
|
+
/**
|
|
34
|
+
* Signs a single transaction.
|
|
35
|
+
* @param transaction - The transaction to sign
|
|
36
|
+
* @returns The signed transaction
|
|
37
|
+
*/
|
|
38
|
+
signTransaction<T extends Transaction | VersionedTransaction>(transaction: T): Promise<T>;
|
|
39
|
+
/**
|
|
40
|
+
* Signs multiple transactions at once.
|
|
41
|
+
* Optional - not all wallets support batch signing.
|
|
42
|
+
* @param transactions - The transactions to sign
|
|
43
|
+
* @returns The signed transactions
|
|
44
|
+
*/
|
|
45
|
+
signAllTransactions?<T extends Transaction | VersionedTransaction>(transactions: T[]): Promise<T[]>;
|
|
46
|
+
/**
|
|
47
|
+
* Signs an arbitrary message.
|
|
48
|
+
* Optional - not all wallets support message signing.
|
|
49
|
+
* @param message - The message bytes to sign
|
|
50
|
+
* @returns The signature bytes
|
|
51
|
+
*/
|
|
52
|
+
signMessage?(message: Uint8Array): Promise<Uint8Array>;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=wallet.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../../src/types/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,SAAS,EACT,WAAW,EACX,oBAAoB,EACrB,MAAM,iBAAiB,CAAC;AAEzB;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,SAAS,EAAE,SAAS,GAAG,IAAI,CAAC;IAE5B;;;;OAIG;IACH,eAAe,CAAC,CAAC,SAAS,WAAW,GAAG,oBAAoB,EAC1D,WAAW,EAAE,CAAC,GACb,OAAO,CAAC,CAAC,CAAC,CAAC;IAEd;;;;;OAKG;IACH,mBAAmB,CAAC,CAAC,CAAC,SAAS,WAAW,GAAG,oBAAoB,EAC/D,YAAY,EAAE,CAAC,EAAE,GAChB,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC;IAEhB;;;;;OAKG;IACH,WAAW,CAAC,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;CACxD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { Commitment, Connection, TransactionInstruction } from "@solana/web3.js";
|
|
2
|
+
import type { MyceliumWallet } from "../types/wallet";
|
|
3
|
+
/**
|
|
4
|
+
* Result of executing a transaction.
|
|
5
|
+
*/
|
|
6
|
+
export interface TransactionResult {
|
|
7
|
+
/** Transaction signature */
|
|
8
|
+
signature: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Execute the full transaction lifecycle.
|
|
12
|
+
*
|
|
13
|
+
* 1. Build transaction from instruction
|
|
14
|
+
* 2. Set recent blockhash
|
|
15
|
+
* 3. Sign transaction using wallet
|
|
16
|
+
* 4. Send transaction to the network
|
|
17
|
+
* 5. Confirm transaction with specified commitment level
|
|
18
|
+
*
|
|
19
|
+
* @param connection - Solana RPC connection
|
|
20
|
+
* @param wallet - Wallet for signing
|
|
21
|
+
* @param instruction - Transaction instruction to execute
|
|
22
|
+
* @param confirmation - Commitment level for confirmation
|
|
23
|
+
* @returns Transaction signature
|
|
24
|
+
*
|
|
25
|
+
* @throws Error if wallet is not connected (no publicKey)
|
|
26
|
+
*/
|
|
27
|
+
export declare function executeTransaction(connection: Connection, wallet: MyceliumWallet, instruction: TransactionInstruction, confirmation: Commitment): Promise<TransactionResult>;
|
|
28
|
+
/**
|
|
29
|
+
* Execute multiple instructions in a single transaction.
|
|
30
|
+
*
|
|
31
|
+
* @param connection - Solana RPC connection
|
|
32
|
+
* @param wallet - Wallet for signing
|
|
33
|
+
* @param instructions - Transaction instructions to execute
|
|
34
|
+
* @param confirmation - Commitment level for confirmation
|
|
35
|
+
* @returns Transaction signature
|
|
36
|
+
*
|
|
37
|
+
* @throws Error if wallet is not connected (no publicKey)
|
|
38
|
+
*/
|
|
39
|
+
export declare function executeTransactionWithInstructions(connection: Connection, wallet: MyceliumWallet, instructions: TransactionInstruction[], confirmation: Commitment): Promise<TransactionResult>;
|
|
40
|
+
//# sourceMappingURL=transaction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction.d.ts","sourceRoot":"","sources":["../../src/utils/transaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EACV,UAAU,EACV,sBAAsB,EACvB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEtD;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,4BAA4B;IAC5B,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,kBAAkB,CACtC,UAAU,EAAE,UAAU,EACtB,MAAM,EAAE,cAAc,EACtB,WAAW,EAAE,sBAAsB,EACnC,YAAY,EAAE,UAAU,GACvB,OAAO,CAAC,iBAAiB,CAAC,CAkC5B;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,kCAAkC,CACtD,UAAU,EAAE,UAAU,EACtB,MAAM,EAAE,cAAc,EACtB,YAAY,EAAE,sBAAsB,EAAE,EACtC,YAAY,EAAE,UAAU,GACvB,OAAO,CAAC,iBAAiB,CAAC,CAqC5B"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { Transaction } from "@solana/web3.js";
|
|
2
|
+
/**
|
|
3
|
+
* Execute the full transaction lifecycle.
|
|
4
|
+
*
|
|
5
|
+
* 1. Build transaction from instruction
|
|
6
|
+
* 2. Set recent blockhash
|
|
7
|
+
* 3. Sign transaction using wallet
|
|
8
|
+
* 4. Send transaction to the network
|
|
9
|
+
* 5. Confirm transaction with specified commitment level
|
|
10
|
+
*
|
|
11
|
+
* @param connection - Solana RPC connection
|
|
12
|
+
* @param wallet - Wallet for signing
|
|
13
|
+
* @param instruction - Transaction instruction to execute
|
|
14
|
+
* @param confirmation - Commitment level for confirmation
|
|
15
|
+
* @returns Transaction signature
|
|
16
|
+
*
|
|
17
|
+
* @throws Error if wallet is not connected (no publicKey)
|
|
18
|
+
*/
|
|
19
|
+
export async function executeTransaction(connection, wallet, instruction, confirmation) {
|
|
20
|
+
if (!wallet.publicKey) {
|
|
21
|
+
throw new Error("Wallet not connected");
|
|
22
|
+
}
|
|
23
|
+
// Build the transaction
|
|
24
|
+
const transaction = new Transaction().add(instruction);
|
|
25
|
+
// Get latest blockhash
|
|
26
|
+
const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash(confirmation);
|
|
27
|
+
transaction.recentBlockhash = blockhash;
|
|
28
|
+
transaction.feePayer = wallet.publicKey;
|
|
29
|
+
// Sign the transaction
|
|
30
|
+
const signed = await wallet.signTransaction(transaction);
|
|
31
|
+
// Send the transaction
|
|
32
|
+
const signature = await connection.sendRawTransaction(signed.serialize(), {
|
|
33
|
+
skipPreflight: false,
|
|
34
|
+
preflightCommitment: confirmation,
|
|
35
|
+
});
|
|
36
|
+
// Confirm the transaction
|
|
37
|
+
await connection.confirmTransaction({
|
|
38
|
+
signature,
|
|
39
|
+
blockhash,
|
|
40
|
+
lastValidBlockHeight,
|
|
41
|
+
}, confirmation);
|
|
42
|
+
return { signature };
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Execute multiple instructions in a single transaction.
|
|
46
|
+
*
|
|
47
|
+
* @param connection - Solana RPC connection
|
|
48
|
+
* @param wallet - Wallet for signing
|
|
49
|
+
* @param instructions - Transaction instructions to execute
|
|
50
|
+
* @param confirmation - Commitment level for confirmation
|
|
51
|
+
* @returns Transaction signature
|
|
52
|
+
*
|
|
53
|
+
* @throws Error if wallet is not connected (no publicKey)
|
|
54
|
+
*/
|
|
55
|
+
export async function executeTransactionWithInstructions(connection, wallet, instructions, confirmation) {
|
|
56
|
+
if (!wallet.publicKey) {
|
|
57
|
+
throw new Error("Wallet not connected");
|
|
58
|
+
}
|
|
59
|
+
// Build the transaction with all instructions
|
|
60
|
+
const transaction = new Transaction();
|
|
61
|
+
for (const ix of instructions) {
|
|
62
|
+
transaction.add(ix);
|
|
63
|
+
}
|
|
64
|
+
// Get latest blockhash
|
|
65
|
+
const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash(confirmation);
|
|
66
|
+
transaction.recentBlockhash = blockhash;
|
|
67
|
+
transaction.feePayer = wallet.publicKey;
|
|
68
|
+
// Sign the transaction
|
|
69
|
+
const signed = await wallet.signTransaction(transaction);
|
|
70
|
+
// Send the transaction
|
|
71
|
+
const signature = await connection.sendRawTransaction(signed.serialize(), {
|
|
72
|
+
skipPreflight: false,
|
|
73
|
+
preflightCommitment: confirmation,
|
|
74
|
+
});
|
|
75
|
+
// Confirm the transaction
|
|
76
|
+
await connection.confirmTransaction({
|
|
77
|
+
signature,
|
|
78
|
+
blockhash,
|
|
79
|
+
lastValidBlockHeight,
|
|
80
|
+
}, confirmation);
|
|
81
|
+
return { signature };
|
|
82
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mycelium-ip/react",
|
|
3
|
+
"version": "0.1.0-alpha.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"description": "React hooks for the Mycelium IP protocol",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsc -p tsconfig.build.json",
|
|
9
|
+
"lint": "biome check .",
|
|
10
|
+
"test": "vitest",
|
|
11
|
+
"typecheck": "tsc -p tsconfig.build.json --noEmit"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist",
|
|
15
|
+
"README.md"
|
|
16
|
+
],
|
|
17
|
+
"publishConfig": {
|
|
18
|
+
"access": "public"
|
|
19
|
+
},
|
|
20
|
+
"keywords": [
|
|
21
|
+
"solana",
|
|
22
|
+
"ip",
|
|
23
|
+
"mycelium",
|
|
24
|
+
"react",
|
|
25
|
+
"hooks"
|
|
26
|
+
],
|
|
27
|
+
"author": "mycelium-dev",
|
|
28
|
+
"license": "MIT",
|
|
29
|
+
"packageManager": "pnpm@10.12.1",
|
|
30
|
+
"main": "./dist/index.js",
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"exports": {
|
|
33
|
+
".": {
|
|
34
|
+
"types": "./dist/index.d.ts",
|
|
35
|
+
"import": "./dist/index.js"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@mycelium-ip/core-sdk": "workspace:^"
|
|
40
|
+
},
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"@solana/web3.js": ">=1.87.0",
|
|
43
|
+
"@tanstack/react-query": ">=5.0.0",
|
|
44
|
+
"react": ">=18"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@solana/web3.js": "^1.98.0",
|
|
48
|
+
"@tanstack/react-query": "^5.76.2",
|
|
49
|
+
"@tanstack/react-query-devtools": "^5.76.2",
|
|
50
|
+
"@testing-library/jest-dom": "^6.6.3",
|
|
51
|
+
"@testing-library/react": "^16.3.0",
|
|
52
|
+
"@types/react": "^19.0.0",
|
|
53
|
+
"@types/react-dom": "^19.0.0",
|
|
54
|
+
"jsdom": "^26.1.0",
|
|
55
|
+
"react": "^19.0.0",
|
|
56
|
+
"react-dom": "^19.0.0",
|
|
57
|
+
"vitest": "^3.1.1"
|
|
58
|
+
}
|
|
59
|
+
}
|