@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,56 +1,60 @@
1
1
  /**
2
- * Product account derivation
2
+ * Context alias derivation
3
3
  *
4
- * Derives product-scoped accounts from a parent account
4
+ * Derives a deterministic, context-bound alias from a parent account using blake2b-256.
5
+ *
6
+ * NOTE: this is NOT the canonical sr25519 product-account derivation used by
7
+ * mobile, desktop, and dotli hosts. For that, use
8
+ * `@parity/product-sdk-keys::deriveProductAccountPublicKey`.
5
9
  */
6
10
 
7
11
  import { createLogger } from "@parity/product-sdk-logger";
8
12
  import { blake2b256 } from "@parity/product-sdk-crypto";
9
13
  import { ss58Encode, ss58Decode, deriveH160 } from "@parity/product-sdk-address";
10
- import type { ProductAccountInfo, AnonymousAliasInfo, RingLocation } from "./types.js";
14
+ import type { ContextAliasInfo, AnonymousAliasInfo, RingLocation } from "./types.js";
11
15
 
12
16
  const log = createLogger("identity");
13
17
 
14
18
  /**
15
- * Derive a product-scoped account from a parent account
19
+ * Derive a context-bound alias from a parent account.
16
20
  *
17
- * The product account is deterministically derived using:
18
- * productPublicKey = hash(parentPublicKey || productName)
21
+ * The alias is deterministically derived using:
22
+ * aliasPublicKey = blake2b256(parentPublicKey || context)
19
23
  *
20
24
  * @param parentAddress - Parent account SS58 address
21
- * @param productName - Product name for derivation
25
+ * @param context - Context string for derivation (e.g. an app id or scope label)
22
26
  * @param ss58Prefix - SS58 prefix (default: 42)
23
- * @returns Product account info
27
+ * @returns Context alias info
24
28
  *
25
29
  * @example
26
30
  * ```ts
27
- * const productAccount = deriveProductAccount(
31
+ * const alias = deriveContextAlias(
28
32
  * '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY',
29
- * 'my-app'
33
+ * 'voting-round-1'
30
34
  * );
31
- * console.log('Product address:', productAccount.address);
35
+ * console.log('Alias address:', alias.address);
32
36
  * ```
33
37
  */
