@parity/product-sdk 0.5.0 → 0.7.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.
Files changed (39) hide show
  1. package/dist/address/index.d.ts +2 -2
  2. package/dist/{chunk-6W3TCR3W.js → chunk-4U2FP26I.js} +27 -25
  3. package/dist/chunk-4U2FP26I.js.map +1 -0
  4. package/dist/cloud-storage/index.d.ts +1 -0
  5. package/dist/cloud-storage/index.js +3 -0
  6. package/dist/core/index.d.ts +3 -3
  7. package/dist/core/index.js +1 -1
  8. package/dist/identity/index.d.ts +26 -22
  9. package/dist/identity/index.js +17 -17
  10. package/dist/identity/index.js.map +1 -1
  11. package/dist/index.d.ts +15 -15
  12. package/dist/index.js +3 -3
  13. package/dist/local-storage/index.d.ts +1 -0
  14. package/dist/local-storage/index.js +3 -0
  15. package/dist/react/index.d.ts +8 -8
  16. package/dist/react/index.js +8 -8
  17. package/dist/react/index.js.map +1 -1
  18. package/dist/{types-DVpAr2JN.d.ts → types-AjDV1BTd.d.ts} +17 -17
  19. package/package.json +16 -16
  20. package/src/cloud-storage/index.ts +6 -0
  21. package/src/core/createApp.ts +49 -43
  22. package/src/core/types.ts +16 -16
  23. package/src/identity/index.ts +6 -6
  24. package/src/identity/product-account.ts +39 -35
  25. package/src/identity/types.ts +6 -6
  26. package/src/index.ts +5 -5
  27. package/src/local-storage/index.ts +6 -0
  28. package/src/react/context.ts +1 -1
  29. package/src/react/index.ts +3 -3
  30. package/src/react/{useStorage.ts → useLocalStorage.ts} +8 -8
  31. package/dist/bulletin/index.d.ts +0 -1
  32. package/dist/bulletin/index.js +0 -3
  33. package/dist/chunk-6W3TCR3W.js.map +0 -1
  34. package/dist/storage/index.d.ts +0 -1
  35. package/dist/storage/index.js +0 -3
  36. package/src/bulletin/index.ts +0 -6
  37. package/src/storage/index.ts +0 -6
  38. /package/dist/{bulletin → cloud-storage}/index.js.map +0 -0
  39. /package/dist/{storage → local-storage}/index.js.map +0 -0
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/react/context.ts","../../src/react/provider.tsx","../../src/react/useWallet.ts","../../src/react/useStorage.ts","../../src/react/useChain.ts"],"names":["useState","useEffect","useCallback"],"mappings":";;;;AAQO,IAAM,iBAAA,GAAoB,cAA0B,IAAI;AAexD,SAAS,aAAA,GAAqB;AACjC,EAAA,MAAM,GAAA,GAAM,WAAW,iBAAiB,CAAA;AACxC,EAAA,IAAI,CAAC,GAAA,EAAK;AACN,IAAA,MAAM,IAAI,KAAA;AAAA,MACN;AAAA,KAEJ;AAAA,EACJ;AACA,EAAA,OAAO,GAAA;AACX;ACKO,SAAS,kBAAA,CAAmB;AAAA,EAC/B,IAAA;AAAA,EACA,QAAA,GAAW,MAAA;AAAA,EACX,QAAA;AAAA,EACA,QAAA,GAAW;AACf,CAAA,EAA4B;AACxB,EAAA,MAAM,CAAC,GAAA,EAAK,MAAM,CAAA,GAAI,SAAqB,IAAI,CAAA;AAC/C,EAAA,MAAM,CAAC,KAAA,EAAO,QAAQ,CAAA,GAAI,SAAuB,IAAI,CAAA;AAErD,EAAA,SAAA,CAAU,MAAM;AACZ,IAAA,IAAI,OAAA,GAAU,IAAA;AAEd,IAAA,SAAA,CAAU,EAAE,IAAA,EAAM,QAAA,EAAU,CAAA,CACvB,IAAA,CAAK,CAAC,UAAA,KAAe;AAClB,MAAA,IAAI,OAAA,EAAS;AACT,QAAA,MAAA,CAAO,UAAU,CAAA;AAAA,MACrB;AAAA,IACJ,CAAC,CAAA,CACA,KAAA,CAAM,CAAC,CAAA,KAAM;AACV,MAAA,IAAI,OAAA,EAAS;AACT,QAAA,QAAA,CAAS,CAAA,YAAa,QAAQ,CAAA,GAAI,IAAI,MAAM,MAAA,CAAO,CAAC,CAAC,CAAC,CAAA;AAAA,MAC1D;AAAA,IACJ,CAAC,CAAA;AAEL,IAAA,OAAO,MAAM;AACT,MAAA,OAAA,GAAU,KAAA;AAAA,IACd,CAAA;AAAA,EACJ,CAAA,EAAG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;AAEV,IAAA,OAAO,MAAM;AACT,MAAA,OAAA,GAAU,KAAA;AAAA,IACd,CAAA;AAAA,EACJ,CAAA,EAAG,CAAC,GAAA,EAAK,GAAA,EAAK,YAAY,CAAC,CAAA;AAE3B,EAAA,MAAM,cAAA,GAAiBC,WAAAA;AAAA,IACnB,OAAO,QAAA,KAAqB;AACxB,MAAA,MAAM,GAAA,CAAI,OAAA,CAAQ,GAAA,CAAI,GAAA,EAAK,QAAQ,CAAA;AACnC,MAAA,QAAA,CAAS,QAAQ,CAAA;AAAA,IACrB,CAAA;AAAA,IACA,CAAC,KAAK,GAAG;AAAA,GACb;AAEA,EAAA,OAAO,CAAC,KAAA,EAAO,cAAA,EAAgB,EAAE,SAAS,CAAA;AAC9C;AClGO,SAAS,SAAoC,KAAA,EAAuB;AACvE,EAAA,MAAM,MAAM,aAAA,EAAc;AAE1B,EAAA,OAAO,QAAQ,MAAM;AACjB,IAAA,OAAO,GAAA,CAAI,KAAA,CAAM,SAAA,CAAU,KAAK,CAAA;AAAA,EACpC,CAAA,EAAG,CAAC,GAAA,EAAK,KAAK,CAAC,CAAA;AACnB","file":"index.js","sourcesContent":["/**\n * React context for Product SDK\n */\n\nimport { createContext, useContext } from \"react\";\nimport type { App } from \"../core/types.js\";\n\n/** Context for the Product SDK app instance */\nexport const ProductSDKContext = createContext<App | null>(null);\n\n/**\n * Hook to access the Product SDK app instance\n *\n * @throws If used outside of ProductSDKProvider\n *\n * @example\n * ```tsx\n * function MyComponent() {\n * const app = useProductSDK();\n * // Use app.wallet, app.storage, etc.\n * }\n * ```\n */\nexport function useProductSDK(): App {\n const app = useContext(ProductSDKContext);\n if (!app) {\n throw new Error(\n \"useProductSDK must be used within a ProductSDKProvider. \" +\n 'Wrap your app with <ProductSDKProvider name=\"your-app\">.',\n );\n }\n return app;\n}\n","/**\n * ProductSDKProvider component\n */\n\nimport React, { useEffect, useState, type ReactNode } from \"react\";\nimport { ProductSDKContext } from \"./context.js\";\nimport { createApp } from \"../core/createApp.js\";\nimport type { App, LogLevel } from \"../core/types.js\";\n\n/** Props for ProductSDKProvider */\nexport interface ProductSDKProviderProps {\n /** Application name - used for storage namespacing and product account derivation */\n name: string;\n /** Log level (default: 'info') */\n logLevel?: LogLevel;\n /** Child components */\n children: ReactNode;\n /** Fallback to show while loading */\n fallback?: ReactNode;\n}\n\n/**\n * Provider component that initializes the Product SDK\n *\n * @example\n * ```tsx\n * import { ProductSDKProvider } from '@parity/product-sdk/react';\n *\n * function App() {\n * return (\n * <ProductSDKProvider name=\"my-app\" fallback={<Loading />}>\n * <MyApp />\n * </ProductSDKProvider>\n * );\n * }\n * ```\n */\nexport function ProductSDKProvider({\n name,\n logLevel = \"info\",\n children,\n fallback = null,\n}: ProductSDKProviderProps) {\n const [app, setApp] = useState<App | null>(null);\n const [error, setError] = useState<Error | null>(null);\n\n useEffect(() => {\n let mounted = true;\n\n createApp({ name, logLevel })\n .then((createdApp) => {\n if (mounted) {\n setApp(createdApp);\n }\n })\n .catch((e) => {\n if (mounted) {\n setError(e instanceof Error ? e : new Error(String(e)));\n }\n });\n\n return () => {\n mounted = false;\n };\n }, [name, logLevel]);\n\n if (error) {\n throw error;\n }\n\n if (!app) {\n return <>{fallback}</>;\n }\n\n return <ProductSDKContext.Provider value={app}>{children}</ProductSDKContext.Provider>;\n}\n","/**\n * useWallet hook\n */\n\nimport { useState, useEffect, useCallback } from \"react\";\nimport { useProductSDK } from \"./context.js\";\nimport type { Account } from \"../core/types.js\";\n\n/** Wallet hook state */\nexport interface UseWalletState {\n /** Whether wallet is connected */\n isConnected: boolean;\n /** Whether connection is in progress */\n isConnecting: boolean;\n /** Available accounts */\n accounts: Account[];\n /** Currently selected account */\n selectedAccount: Account | null;\n /** Last error */\n error: Error | null;\n}\n\n/** Wallet hook actions */\nexport interface UseWalletActions {\n /** Connect to wallet */\n connect: () => Promise<void>;\n /** Disconnect from wallet */\n disconnect: () => Promise<void>;\n /** Select an account */\n selectAccount: (address: string) => void;\n /** Sign a message */\n signMessage: (message: string | Uint8Array) => Promise<Uint8Array>;\n}\n\n/** Return type of useWallet */\nexport type UseWalletReturn = UseWalletState & UseWalletActions;\n\n/**\n * Hook for wallet connection and signing\n *\n * @example\n * ```tsx\n * function WalletButton() {\n * const { isConnected, accounts, connect, disconnect, selectAccount } = useWallet();\n *\n * if (!isConnected) {\n * return <button onClick={connect}>Connect Wallet</button>;\n * }\n *\n * return (\n * <div>\n * <select onChange={(e) => selectAccount(e.target.value)}>\n * {accounts.map((a) => (\n * <option key={a.address} value={a.address}>\n * {a.name || a.address}\n * </option>\n * ))}\n * </select>\n * <button onClick={disconnect}>Disconnect</button>\n * </div>\n * );\n * }\n * ```\n */\nexport function useWallet(): UseWalletReturn {\n const app = useProductSDK();\n\n const [state, setState] = useState<UseWalletState>({\n isConnected: false,\n isConnecting: false,\n accounts: [],\n selectedAccount: null,\n error: null,\n });\n\n const connect = useCallback(async () => {\n setState((s) => ({ ...s, isConnecting: true, error: null }));\n try {\n const result = await app.wallet.connect();\n setState((s) => ({\n ...s,\n isConnected: true,\n isConnecting: false,\n accounts: result.accounts,\n selectedAccount: result.accounts[0] || null,\n }));\n } catch (e) {\n setState((s) => ({\n ...s,\n isConnecting: false,\n error: e instanceof Error ? e : new Error(String(e)),\n }));\n }\n }, [app]);\n\n const disconnect = useCallback(async () => {\n await app.wallet.disconnect();\n setState({\n isConnected: false,\n isConnecting: false,\n accounts: [],\n selectedAccount: null,\n error: null,\n });\n }, [app]);\n\n const selectAccount = useCallback(\n (address: string) => {\n app.wallet.selectAccount(address);\n const account = state.accounts.find((a) => a.address === address) || null;\n setState((s) => ({ ...s, selectedAccount: account }));\n },\n [app, state.accounts],\n );\n\n const signMessage = useCallback(\n async (message: string | Uint8Array) => {\n return app.wallet.signMessage(message);\n },\n [app],\n );\n\n // Subscribe to account changes\n useEffect(() => {\n const unsubscribe = app.wallet.onAccountChange((account) => {\n setState((s) => ({ ...s, selectedAccount: account }));\n });\n return unsubscribe;\n }, [app]);\n\n return {\n ...state,\n connect,\n disconnect,\n selectAccount,\n signMessage,\n };\n}\n","/**\n * useStorage hook\n */\n\nimport { useState, useEffect, useCallback } from \"react\";\nimport { useProductSDK } from \"./context.js\";\n\n/**\n * Hook for key-value storage operations\n *\n * @param key - Storage key\n * @param defaultValue - Default value if key doesn't exist\n *\n * @example\n * ```tsx\n * function ThemeToggle() {\n * const [theme, setTheme, { loading }] = useStorage('theme', 'light');\n *\n * if (loading) return <div>Loading...</div>;\n *\n * return (\n * <button onClick={() => setTheme(theme === 'light' ? 'dark' : 'light')}>\n * Current: {theme}\n * </button>\n * );\n * }\n * ```\n */\nexport function useStorage<T = string>(\n key: string,\n defaultValue?: T,\n): [T | null, (value: T) => Promise<void>, { loading: boolean; error: Error | null }] {\n const app = useProductSDK();\n\n const [value, setValue] = useState<T | null>(null);\n const [loading, setLoading] = useState(true);\n const [error, setError] = useState<Error | null>(null);\n\n // Load initial value\n useEffect(() => {\n let mounted = true;\n\n const loadValue = async () => {\n try {\n setLoading(true);\n const stored = await app.storage.getJSON<T>(key);\n if (mounted) {\n setValue(stored ?? defaultValue ?? null);\n setLoading(false);\n }\n } catch (e) {\n if (mounted) {\n setError(e instanceof Error ? e : new Error(String(e)));\n setLoading(false);\n }\n }\n };\n\n loadValue();\n\n return () => {\n mounted = false;\n };\n }, [app, key, defaultValue]);\n\n const setStoredValue = useCallback(\n async (newValue: T) => {\n try {\n setError(null);\n await app.storage.setJSON(key, newValue);\n setValue(newValue);\n } catch (e) {\n setError(e instanceof Error ? e : new Error(String(e)));\n throw e;\n }\n },\n [app, key],\n );\n\n return [value, setStoredValue, { loading, error }];\n}\n\n/**\n * Hook for string storage (simpler API)\n *\n * @param key - Storage key\n * @param defaultValue - Default value\n */\nexport function useStorageString(\n key: string,\n defaultValue?: string,\n): [string | null, (value: string) => Promise<void>, { loading: boolean }] {\n const app = useProductSDK();\n\n const [value, setValue] = useState<string | null>(null);\n const [loading, setLoading] = useState(true);\n\n useEffect(() => {\n let mounted = true;\n\n const loadValue = async () => {\n const stored = await app.storage.get(key);\n if (mounted) {\n setValue(stored ?? defaultValue ?? null);\n setLoading(false);\n }\n };\n\n loadValue();\n\n return () => {\n mounted = false;\n };\n }, [app, key, defaultValue]);\n\n const setStoredValue = useCallback(\n async (newValue: string) => {\n await app.storage.set(key, newValue);\n setValue(newValue);\n },\n [app, key],\n );\n\n return [value, setStoredValue, { loading }];\n}\n","/**\n * useChain hook\n */\n\nimport { useMemo } from \"react\";\nimport { useProductSDK } from \"./context.js\";\nimport type { ChainDefinition, TypedApi } from \"../core/types.js\";\n\n/**\n * Hook to get a typed chain client\n *\n * @param chain - Chain descriptor (PAPI ChainDefinition)\n *\n * @example\n * ```tsx\n * import { paseo_asset_hub } from '@parity/product-sdk-descriptors/paseo-asset-hub';\n * import { useChain } from '@parity/product-sdk/react';\n *\n * function AssetHubBalance() {\n * const assetHub = useChain(paseo_asset_hub);\n *\n * // assetHub is typed for Asset Hub queries\n * const balance = await assetHub.query.System.Account.getValue(address);\n * }\n * ```\n */\nexport function useChain<T extends ChainDefinition>(chain: T): TypedApi<T> {\n const app = useProductSDK();\n\n return useMemo(() => {\n return app.chain.getClient(chain);\n }, [app, chain]);\n}\n"]}
1
+ {"version":3,"sources":["../../src/react/context.ts","../../src/react/provider.tsx","../../src/react/useWallet.ts","../../src/react/useLocalStorage.ts","../../src/react/useChain.ts"],"names":["useState","useEffect","useCallback"],"mappings":";;;;AAQO,IAAM,iBAAA,GAAoB,cAA0B,IAAI;AAexD,SAAS,aAAA,GAAqB;AACjC,EAAA,MAAM,GAAA,GAAM,WAAW,iBAAiB,CAAA;AACxC,EAAA,IAAI,CAAC,GAAA,EAAK;AACN,IAAA,MAAM,IAAI,KAAA;AAAA,MACN;AAAA,KAEJ;AAAA,EACJ;AACA,EAAA,OAAO,GAAA;AACX;ACKO,SAAS,kBAAA,CAAmB;AAAA,EAC/B,IAAA;AAAA,EACA,QAAA,GAAW,MAAA;AAAA,EACX,QAAA;AAAA,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AAuB;AACvE,EAAA,MAAM,MAAM,aAAA,EAAc;AAE1B,EAAA,OAAO,QAAQ,MAAM;AACjB,IAAA,OAAO,GAAA,CAAI,KAAA,CAAM,SAAA,CAAU,KAAK,CAAA;AAAA,EACpC,CAAA,EAAG,CAAC,GAAA,EAAK,KAAK,CAAC,CAAA;AACnB","file":"index.js","sourcesContent":["/**\n * React context for Product SDK\n */\n\nimport { createContext, useContext } from \"react\";\nimport type { App } from \"../core/types.js\";\n\n/** Context for the Product SDK app instance */\nexport const ProductSDKContext = createContext<App | null>(null);\n\n/**\n * Hook to access the Product SDK app instance\n *\n * @throws If used outside of ProductSDKProvider\n *\n * @example\n * ```tsx\n * function MyComponent() {\n * const app = useProductSDK();\n * // Use app.wallet, app.localStorage, etc.\n * }\n * ```\n */\nexport function useProductSDK(): App {\n const app = useContext(ProductSDKContext);\n if (!app) {\n throw new Error(\n \"useProductSDK must be used within a ProductSDKProvider. \" +\n 'Wrap your app with <ProductSDKProvider name=\"your-app\">.',\n );\n }\n return app;\n}\n","/**\n * ProductSDKProvider component\n */\n\nimport React, { useEffect, useState, type ReactNode } from \"react\";\nimport { ProductSDKContext } from \"./context.js\";\nimport { createApp } from \"../core/createApp.js\";\nimport type { App, LogLevel } from \"../core/types.js\";\n\n/** Props for ProductSDKProvider */\nexport interface ProductSDKProviderProps {\n /** Application name - used for storage namespacing and product account derivation */\n name: string;\n /** Log level (default: 'info') */\n logLevel?: LogLevel;\n /** Child components */\n children: ReactNode;\n /** Fallback to show while loading */\n fallback?: ReactNode;\n}\n\n/**\n * Provider component that initializes the Product SDK\n *\n * @example\n * ```tsx\n * import { ProductSDKProvider } from '@parity/product-sdk/react';\n *\n * function App() {\n * return (\n * <ProductSDKProvider name=\"my-app\" fallback={<Loading />}>\n * <MyApp />\n * </ProductSDKProvider>\n * );\n * }\n * ```\n */\nexport function ProductSDKProvider({\n name,\n logLevel = \"info\",\n children,\n fallback = null,\n}: ProductSDKProviderProps) {\n const [app, setApp] = useState<App | null>(null);\n const [error, setError] = useState<Error | null>(null);\n\n useEffect(() => {\n let mounted = true;\n\n createApp({ name, logLevel })\n .then((createdApp) => {\n if (mounted) {\n setApp(createdApp);\n }\n })\n .catch((e) => {\n if (mounted) {\n setError(e instanceof Error ? e : new Error(String(e)));\n }\n });\n\n return () => {\n mounted = false;\n };\n }, [name, logLevel]);\n\n if (error) {\n throw error;\n }\n\n if (!app) {\n return <>{fallback}</>;\n }\n\n return <ProductSDKContext.Provider value={app}>{children}</ProductSDKContext.Provider>;\n}\n","/**\n * useWallet hook\n */\n\nimport { useState, useEffect, useCallback } from \"react\";\nimport { useProductSDK } from \"./context.js\";\nimport type { Account } from \"../core/types.js\";\n\n/** Wallet hook state */\nexport interface UseWalletState {\n /** Whether wallet is connected */\n isConnected: boolean;\n /** Whether connection is in progress */\n isConnecting: boolean;\n /** Available accounts */\n accounts: Account[];\n /** Currently selected account */\n selectedAccount: Account | null;\n /** Last error */\n error: Error | null;\n}\n\n/** Wallet hook actions */\nexport interface UseWalletActions {\n /** Connect to wallet */\n connect: () => Promise<void>;\n /** Disconnect from wallet */\n disconnect: () => Promise<void>;\n /** Select an account */\n selectAccount: (address: string) => void;\n /** Sign a message */\n signMessage: (message: string | Uint8Array) => Promise<Uint8Array>;\n}\n\n/** Return type of useWallet */\nexport type UseWalletReturn = UseWalletState & UseWalletActions;\n\n/**\n * Hook for wallet connection and signing\n *\n * @example\n * ```tsx\n * function WalletButton() {\n * const { isConnected, accounts, connect, disconnect, selectAccount } = useWallet();\n *\n * if (!isConnected) {\n * return <button onClick={connect}>Connect Wallet</button>;\n * }\n *\n * return (\n * <div>\n * <select onChange={(e) => selectAccount(e.target.value)}>\n * {accounts.map((a) => (\n * <option key={a.address} value={a.address}>\n * {a.name || a.address}\n * </option>\n * ))}\n * </select>\n * <button onClick={disconnect}>Disconnect</button>\n * </div>\n * );\n * }\n * ```\n */\nexport function useWallet(): UseWalletReturn {\n const app = useProductSDK();\n\n const [state, setState] = useState<UseWalletState>({\n isConnected: false,\n isConnecting: false,\n accounts: [],\n selectedAccount: null,\n error: null,\n });\n\n const connect = useCallback(async () => {\n setState((s) => ({ ...s, isConnecting: true, error: null }));\n try {\n const result = await app.wallet.connect();\n setState((s) => ({\n ...s,\n isConnected: true,\n isConnecting: false,\n accounts: result.accounts,\n selectedAccount: result.accounts[0] || null,\n }));\n } catch (e) {\n setState((s) => ({\n ...s,\n isConnecting: false,\n error: e instanceof Error ? e : new Error(String(e)),\n }));\n }\n }, [app]);\n\n const disconnect = useCallback(async () => {\n await app.wallet.disconnect();\n setState({\n isConnected: false,\n isConnecting: false,\n accounts: [],\n selectedAccount: null,\n error: null,\n });\n }, [app]);\n\n const selectAccount = useCallback(\n (address: string) => {\n app.wallet.selectAccount(address);\n const account = state.accounts.find((a) => a.address === address) || null;\n setState((s) => ({ ...s, selectedAccount: account }));\n },\n [app, state.accounts],\n );\n\n const signMessage = useCallback(\n async (message: string | Uint8Array) => {\n return app.wallet.signMessage(message);\n },\n [app],\n );\n\n // Subscribe to account changes\n useEffect(() => {\n const unsubscribe = app.wallet.onAccountChange((account) => {\n setState((s) => ({ ...s, selectedAccount: account }));\n });\n return unsubscribe;\n }, [app]);\n\n return {\n ...state,\n connect,\n disconnect,\n selectAccount,\n signMessage,\n };\n}\n","/**\n * useLocalStorage hook\n */\n\nimport { useState, useEffect, useCallback } from \"react\";\nimport { useProductSDK } from \"./context.js\";\n\n/**\n * Hook for key-value storage operations\n *\n * @param key - Storage key\n * @param defaultValue - Default value if key doesn't exist\n *\n * @example\n * ```tsx\n * function ThemeToggle() {\n * const [theme, setTheme, { loading }] = useLocalStorage('theme', 'light');\n *\n * if (loading) return <div>Loading...</div>;\n *\n * return (\n * <button onClick={() => setTheme(theme === 'light' ? 'dark' : 'light')}>\n * Current: {theme}\n * </button>\n * );\n * }\n * ```\n */\nexport function useLocalStorage<T = string>(\n key: string,\n defaultValue?: T,\n): [T | null, (value: T) => Promise<void>, { loading: boolean; error: Error | null }] {\n const app = useProductSDK();\n\n const [value, setValue] = useState<T | null>(null);\n const [loading, setLoading] = useState(true);\n const [error, setError] = useState<Error | null>(null);\n\n // Load initial value\n useEffect(() => {\n let mounted = true;\n\n const loadValue = async () => {\n try {\n setLoading(true);\n const stored = await app.localStorage.getJSON<T>(key);\n if (mounted) {\n setValue(stored ?? defaultValue ?? null);\n setLoading(false);\n }\n } catch (e) {\n if (mounted) {\n setError(e instanceof Error ? e : new Error(String(e)));\n setLoading(false);\n }\n }\n };\n\n loadValue();\n\n return () => {\n mounted = false;\n };\n }, [app, key, defaultValue]);\n\n const setStoredValue = useCallback(\n async (newValue: T) => {\n try {\n setError(null);\n await app.localStorage.setJSON(key, newValue);\n setValue(newValue);\n } catch (e) {\n setError(e instanceof Error ? e : new Error(String(e)));\n throw e;\n }\n },\n [app, key],\n );\n\n return [value, setStoredValue, { loading, error }];\n}\n\n/**\n * Hook for string storage (simpler API)\n *\n * @param key - Storage key\n * @param defaultValue - Default value\n */\nexport function useLocalStorageString(\n key: string,\n defaultValue?: string,\n): [string | null, (value: string) => Promise<void>, { loading: boolean }] {\n const app = useProductSDK();\n\n const [value, setValue] = useState<string | null>(null);\n const [loading, setLoading] = useState(true);\n\n useEffect(() => {\n let mounted = true;\n\n const loadValue = async () => {\n const stored = await app.localStorage.get(key);\n if (mounted) {\n setValue(stored ?? defaultValue ?? null);\n setLoading(false);\n }\n };\n\n loadValue();\n\n return () => {\n mounted = false;\n };\n }, [app, key, defaultValue]);\n\n const setStoredValue = useCallback(\n async (newValue: string) => {\n await app.localStorage.set(key, newValue);\n setValue(newValue);\n },\n [app, key],\n );\n\n return [value, setStoredValue, { loading }];\n}\n","/**\n * useChain hook\n */\n\nimport { useMemo } from \"react\";\nimport { useProductSDK } from \"./context.js\";\nimport type { ChainDefinition, TypedApi } from \"../core/types.js\";\n\n/**\n * Hook to get a typed chain client\n *\n * @param chain - Chain descriptor (PAPI ChainDefinition)\n *\n * @example\n * ```tsx\n * import { paseo_asset_hub } from '@parity/product-sdk-descriptors/paseo-asset-hub';\n * import { useChain } from '@parity/product-sdk/react';\n *\n * function AssetHubBalance() {\n * const assetHub = useChain(paseo_asset_hub);\n *\n * // assetHub is typed for Asset Hub queries\n * const balance = await assetHub.query.System.Account.getValue(address);\n * }\n * ```\n */\nexport function useChain<T extends ChainDefinition>(chain: T): TypedApi<T> {\n const app = useProductSDK();\n\n return useMemo(() => {\n return app.chain.getClient(chain);\n }, [app, chain]);\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  import { LogLevel } from '@parity/product-sdk-logger';
2
- import { BulletinEnvironment } from '@parity/product-sdk-bulletin';
2
+ import { CloudStorageEnvironment } from '@parity/product-sdk-cloud-storage';
3
3
  import { ChainClient } from '@parity/product-sdk-chain-client';
4
4
  import { ChainDefinition, TypedApi, PolkadotClient } from 'polkadot-api';
5
5
 
@@ -7,10 +7,10 @@ import { ChainDefinition, TypedApi, PolkadotClient } from 'polkadot-api';
7
7
  * Core types for @parity/product-sdk
8
8
  */
9
9
 
10
- /** Bulletin configuration options */
11
- interface BulletinConfig {
12
- /** Bulletin environment to connect to */
13
- environment: BulletinEnvironment;
10
+ /** Cloud Storage configuration options */
11
+ interface CloudStorageConfig {
12
+ /** Cloud Storage environment to connect to */
13
+ environment: CloudStorageEnvironment;
14
14
  }
15
15
  /** Configuration for createApp */
16
16
  interface AppConfig {
@@ -19,11 +19,11 @@ interface AppConfig {
19
19
  /** Log level for SDK operations (default: 'info') */
20
20
  logLevel?: LogLevel;
21
21
  /**
22
- * Bulletin Chain configuration.
22
+ * Cloud Storage configuration.
23
23
  * - Omit or pass config object to enable (default: { environment: "paseo" })
24
- * - Pass `false` to disable bulletin initialization
24
+ * - Pass `false` to disable cloud storage initialization
25
25
  */
26
- bulletin?: BulletinConfig | false;
26
+ cloudStorage?: CloudStorageConfig | false;
27
27
  }
28
28
  /** Wallet API exposed by the SDK */
29
29
  interface WalletApi {
@@ -51,7 +51,7 @@ interface WalletApi {
51
51
  createProof(message: Uint8Array): Promise<Uint8Array>;
52
52
  }
53
53
  /** Storage API exposed by the SDK */
54
- interface StorageApi {
54
+ interface LocalStorageApi {
55
55
  /** Get a value by key */
56
56
  get(key: string): Promise<string | null>;
57
57
  /** Set a value by key */
@@ -107,10 +107,10 @@ interface ChainApi {
107
107
  */
108
108
  destroyAll(): void;
109
109
  }
110
- /** Bulletin Chain API exposed by the SDK */
111
- interface BulletinApi {
110
+ /** Cloud Storage API exposed by the SDK */
111
+ interface CloudStorageApi {
112
112
  /**
113
- * Upload data to Bulletin Chain.
113
+ * Upload data to the Cloud.
114
114
  *
115
115
  * Requires a wallet to be connected and an account selected. Throws
116
116
  * "No signer available …" otherwise.
@@ -129,12 +129,12 @@ interface BulletinApi {
129
129
  interface App {
130
130
  /** Wallet/signing operations */
131
131
  wallet: WalletApi;
132
- /** Key-value storage operations */
133
- storage: StorageApi;
132
+ /** Local Key-value storage operations */
133
+ localStorage: LocalStorageApi;
134
134
  /** Chain interaction operations */
135
135
  chain: ChainApi;
136
- /** Bulletin Chain operations (null if disabled via config) */
137
- bulletin: BulletinApi | null;
136
+ /** Cloud Storage operations (null if disabled via config) */
137
+ cloudStorage: CloudStorageApi | null;
138
138
  /** Get app configuration */
139
139
  getAppInfo(): AppConfig;
140
140
  }
@@ -148,4 +148,4 @@ interface Account {
148
148
  source: string;
149
149
  }
150
150
 
151
- export type { App as A, BulletinApi as B, ChainApi as C, StorageApi as S, WalletApi as W, Account as a, AppConfig as b, BulletinConfig as c };
151
+ export type { App as A, ChainApi as C, LocalStorageApi as L, WalletApi as W, Account as a, AppConfig as b, CloudStorageApi as c, CloudStorageConfig as d };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parity/product-sdk",
3
- "version": "0.5.0",
3
+ "version": "0.7.0",
4
4
  "description": "Unified SDK for building products in the Polkadot ecosystem - umbrella package",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -16,9 +16,9 @@
16
16
  "import": "./dist/address/index.js",
17
17
  "types": "./dist/address/index.d.ts"
18
18
  },
19
- "./bulletin": {
20
- "import": "./dist/bulletin/index.js",
21
- "types": "./dist/bulletin/index.d.ts"
19
+ "./cloud-storage": {
20
+ "import": "./dist/cloud-storage/index.js",
21
+ "types": "./dist/cloud-storage/index.d.ts"
22
22
  },
23
23
  "./chain": {
24
24
  "import": "./dist/chain/index.js",
@@ -48,9 +48,9 @@
48
48
  "import": "./dist/react/index.js",
49
49
  "types": "./dist/react/index.d.ts"
50
50
  },
51
- "./storage": {
52
- "import": "./dist/storage/index.js",
53
- "types": "./dist/storage/index.d.ts"
51
+ "./local-storage": {
52
+ "import": "./dist/local-storage/index.js",
53
+ "types": "./dist/local-storage/index.d.ts"
54
54
  },
55
55
  "./wallet": {
56
56
  "import": "./dist/wallet/index.js",
@@ -64,16 +64,16 @@
64
64
  "dependencies": {
65
65
  "polkadot-api": "^2.1.2",
66
66
  "@parity/product-sdk-address": "0.1.1",
67
- "@parity/product-sdk-bulletin": "0.4.1",
68
- "@parity/product-sdk-chain-client": "0.4.1",
69
- "@parity/product-sdk-contracts": "0.5.0",
67
+ "@parity/product-sdk-cloud-storage": "0.5.0",
68
+ "@parity/product-sdk-chain-client": "0.5.0",
69
+ "@parity/product-sdk-contracts": "0.6.0",
70
70
  "@parity/product-sdk-crypto": "0.1.1",
71
- "@parity/product-sdk-host": "0.3.0",
71
+ "@parity/product-sdk-host": "0.5.0",
72
+ "@parity/product-sdk-keys": "0.3.1",
72
73
  "@parity/product-sdk-logger": "0.1.1",
73
- "@parity/product-sdk-signer": "0.2.4",
74
- "@parity/product-sdk-keys": "0.2.3",
75
- "@parity/product-sdk-storage": "0.1.4",
76
- "@parity/product-sdk-tx": "0.2.3"
74
+ "@parity/product-sdk-signer": "0.4.0",
75
+ "@parity/product-sdk-tx": "0.2.5",
76
+ "@parity/product-sdk-local-storage": "0.2.0"
77
77
  },
78
78
  "peerDependencies": {
79
79
  "react": "^18.0.0 || ^19.0.0"
@@ -99,7 +99,7 @@
99
99
  ],
100
100
  "license": "Apache-2.0",
101
101
  "scripts": {
102
- "build": "tsup",
102
+ "build": "NODE_OPTIONS=--max-old-space-size=8192 tsup",
103
103
  "clean": "rm -rf dist"
104
104
  }
105
105
  }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @parity/product-sdk/bulletin
3
+ *
4
+ * Re-exports from @parity/product-sdk-cloud-storage.
5
+ */
6
+ export * from "@parity/product-sdk-cloud-storage";
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * createApp - Main entry point for the Product SDK
3
3
  *
4
- * Creates an App instance with wallet, storage, chain, and bulletin APIs.
4
+ * Creates an App instance with wallet, storage, chain, and cloud storage APIs.
5
5
  */
6
6
 
7
7
  import type { ChainDefinition } from "polkadot-api";
@@ -9,15 +9,19 @@ import type {
9
9
  App,
10
10
  AppConfig,
11
11
  WalletApi,
12
- StorageApi,
13
12
  ChainApi,
14
- BulletinApi,
15
13
  Account,
14
+ CloudStorageApi,
15
+ LocalStorageApi,
16
16
  } from "./types.js";
17
17
  import { configure, createLogger } from "@parity/product-sdk-logger";
18
- import { createKvStore } from "@parity/product-sdk-storage";
18
+ import { createLocalKvStore } from "@parity/product-sdk-local-storage";
19
19
  import { SignerManager } from "@parity/product-sdk-signer";
20
- import { BulletinClient, calculateCid, createLazySigner } from "@parity/product-sdk-bulletin";
20
+ import {
21
+ CloudStorageClient,
22
+ calculateCid,
23
+ createLazySigner,
24
+ } from "@parity/product-sdk-cloud-storage";
21
25
  import {
22
26
  createChainClient,
23
27
  getClient,
@@ -37,33 +41,33 @@ const log = createLogger("app");
37
41
  * ```ts
38
42
  * import { createApp } from '@parity/product-sdk';
39
43
  *
40
- * // Default: bulletin enabled with paseo environment
44
+ * // Default: cloud storage enabled with paseo environment
41
45
  * const app = await createApp({
42
46
  * name: 'my-app',
43
47
  * logLevel: 'info',
44
48
  * });
45
49
  *
46
- * // Custom bulletin environment
50
+ * // Custom cloud storage environment
47
51
  * const prodApp = await createApp({
48
52
  * name: 'my-app',
49
- * bulletin: { environment: 'polkadot' },
53
+ * cloudStorage: { environment: 'polkadot' },
50
54
  * });
51
55
  *
52
- * // Disable bulletin entirely
53
- * const noBulletinApp = await createApp({
56
+ * // Disable cloud storage entirely
57
+ * const noCloudStorageApp = await createApp({
54
58
  * name: 'my-app',
55
- * bulletin: false,
59
+ * cloudStorage: false,
56
60
  * });
57
61
  *
58
62
  * // Connect wallet
59
63
  * const { accounts } = await app.wallet.connect();
60
64
  *
61
65
  * // Use storage
62
- * await app.storage.set('key', 'value');
66
+ * await app.localStorage.set('key', 'value');
63
67
  *
64
- * // Use bulletin (check for null if it might be disabled)
65
- * if (app.bulletin) {
66
- * const cid = await app.bulletin.upload('hello world');
68
+ * // Use cloud storage (check for null if it might be disabled)
69
+ * if (app.cloudStorage) {
70
+ * const cid = await app.cloudStorage.upload('hello world');
67
71
  * }
68
72
  * ```
69
73
  */
@@ -76,44 +80,46 @@ export async function createApp(config: AppConfig): Promise<App> {
76
80
  log.info("Creating Product SDK app", { name: config.name });
77
81
 
78
82
  // Initialize storage (container-only - will throw if not in container)
79
- const kvStore = await createKvStore({ prefix: config.name });
83
+ const localKvStore = await createLocalKvStore({ prefix: config.name });
80
84
 
81
85
  // Initialize signer manager
82
86
  const signerManager = new SignerManager({
83
87
  dappName: config.name,
84
88
  });
85
89
 
86
- // Initialize bulletin client (configurable, defaults to paseo).
90
+ // Initialize cloud storage client (configurable, defaults to paseo).
87
91
  //
88
- // The signer is wrapped lazily so the bulletin client can be built before
92
+ // The signer is wrapped lazily so the cloud storage client can be built before
89
93
  // an account is selected. Uploads will throw a clear error if no signer
90
94
  // is available at submission time. Reads (fetch / fetchJson) don't need
91
95
  // a signer and work regardless.
92
- const bulletinEnabled = config.bulletin !== false;
93
- const bulletinEnvironment =
94
- typeof config.bulletin === "object" ? config.bulletin.environment : "paseo";
95
- const bulletinClient = bulletinEnabled
96
- ? await BulletinClient.create({
97
- environment: bulletinEnvironment,
96
+ const cloudStorageEnabled = config.cloudStorage !== false;
97
+ const cloudStorageEnvironment =
98
+ typeof config.cloudStorage === "object" ? config.cloudStorage.environment : "paseo";
99
+ const cloudStorageClient = cloudStorageEnabled
100
+ ? await CloudStorageClient.create({
101
+ environment: cloudStorageEnvironment,
98
102
  signer: createLazySigner(() => signerManager.getSigner()),
99
103
  })
100
104
  : null;
101
105
 
102
- if (bulletinEnabled) {
103
- log.debug("Bulletin client initialized", { environment: bulletinEnvironment });
106
+ if (cloudStorageEnabled) {
107
+ log.debug("Cloud Storage client (Bulletin) initialized", {
108
+ environment: cloudStorageEnvironment,
109
+ });
104
110
  } else {
105
- log.debug("Bulletin client disabled");
111
+ log.debug("Cloud Storage client disabled");
106
112
  }
107
113
 
108
114
  // Create storage API adapter
109
- const storageApi: StorageApi = {
110
- get: (key) => kvStore.get(key),
111
- set: (key, value) => kvStore.set(key, value),
112
- getJSON: <T>(key: string) => kvStore.getJSON<T>(key),
113
- setJSON: <T>(key: string, value: T) => kvStore.setJSON(key, value),
114
- remove: (key) => kvStore.remove(key),
115
+ const localStorageApi: LocalStorageApi = {
116
+ get: (key) => localKvStore.get(key),
117
+ set: (key, value) => localKvStore.set(key, value),
118
+ getJSON: <T>(key: string) => localKvStore.getJSON<T>(key),
119
+ setJSON: <T>(key: string, value: T) => localKvStore.setJSON(key, value),
120
+ remove: (key) => localKvStore.remove(key),
115
121
  clear: async () => {
116
- // KvStore doesn't have clear - this is a no-op
122
+ // LocalKvStore doesn't have clear - this is a no-op
117
123
  log.debug("clear() is not supported in container storage mode");
118
124
  },
119
125
  };
@@ -153,27 +159,27 @@ export async function createApp(config: AppConfig): Promise<App> {
153
159
  },
154
160
  };
155
161
 
156
- // Create bulletin API adapter (null if disabled)
157
- const bulletinApi: BulletinApi | null = bulletinClient
162
+ // Create Cloud Storage API adapter (null if disabled)
163
+ const cloudStorageApi: CloudStorageApi | null = cloudStorageClient
158
164
  ? {
159
165
  upload: async (data) => {
160
166
  const bytes = typeof data === "string" ? new TextEncoder().encode(data) : data;
161
167
  // Explicitly request a DAG-PB manifest so chunked uploads always
162
168
  // resolve to a single root CID. Without this, AsyncBulletinClient
163
169
  // can return `result.cid: undefined` for chunked-without-manifest
164
- // uploads — but BulletinApi.upload promises a string return, and
170
+ // uploads — but CloudStorageApi.upload promises a string return, and
165
171
  // app consumers expect a CID they can hand to `fetch(cid)`. Keep
166
172
  // the defensive null-check below as belt-and-braces in case the
167
173
  // upstream contract shifts.
168
- const result = await bulletinClient.store(bytes).withManifest(true).send();
174
+ const result = await cloudStorageClient.store(bytes).withManifest(true).send();
169
175
  if (!result.cid) {
170
176
  throw new Error(
171
- "Bulletin upload returned no CID despite .withManifest(true). Upstream contract may have shifted — file an issue.",
177
+ "Cloud storage upload returned no CID despite .withManifest(true). Upstream contract may have shifted — file an issue.",
172
178
  );
173
179
  }
174
180
  return result.cid.toString();
175
181
  },
176
- fetch: (cid) => bulletinClient.fetchBytes(cid),
182
+ fetch: (cid) => cloudStorageClient.fetchBytes(cid),
177
183
  computeCid: async (data) => {
178
184
  const bytes = typeof data === "string" ? new TextEncoder().encode(data) : data;
179
185
  const cid = await calculateCid(bytes);
@@ -184,14 +190,14 @@ export async function createApp(config: AppConfig): Promise<App> {
184
190
 
185
191
  log.info("Product SDK app created", {
186
192
  name: config.name,
187
- bulletin: bulletinEnabled ? bulletinEnvironment : "disabled",
193
+ cloudStorage: cloudStorageEnabled ? cloudStorageEnvironment : "disabled",
188
194
  });
189
195
 
190
196
  return {
191
197
  wallet: walletApi,
192
- storage: storageApi,
198
+ localStorage: localStorageApi,
193
199
  chain: chainApi,
194
- bulletin: bulletinApi,
200
+ cloudStorage: cloudStorageApi,
195
201
  getAppInfo: () => ({ ...config }),
196
202
  };
197
203
  }
package/src/core/types.ts CHANGED
@@ -3,17 +3,17 @@
3
3
  */
4
4
 
5
5
  import type { LogLevel } from "@parity/product-sdk-logger";
6
- import type { BulletinEnvironment } from "@parity/product-sdk-bulletin";
6
+ import type { CloudStorageEnvironment } from "@parity/product-sdk-cloud-storage";
7
7
  import type { ChainClient } from "@parity/product-sdk-chain-client";
8
8
  import type { ChainDefinition, TypedApi, PolkadotClient } from "polkadot-api";
9
9
 
10
10
  export type { LogLevel };
11
11
  export type { ChainClient };
12
12
 
13
- /** Bulletin configuration options */
14
- export interface BulletinConfig {
15
- /** Bulletin environment to connect to */
16
- environment: BulletinEnvironment;
13
+ /** Cloud Storage configuration options */
14
+ export interface CloudStorageConfig {
15
+ /** Cloud Storage environment to connect to */
16
+ environment: CloudStorageEnvironment;
17
17
  }
18
18
 
19
19
  /** Configuration for createApp */
@@ -23,11 +23,11 @@ export interface AppConfig {
23
23
  /** Log level for SDK operations (default: 'info') */
24
24
  logLevel?: LogLevel;
25
25
  /**
26
- * Bulletin Chain configuration.
26
+ * Cloud Storage configuration.
27
27
  * - Omit or pass config object to enable (default: { environment: "paseo" })
28
- * - Pass `false` to disable bulletin initialization
28
+ * - Pass `false` to disable cloud storage initialization
29
29
  */
30
- bulletin?: BulletinConfig | false;
30
+ cloudStorage?: CloudStorageConfig | false;
31
31
  }
32
32
 
33
33
  /** Wallet API exposed by the SDK */
@@ -55,7 +55,7 @@ export interface WalletApi {
55
55
  }
56
56
 
57
57
  /** Storage API exposed by the SDK */
58
- export interface StorageApi {
58
+ export interface LocalStorageApi {
59
59
  /** Get a value by key */
60
60
  get(key: string): Promise<string | null>;
61
61
  /** Set a value by key */
@@ -117,10 +117,10 @@ export interface ChainApi {
117
117
  destroyAll(): void;
118
118
  }
119
119
 
120
- /** Bulletin Chain API exposed by the SDK */
121
- export interface BulletinApi {
120
+ /** Cloud Storage API exposed by the SDK */
121
+ export interface CloudStorageApi {
122
122
  /**
123
- * Upload data to Bulletin Chain.
123
+ * Upload data to the Cloud.
124
124
  *
125
125
  * Requires a wallet to be connected and an account selected. Throws
126
126
  * "No signer available …" otherwise.
@@ -140,12 +140,12 @@ export interface BulletinApi {
140
140
  export interface App {
141
141
  /** Wallet/signing operations */
142
142
  wallet: WalletApi;
143
- /** Key-value storage operations */
144
- storage: StorageApi;
143
+ /** Local Key-value storage operations */
144
+ localStorage: LocalStorageApi;
145
145
  /** Chain interaction operations */
146
146
  chain: ChainApi;
147
- /** Bulletin Chain operations (null if disabled via config) */
148
- bulletin: BulletinApi | null;
147
+ /** Cloud Storage operations (null if disabled via config) */
148
+ cloudStorage: CloudStorageApi | null;
149
149
  /** Get app configuration */
150
150
  getAppInfo(): AppConfig;
151
151
  }
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * @parity/product-sdk/identity
3
3
  *
4
- * Identity utilities including DotNS name resolution,
5
- * product account derivation, and Ring VRF anonymous aliases.
4
+ * Identity utilities: DotNS name resolution, context-alias derivation,
5
+ * and Ring VRF anonymous aliases.
6
6
  */
7
7
 
8
8
  // DotNS utilities
@@ -14,10 +14,10 @@ export {
14
14
  isDotNsAvailable,
15
15
  } from "./dotns.js";
16
16
 
17
- // Product account utilities
17
+ // Context alias utilities
18
18
  export {
19
- deriveProductAccount,
20
- verifyProductAccount,
19
+ deriveContextAlias,
20
+ verifyContextAlias,
21
21
  deriveAnonymousAlias,
22
22
  createRingProof,
23
23
  verifyRingProof,
@@ -26,7 +26,7 @@ export {
26
26
  // Types
27
27
  export type {
28
28
  DotNsRecord,
29
- ProductAccountInfo,
29
+ ContextAliasInfo,
30
30
  AnonymousAliasInfo,
31
31
  RingLocation,
32
32
  VerificationResult,