34
- export function deriveProductAccount(
38
+ export function deriveContextAlias(
35
39
  parentAddress: string,
36
- productName: string,
40
+ context: string,
37
41
  ss58Prefix = 42,
38
- ): ProductAccountInfo {
42
+ ): ContextAliasInfo {
39
43
  const { publicKey: parentPublicKey } = ss58Decode(parentAddress);
40
44
 
41
- // Derive product public key: blake2b-256(parentPublicKey || productName)
42
- const productNameBytes = new TextEncoder().encode(productName);
43
- const combined = new Uint8Array(parentPublicKey.length + productNameBytes.length);
45
+ // Derive alias public key: blake2b-256(parentPublicKey || context)
46
+ const contextBytes = new TextEncoder().encode(context);
47
+ const combined = new Uint8Array(parentPublicKey.length + contextBytes.length);
44
48
  combined.set(parentPublicKey, 0);
45
- combined.set(productNameBytes, parentPublicKey.length);
49
+ combined.set(contextBytes, parentPublicKey.length);
46
50
 
47
- const productPublicKey = blake2b256(combined);
48
- const address = ss58Encode(productPublicKey, ss58Prefix);
49
- const h160Address = deriveH160(productPublicKey);
51
+ const aliasPublicKey = blake2b256(combined);
52
+ const address = ss58Encode(aliasPublicKey, ss58Prefix);
53
+ const h160Address = deriveH160(aliasPublicKey);
50
54
 
51
- log.debug("Derived product account", {
55
+ log.debug("Derived context alias", {
52
56
  parentAddress,
53
- productName,
57
+ context,
54
58
  address,
55
59
  });
56
60
 
@@ -58,32 +62,32 @@ export function deriveProductAccount(
58
62
  address,
59
63
  h160Address,
60
64
  parentAddress,
61
- productName,
65
+ context,
62
66
  };
63
67
  }
64
68
 
65
69
  /**
66
- * Verify that a product account was derived from a parent account
70
+ * Verify that a context alias was derived from a parent account.
67
71
  *
68
- * @param productAddress - Product account address
72
+ * @param aliasAddress - Context alias SS58 address
69
73
  * @param parentAddress - Claimed parent address
70
- * @param productName - Product name
74
+ * @param context - Context string used for derivation
71
75
  * @returns True if derivation is valid
72
76
  */
73
- export function verifyProductAccount(
74
- productAddress: string,
77
+ export function verifyContextAlias(
78
+ aliasAddress: string,
75
79
  parentAddress: string,
76
- productName: string,
80
+ context: string,
77
81
  ): boolean {
78
82
  try {
79
- const derived = deriveProductAccount(parentAddress, productName);
80
- const { publicKey: productKey } = ss58Decode(productAddress);
83
+ const derived = deriveContextAlias(parentAddress, context);
84
+ const { publicKey: aliasKey } = ss58Decode(aliasAddress);
81
85
  const { publicKey: derivedKey } = ss58Decode(derived.address);
82
86
 
83
87
  // Compare public keys
84
- if (productKey.length !== derivedKey.length) return false;
85
- for (let i = 0; i < productKey.length; i++) {
86
- if (productKey[i] !== derivedKey[i]) return false;
88
+ if (aliasKey.length !== derivedKey.length) return false;
89
+ for (let i = 0; i < aliasKey.length; i++) {
90
+ if (aliasKey[i] !== derivedKey[i]) return false;
87
91
  }
88
92
  return true;
89
93
  } catch {
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Identity module types
3
3
  *
4
- * Types for DotNS name resolution and product account derivation
4
+ * Types for DotNS name resolution and context-alias derivation
5
5
  */
6
6
 
7
7
  /** DotNS name resolution result */
@@ -16,16 +16,16 @@ export interface DotNsRecord {
16
16
  expiresAt?: number;
17
17
  }
18
18
 
19
- /** Product account info */
20
- export interface ProductAccountInfo {
21
- /** Product-scoped SS58 address */
19
+ /** Context alias info: a deterministic, context-bound alias derived from a parent account */
20
+ export interface ContextAliasInfo {
21
+ /** Alias SS58 address */
22
22
  address: string;
23
23
  /** H160 EVM address */
24
24
  h160Address: `0x${string}`;
25
25
  /** Parent account address */
26
26
  parentAddress: string;
27
- /** Product name used for derivation */
28
- productName: string;
27
+ /** Context string used for derivation */
28
+ context: string;
29
29
  }
30
30
 
31
31
  /** Ring VRF alias info */
package/src/index.ts CHANGED
@@ -16,7 +16,7 @@
16
16
  * const { accounts } = await app.wallet.connect();
17
17
  *
18
18
  * // Use storage
19
- * await app.storage.set('key', 'value');
19
+ * await app.localStorage.set('key', 'value');
20
20
  * ```
21
21
  *
22
22
  * @packageDocumentation
@@ -30,9 +30,9 @@ export type {
30
30
  AppConfig,
31
31
  LogLevel,
32
32
  WalletApi,
33
- StorageApi,
33
+ LocalStorageApi,
34
34
  ChainApi,
35
- BulletinApi,
35
+ CloudStorageApi,
36
36
  Account,
37
37
  ChainClient,
38
38
  ChainDefinition,
@@ -45,5 +45,5 @@ export type { LogEntry, LogHandler, LoggerConfig, Logger } from "./core/logger.j
45
45
  export { isInsideContainer, isInsideContainerSync } from "@parity/product-sdk-host";
46
46
  export { createChainClient } from "@parity/product-sdk-chain-client";
47
47
  export { SignerManager } from "@parity/product-sdk-signer";
48
- export { createKvStore } from "@parity/product-sdk-storage";
49
- export { BulletinClient, calculateCid } from "@parity/product-sdk-bulletin";
48
+ export { createLocalKvStore } from "@parity/product-sdk-local-storage";
49
+ export { CloudStorageClient, calculateCid } from "@parity/product-sdk-cloud-storage";
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @parity/product-sdk/local-storage
3
+ *
4
+ * Re-exports from @parity/product-sdk-local-storage.
5
+ */
6
+ export * from "@parity/product-sdk-local-storage";
@@ -17,7 +17,7 @@ export const ProductSDKContext = createContext<App | null>(null);
17
17
  * ```tsx
18
18
  * function MyComponent() {
19
19
  * const app = useProductSDK();
20
- * // Use app.wallet, app.storage, etc.
20
+ * // Use app.wallet, app.localStorage, etc.
21
21
  * }
22
22
  * ```
23
23
  */
@@ -6,7 +6,7 @@
6
6
  *
7
7
  * @example
8
8
  * ```tsx
9
- * import { ProductSDKProvider, useWallet, useStorage } from '@parity/product-sdk/react';
9
+ * import { ProductSDKProvider, useWallet, useLocalStorage } from '@parity/product-sdk/react';
10
10
  *
11
11
  * function App() {
12
12
  * return (
@@ -18,7 +18,7 @@
18
18
  *
19
19
  * function MyApp() {
20
20
  * const { isConnected, connect, accounts } = useWallet();
21
- * const [theme, setTheme] = useStorage('theme', 'light');
21
+ * const [theme, setTheme] = useLocalStorage('theme', 'light');
22
22
  *
23
23
  * // ...
24
24
  * }
@@ -36,6 +36,6 @@ export { ProductSDKContext, useProductSDK } from "./context.js";
36
36
  export { useWallet } from "./useWallet.js";
37
37
  export type { UseWalletState, UseWalletActions, UseWalletReturn } from "./useWallet.js";
38
38
 
39
- export { useStorage, useStorageString } from "./useStorage.js";
39
+ export { useLocalStorage, useLocalStorageString } from "./useLocalStorage.js";
40
40
 
41
41
  export { useChain } from "./useChain.js";
@@ -1,5 +1,5 @@
1
1
  /**
2
- * useStorage hook
2
+ * useLocalStorage hook
3
3
  */
4
4
 
5
5
  import { useState, useEffect, useCallback } from "react";
@@ -14,7 +14,7 @@ import { useProductSDK } from "./context.js";
14
14
  * @example
15
15
  * ```tsx
16
16
  * function ThemeToggle() {
17
- * const [theme, setTheme, { loading }] = useStorage('theme', 'light');
17
+ * const [theme, setTheme, { loading }] = useLocalStorage('theme', 'light');
18
18
  *
19
19
  * if (loading) return <div>Loading...</div>;
20
20
  *
@@ -26,7 +26,7 @@ import { useProductSDK } from "./context.js";
26
26
  * }
27
27
  * ```
28
28
  */
29
- export function useStorage<T = string>(
29
+ export function useLocalStorage<T = string>(
30
30
  key: string,
31
31
  defaultValue?: T,
32
32
  ): [T | null, (value: T) => Promise<void>, { loading: boolean; error: Error | null }] {
@@ -43,7 +43,7 @@ export function useStorage<T = string>(
43
43
  const loadValue = async () => {
44
44
  try {
45
45
  setLoading(true);
46
- const stored = await app.storage.getJSON<T>(key);
46
+ const stored = await app.localStorage.getJSON<T>(key);
47
47
  if (mounted) {
48
48
  setValue(stored ?? defaultValue ?? null);
49
49
  setLoading(false);
@@ -67,7 +67,7 @@ export function useStorage<T = string>(
67
67
  async (newValue: T) => {
68
68
  try {
69
69
  setError(null);
70
- await app.storage.setJSON(key, newValue);
70
+ await app.localStorage.setJSON(key, newValue);
71
71
  setValue(newValue);
72
72
  } catch (e) {
73
73
  setError(e instanceof Error ? e : new Error(String(e)));
@@ -86,7 +86,7 @@ export function useStorage<T = string>(
86
86
  * @param key - Storage key
87
87
  * @param defaultValue - Default value
88
88
  */
89
- export function useStorageString(
89
+ export function useLocalStorageString(
90
90
  key: string,
91
91
  defaultValue?: string,
92
92
  ): [string | null, (value: string) => Promise<void>, { loading: boolean }] {
@@ -99,7 +99,7 @@ export function useStorageString(
99
99
  let mounted = true;
100
100
 
101
101
  const loadValue = async () => {
102
- const stored = await app.storage.get(key);
102
+ const stored = await app.localStorage.get(key);
103
103
  if (mounted) {
104
104
  setValue(stored ?? defaultValue ?? null);
105
105
  setLoading(false);
@@ -115,7 +115,7 @@ export function useStorageString(
115
115
 
116
116
  const setStoredValue = useCallback(
117
117
  async (newValue: string) => {
118
- await app.storage.set(key, newValue);
118
+ await app.localStorage.set(key, newValue);
119
119
  setValue(newValue);
120
120
  },
121
121
  [app, key],
@@ -1 +0,0 @@
1
- export * from '@parity/product-sdk-bulletin';
@@ -1,3 +0,0 @@
1
- export * from '@parity/product-sdk-bulletin';
2
- //# sourceMappingURL=index.js.map
3
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/core/createApp.ts"],"names":[],"mappings":";;;;;;;AA2BA,IAAM,GAAA,GAAM,aAAa,KAAK,CAAA;AA0C9B,eAAsB,UAAU,MAAA,EAAiC;AAE7D,EAAA,IAAI,OAAO,QAAA,EAAU;AACjB,IAAA,SAAA,CAAU,EAAE,KAAA,EAAO,MAAA,CAAO,QAAA,EAAU,CAAA;AAAA,EACxC;AAEA,EAAA,GAAA,CAAI,KAAK,0BAAA,EAA4B,EAAE,IAAA,EAAM,MAAA,CAAO,MAAM,CAAA;AAG1D,EAAA,MAAM,UAAU,MAAM,aAAA,CAAc,EAAE,MAAA,EAAQ,MAAA,CAAO,MAAM,CAAA;AAG3D,EAAA,MAAM,aAAA,GAAgB,IAAI,aAAA,CAAc;AAAA,IACpC,UAAU,MAAA,CAAO;AAAA,GACpB,CAAA;AAQD,EAAA,MAAM,eAAA,GAAkB,OAAO,QAAA,KAAa,KAAA;AAC5C,EAAA,MAAM,sBACF,OAAO,MAAA,CAAO,aAAa,QAAA,GAAW,MAAA,CAAO,SAAS,WAAA,GAAc,OAAA;AACxE,EAAA,MAAM,cAAA,GAAiB,eAAA,GACjB,MAAM,cAAA,CAAe,MAAA,CAAO;AAAA,IACxB,WAAA,EAAa,mBAAA;AAAA,IACb,MAAA,EAAQ,gBAAA,CAAiB,MAAM,aA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AAA,IAEA,MAAM,YAAY,OAAA,EAAmD;AACjE,MAAA,MAAM,KAAA,GAAQ,OAAO,OAAA,KAAY,QAAA,GAAW,IAAI,WAAA,EAAY,CAAE,MAAA,CAAO,OAAO,CAAA,GAAI,OAAA;AAChF,MAAA,MAAM,MAAA,GAAS,MAAM,aAAA,CAAc,OAAA,CAAQ,KAAK,CAAA;AAChD,MAAA,IAAI,CAAC,OAAO,EAAA,EAAI;AACZ,QAAA,MAAM,IAAI,KAAA,CAAM,MAAA,CAAO,KAAA,CAAM,OAAO,CAAA;AAAA,MACxC;AACA,MAAA,OAAO,MAAA,CAAO,KAAA;AAAA,IAClB,CAAA;AAAA,IAEA,gBAAgB,QAAA,EAAyD;AACrE,MAAA,wBAAA,CAAyB,IAAI,QAAQ,CAAA;AACrC,MAAA,OAAO,MAAM,wBAAA,CAAyB,MAAA,CAAO,QAAQ,CAAA;AAAA,IACzD,CAAA;AAAA,IAEA,iBAAA,GAAoC;AAGhC,MAAA,GAAA,CAAI,IAAA;AAAA,QACA;AAAA,OACJ;AACA,MAAA,OAAO,IAAA;AAAA,IACX,CAAA;AAAA,IAEA,iBAAA,GAAmC;AAG/B,MAAA,GAAA,CAAI,IAAA;AAAA,QACA;AAAA,OACJ;AACA,MAAA,OAAO,IAAA;AAAA,IACX,CAAA;AAAA,IAEA,MAAM,YAAY,QAAA,EAA2C;AAEzD,MAAA,MAAM,IAAI,KAAA;AAAA,QACN;AAAA,OAEJ;AAAA,IACJ;AAAA,GACJ;AACJ","file":"chunk-6W3TCR3W.js","sourcesContent":["/**\n * createApp - Main entry point for the Product SDK\n *\n * Creates an App instance with wallet, storage, chain, and bulletin APIs.\n */\n\nimport type { ChainDefinition } from \"polkadot-api\";\nimport type {\n App,\n AppConfig,\n WalletApi,\n StorageApi,\n ChainApi,\n BulletinApi,\n Account,\n} from \"./types.js\";\nimport { configure, createLogger } from \"@parity/product-sdk-logger\";\nimport { createKvStore } from \"@parity/product-sdk-storage\";\nimport { SignerManager } from \"@parity/product-sdk-signer\";\nimport { BulletinClient, calculateCid, createLazySigner } from \"@parity/product-sdk-bulletin\";\nimport {\n createChainClient,\n getClient,\n isConnected,\n destroyAll,\n} from \"@parity/product-sdk-chain-client\";\n\nconst log = createLogger(\"app\");\n\n/**\n * Create a new Product SDK app instance\n *\n * @param config - Application configuration\n * @returns App instance with all APIs\n *\n * @example\n * ```ts\n * import { createApp } from '@parity/product-sdk';\n *\n * // Default: bulletin enabled with paseo environment\n * const app = await createApp({\n * name: 'my-app',\n * logLevel: 'info',\n * });\n *\n * // Custom bulletin environment\n * const prodApp = await createApp({\n * name: 'my-app',\n * bulletin: { environment: 'polkadot' },\n * });\n *\n * // Disable bulletin entirely\n * const noBulletinApp = await createApp({\n * name: 'my-app',\n * bulletin: false,\n * });\n *\n * // Connect wallet\n * const { accounts } = await app.wallet.connect();\n *\n * // Use storage\n * await app.storage.set('key', 'value');\n *\n * // Use bulletin (check for null if it might be disabled)\n * if (app.bulletin) {\n * const cid = await app.bulletin.upload('hello world');\n * }\n * ```\n */\nexport async function createApp(config: AppConfig): Promise<App> {\n // Set log level if specified\n if (config.logLevel) {\n configure({ level: config.logLevel });\n }\n\n log.info(\"Creating Product SDK app\", { name: config.name });\n\n // Initialize storage (container-only - will throw if not in container)\n const kvStore = await createKvStore({ prefix: config.name });\n\n // Initialize signer manager\n const signerManager = new SignerManager({\n dappName: config.name,\n });\n\n // Initialize bulletin client (configurable, defaults to paseo).\n //\n // The signer is wrapped lazily so the bulletin client can be built before\n // an account is selected. Uploads will throw a clear error if no signer\n // is available at submission time. Reads (fetch / fetchJson) don't need\n // a signer and work regardless.\n const bulletinEnabled = config.bulletin !== false;\n const bulletinEnvironment =\n typeof config.bulletin === \"object\" ? config.bulletin.environment : \"paseo\";\n const bulletinClient = bulletinEnabled\n ? await BulletinClient.create({\n environment: bulletinEnvironment,\n signer: createLazySigner(() => signerManager.getSigner()),\n })\n : null;\n\n if (bulletinEnabled) {\n log.debug(\"Bulletin client initialized\", { environment: bulletinEnvironment });\n } else {\n log.debug(\"Bulletin client disabled\");\n }\n\n // Create storage API adapter\n const storageApi: StorageApi = {\n get: (key) => kvStore.get(key),\n set: (key, value) => kvStore.set(key, value),\n getJSON: <T>(key: string) => kvStore.getJSON<T>(key),\n setJSON: <T>(key: string, value: T) => kvStore.setJSON(key, value),\n remove: (key) => kvStore.remove(key),\n clear: async () => {\n // KvStore doesn't have clear - this is a no-op\n log.debug(\"clear() is not supported in container storage mode\");\n },\n };\n\n // Create wallet API adapter\n const walletApi = createWalletApi(signerManager);\n\n // Create chain API\n const chainApi: ChainApi = {\n getClient(descriptor) {\n log.debug(\"getClient called\", { genesis: descriptor.genesis });\n const client = getClient(descriptor);\n return client.getTypedApi(descriptor);\n },\n\n getRawClient(descriptor) {\n log.debug(\"getRawClient called\", { genesis: descriptor.genesis });\n return getClient(descriptor);\n },\n\n async connect<T extends Record<string, ChainDefinition>>(chains: T) {\n log.debug(\"connect called\", { chains: Object.keys(chains) });\n // Build empty rpcs object (required by API but unused - host routes connections)\n const rpcs = Object.fromEntries(\n Object.keys(chains).map((k) => [k, [] as readonly string[]]),\n ) as { [K in keyof T]: readonly string[] };\n return createChainClient({ chains, rpcs });\n },\n\n isConnected(descriptor) {\n return isConnected(descriptor);\n },\n\n destroyAll() {\n log.debug(\"destroyAll called\");\n destroyAll();\n },\n };\n\n // Create bulletin API adapter (null if disabled)\n const bulletinApi: BulletinApi | null = bulletinClient\n ? {\n upload: async (data) => {\n const bytes = typeof data === \"string\" ? new TextEncoder().encode(data) : data;\n // Explicitly request a DAG-PB manifest so chunked uploads always\n // resolve to a single root CID. Without this, AsyncBulletinClient\n // can return `result.cid: undefined` for chunked-without-manifest\n // uploads — but BulletinApi.upload promises a string return, and\n // app consumers expect a CID they can hand to `fetch(cid)`. Keep\n // the defensive null-check below as belt-and-braces in case the\n // upstream contract shifts.\n const result = await bulletinClient.store(bytes).withManifest(true).send();\n if (!result.cid) {\n throw new Error(\n \"Bulletin upload returned no CID despite .withManifest(true). Upstream contract may have shifted — file an issue.\",\n );\n }\n return result.cid.toString();\n },\n fetch: (cid) => bulletinClient.fetchBytes(cid),\n computeCid: async (data) => {\n const bytes = typeof data === \"string\" ? new TextEncoder().encode(data) : data;\n const cid = await calculateCid(bytes);\n return cid.toString();\n },\n }\n : null;\n\n log.info(\"Product SDK app created\", {\n name: config.name,\n bulletin: bulletinEnabled ? bulletinEnvironment : \"disabled\",\n });\n\n return {\n wallet: walletApi,\n storage: storageApi,\n chain: chainApi,\n bulletin: bulletinApi,\n getAppInfo: () => ({ ...config }),\n };\n}\n\n/**\n * Create wallet API adapter using SignerManager from leaf package\n */\nfunction createWalletApi(signerManager: SignerManager): WalletApi {\n // Track account change subscribers\n const accountChangeSubscribers = new Set<(account: Account | null) => void>();\n\n // Subscribe to signer manager state changes\n signerManager.subscribe((state) => {\n const account = state.selectedAccount\n ? {\n address: state.selectedAccount.address,\n name: state.selectedAccount.name ?? undefined,\n source: state.selectedAccount.source,\n }\n : null;\n for (const callback of accountChangeSubscribers) {\n try {\n callback(account);\n } catch (e) {\n log.warn(\"Account change callback threw\", { error: e });\n }\n }\n });\n\n return {\n async connect(): Promise<{ accounts: Account[] }> {\n const result = await signerManager.connect();\n if (!result.ok) {\n throw new Error(result.error.message);\n }\n return {\n accounts: result.value.map((a) => ({\n address: a.address,\n name: a.name ?? undefined,\n source: a.source,\n })),\n };\n },\n\n async disconnect(): Promise<void> {\n signerManager.disconnect();\n },\n\n getAccounts(): Account[] {\n return signerManager.getState().accounts.map((a) => ({\n address: a.address,\n name: a.name ?? undefined,\n source: a.source,\n }));\n },\n\n getSelectedAccount(): Account | null {\n const selected = signerManager.getState().selectedAccount;\n if (!selected) return null;\n return {\n address: selected.address,\n name: selected.name ?? undefined,\n source: selected.source,\n };\n },\n\n selectAccount(address: string): void {\n signerManager.selectAccount(address);\n },\n\n async signMessage(message: string | Uint8Array): Promise<Uint8Array> {\n const bytes = typeof message === \"string\" ? new TextEncoder().encode(message) : message;\n const result = await signerManager.signRaw(bytes);\n if (!result.ok) {\n throw new Error(result.error.message);\n }\n return result.value;\n },\n\n onAccountChange(callback: (account: Account | null) => void): () => void {\n accountChangeSubscribers.add(callback);\n return () => accountChangeSubscribers.delete(callback);\n },\n\n getProductAccount(): Account | null {\n // Product accounts require async call - this sync API can't support it properly\n // Users should use SignerManager.getProductAccount() directly\n log.warn(\n \"getProductAccount() is deprecated - use SignerManager.getProductAccount() directly\",\n );\n return null;\n },\n\n getAnonymousAlias(): string | null {\n // Anonymous aliases require async call - this sync API can't support it properly\n // Users should use SignerManager.getProductAccountAlias() directly\n log.warn(\n \"getAnonymousAlias() is deprecated - use SignerManager.getProductAccountAlias() directly\",\n );\n return null;\n },\n\n async createProof(_message: Uint8Array): Promise<Uint8Array> {\n // Ring VRF proofs require SignerManager.createRingVRFProof() directly\n throw new Error(\n \"createProof() is not implemented in the App API. \" +\n \"Use SignerManager.createRingVRFProof() directly.\",\n );\n },\n };\n}\n"]}
@@ -1 +0,0 @@
1
- export * from '@parity/product-sdk-storage';
@@ -1,3 +0,0 @@
1
- export * from '@parity/product-sdk-storage';
2
- //# sourceMappingURL=index.js.map
3
- //# sourceMappingURL=index.js.map
@@ -1,6 +0,0 @@
1
- /**
2
- * @parity/product-sdk/bulletin
3
- *
4
- * Re-exports from @parity/product-sdk-bulletin.
5
- */
6
- export * from "@parity/product-sdk-bulletin";
@@ -1,6 +0,0 @@
1
- /**
2
- * @parity/product-sdk/storage
3
- *
4
- * Re-exports from @parity/product-sdk-storage.
5
- */
6
- export * from "@parity/product-sdk-storage";
File without changes
File without changes