@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.
- package/dist/address/index.d.ts +2 -2
- package/dist/{chunk-6W3TCR3W.js → chunk-4U2FP26I.js} +27 -25
- package/dist/chunk-4U2FP26I.js.map +1 -0
- package/dist/cloud-storage/index.d.ts +1 -0
- package/dist/cloud-storage/index.js +3 -0
- package/dist/core/index.d.ts +3 -3
- package/dist/core/index.js +1 -1
- package/dist/identity/index.d.ts +26 -22
- package/dist/identity/index.js +17 -17
- package/dist/identity/index.js.map +1 -1
- package/dist/index.d.ts +15 -15
- package/dist/index.js +3 -3
- package/dist/local-storage/index.d.ts +1 -0
- package/dist/local-storage/index.js +3 -0
- package/dist/react/index.d.ts +8 -8
- package/dist/react/index.js +8 -8
- package/dist/react/index.js.map +1 -1
- package/dist/{types-DVpAr2JN.d.ts → types-AjDV1BTd.d.ts} +17 -17
- package/package.json +16 -16
- package/src/cloud-storage/index.ts +6 -0
- package/src/core/createApp.ts +49 -43
- package/src/core/types.ts +16 -16
- package/src/identity/index.ts +6 -6
- package/src/identity/product-account.ts +39 -35
- package/src/identity/types.ts +6 -6
- package/src/index.ts +5 -5
- package/src/local-storage/index.ts +6 -0
- package/src/react/context.ts +1 -1
- package/src/react/index.ts +3 -3
- package/src/react/{useStorage.ts → useLocalStorage.ts} +8 -8
- package/dist/bulletin/index.d.ts +0 -1
- package/dist/bulletin/index.js +0 -3
- package/dist/chunk-6W3TCR3W.js.map +0 -1
- package/dist/storage/index.d.ts +0 -1
- package/dist/storage/index.js +0 -3
- package/src/bulletin/index.ts +0 -6
- package/src/storage/index.ts +0 -6
- /package/dist/{bulletin → cloud-storage}/index.js.map +0 -0
- /package/dist/{storage → local-storage}/index.js.map +0 -0
package/dist/address/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export * from '@parity/product-sdk-address';
|
|
2
|
-
import '@parity/product-sdk-
|
|
2
|
+
import '@parity/product-sdk-cloud-storage';
|
|
3
3
|
import '@parity/product-sdk-chain-client';
|
|
4
4
|
import '@parity/product-sdk-contracts';
|
|
5
5
|
import '@parity/product-sdk-crypto';
|
|
6
6
|
import '@parity/product-sdk-host';
|
|
7
|
-
import '@parity/product-sdk-storage';
|
|
7
|
+
import '@parity/product-sdk-local-storage';
|
|
8
8
|
import '@parity/product-sdk-signer';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createLogger, configure } from '@parity/product-sdk-logger';
|
|
2
|
-
import {
|
|
2
|
+
import { createLocalKvStore } from '@parity/product-sdk-local-storage';
|
|
3
3
|
import { SignerManager } from '@parity/product-sdk-signer';
|
|
4
|
-
import {
|
|
4
|
+
import { CloudStorageClient, createLazySigner, calculateCid } from '@parity/product-sdk-cloud-storage';
|
|
5
5
|
import { destroyAll, isConnected, createChainClient, getClient } from '@parity/product-sdk-chain-client';
|
|
6
6
|
|
|
7
7
|
// src/core/createApp.ts
|
|
@@ -11,27 +11,29 @@ async function createApp(config) {
|
|
|
11
11
|
configure({ level: config.logLevel });
|
|
12
12
|
}
|
|
13
13
|
log.info("Creating Product SDK app", { name: config.name });
|
|
14
|
-
const
|
|
14
|
+
const localKvStore = await createLocalKvStore({ prefix: config.name });
|
|
15
15
|
const signerManager = new SignerManager({
|
|
16
16
|
dappName: config.name
|
|
17
17
|
});
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
environment:
|
|
18
|
+
const cloudStorageEnabled = config.cloudStorage !== false;
|
|
19
|
+
const cloudStorageEnvironment = typeof config.cloudStorage === "object" ? config.cloudStorage.environment : "paseo";
|
|
20
|
+
const cloudStorageClient = cloudStorageEnabled ? await CloudStorageClient.create({
|
|
21
|
+
environment: cloudStorageEnvironment,
|
|
22
22
|
signer: createLazySigner(() => signerManager.getSigner())
|
|
23
23
|
}) : null;
|
|
24
|
-
if (
|
|
25
|
-
log.debug("
|
|
24
|
+
if (cloudStorageEnabled) {
|
|
25
|
+
log.debug("Cloud Storage client (Bulletin) initialized", {
|
|
26
|
+
environment: cloudStorageEnvironment
|
|
27
|
+
});
|
|
26
28
|
} else {
|
|
27
|
-
log.debug("
|
|
29
|
+
log.debug("Cloud Storage client disabled");
|
|
28
30
|
}
|
|
29
|
-
const
|
|
30
|
-
get: (key) =>
|
|
31
|
-
set: (key, value) =>
|
|
32
|
-
getJSON: (key) =>
|
|
33
|
-
setJSON: (key, value) =>
|
|
34
|
-
remove: (key) =>
|
|
31
|
+
const localStorageApi = {
|
|
32
|
+
get: (key) => localKvStore.get(key),
|
|
33
|
+
set: (key, value) => localKvStore.set(key, value),
|
|
34
|
+
getJSON: (key) => localKvStore.getJSON(key),
|
|
35
|
+
setJSON: (key, value) => localKvStore.setJSON(key, value),
|
|
36
|
+
remove: (key) => localKvStore.remove(key),
|
|
35
37
|
clear: async () => {
|
|
36
38
|
log.debug("clear() is not supported in container storage mode");
|
|
37
39
|
}
|
|
@@ -62,18 +64,18 @@ async function createApp(config) {
|
|
|
62
64
|
destroyAll();
|
|
63
65
|
}
|
|
64
66
|
};
|
|
65
|
-
const
|
|
67
|
+
const cloudStorageApi = cloudStorageClient ? {
|
|
66
68
|
upload: async (data) => {
|
|
67
69
|
const bytes = typeof data === "string" ? new TextEncoder().encode(data) : data;
|
|
68
|
-
const result = await
|
|
70
|
+
const result = await cloudStorageClient.store(bytes).withManifest(true).send();
|
|
69
71
|
if (!result.cid) {
|
|
70
72
|
throw new Error(
|
|
71
|
-
"
|
|
73
|
+
"Cloud storage upload returned no CID despite .withManifest(true). Upstream contract may have shifted \u2014 file an issue."
|
|
72
74
|
);
|
|
73
75
|
}
|
|
74
76
|
return result.cid.toString();
|
|
75
77
|
},
|
|
76
|
-
fetch: (cid) =>
|
|
78
|
+
fetch: (cid) => cloudStorageClient.fetchBytes(cid),
|
|
77
79
|
computeCid: async (data) => {
|
|
78
80
|
const bytes = typeof data === "string" ? new TextEncoder().encode(data) : data;
|
|
79
81
|
const cid = await calculateCid(bytes);
|
|
@@ -82,13 +84,13 @@ async function createApp(config) {
|
|
|
82
84
|
} : null;
|
|
83
85
|
log.info("Product SDK app created", {
|
|
84
86
|
name: config.name,
|
|
85
|
-
|
|
87
|
+
cloudStorage: cloudStorageEnabled ? cloudStorageEnvironment : "disabled"
|
|
86
88
|
});
|
|
87
89
|
return {
|
|
88
90
|
wallet: walletApi,
|
|
89
|
-
|
|
91
|
+
localStorage: localStorageApi,
|
|
90
92
|
chain: chainApi,
|
|
91
|
-
|
|
93
|
+
cloudStorage: cloudStorageApi,
|
|
92
94
|
getAppInfo: () => ({ ...config })
|
|
93
95
|
};
|
|
94
96
|
}
|
|
@@ -177,5 +179,5 @@ function createWalletApi(signerManager) {
|
|
|
177
179
|
}
|
|
178
180
|
|
|
179
181
|
export { createApp };
|
|
180
|
-
//# sourceMappingURL=chunk-
|
|
181
|
-
//# sourceMappingURL=chunk-
|
|
182
|
+
//# sourceMappingURL=chunk-4U2FP26I.js.map
|
|
183
|
+
//# sourceMappingURL=chunk-4U2FP26I.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/createApp.ts"],"names":[],"mappings":";;;;;;;AA+BA,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,eAAe,MAAM,kBAAA,CAAmB,EAAE,MAAA,EAAQ,MAAA,CAAO,MAAM,CAAA;AAGrE,EAAA,MAAM,aAAA,GAAgB,IAAI,aAAA,CAAc;AAAA,IACpC,UAAU,MAAA,CAAO;AAAA,GACpB,CAAA;AAQ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AAA,GACJ;AACJ","file":"chunk-4U2FP26I.js","sourcesContent":["/**\n * createApp - Main entry point for the Product SDK\n *\n * Creates an App instance with wallet, storage, chain, and cloud storage APIs.\n */\n\nimport type { ChainDefinition } from \"polkadot-api\";\nimport type {\n App,\n AppConfig,\n WalletApi,\n ChainApi,\n Account,\n CloudStorageApi,\n LocalStorageApi,\n} from \"./types.js\";\nimport { configure, createLogger } from \"@parity/product-sdk-logger\";\nimport { createLocalKvStore } from \"@parity/product-sdk-local-storage\";\nimport { SignerManager } from \"@parity/product-sdk-signer\";\nimport {\n CloudStorageClient,\n calculateCid,\n createLazySigner,\n} from \"@parity/product-sdk-cloud-storage\";\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: cloud storage enabled with paseo environment\n * const app = await createApp({\n * name: 'my-app',\n * logLevel: 'info',\n * });\n *\n * // Custom cloud storage environment\n * const prodApp = await createApp({\n * name: 'my-app',\n * cloudStorage: { environment: 'polkadot' },\n * });\n *\n * // Disable cloud storage entirely\n * const noCloudStorageApp = await createApp({\n * name: 'my-app',\n * cloudStorage: false,\n * });\n *\n * // Connect wallet\n * const { accounts } = await app.wallet.connect();\n *\n * // Use storage\n * await app.localStorage.set('key', 'value');\n *\n * // Use cloud storage (check for null if it might be disabled)\n * if (app.cloudStorage) {\n * const cid = await app.cloudStorage.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 localKvStore = await createLocalKvStore({ prefix: config.name });\n\n // Initialize signer manager\n const signerManager = new SignerManager({\n dappName: config.name,\n });\n\n // Initialize cloud storage client (configurable, defaults to paseo).\n //\n // The signer is wrapped lazily so the cloud storage 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 cloudStorageEnabled = config.cloudStorage !== false;\n const cloudStorageEnvironment =\n typeof config.cloudStorage === \"object\" ? config.cloudStorage.environment : \"paseo\";\n const cloudStorageClient = cloudStorageEnabled\n ? await CloudStorageClient.create({\n environment: cloudStorageEnvironment,\n signer: createLazySigner(() => signerManager.getSigner()),\n })\n : null;\n\n if (cloudStorageEnabled) {\n log.debug(\"Cloud Storage client (Bulletin) initialized\", {\n environment: cloudStorageEnvironment,\n });\n } else {\n log.debug(\"Cloud Storage client disabled\");\n }\n\n // Create storage API adapter\n const localStorageApi: LocalStorageApi = {\n get: (key) => localKvStore.get(key),\n set: (key, value) => localKvStore.set(key, value),\n getJSON: <T>(key: string) => localKvStore.getJSON<T>(key),\n setJSON: <T>(key: string, value: T) => localKvStore.setJSON(key, value),\n remove: (key) => localKvStore.remove(key),\n clear: async () => {\n // LocalKvStore 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 Cloud Storage API adapter (null if disabled)\n const cloudStorageApi: CloudStorageApi | null = cloudStorageClient\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 CloudStorageApi.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 cloudStorageClient.store(bytes).withManifest(true).send();\n if (!result.cid) {\n throw new Error(\n \"Cloud storage 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) => cloudStorageClient.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 cloudStorage: cloudStorageEnabled ? cloudStorageEnvironment : \"disabled\",\n });\n\n return {\n wallet: walletApi,\n localStorage: localStorageApi,\n chain: chainApi,\n cloudStorage: cloudStorageApi,\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"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@parity/product-sdk-cloud-storage';
|
package/dist/core/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export { createApp } from '../index.js';
|
|
2
2
|
export { LogEntry, LogHandler, LogLevel, Logger, LoggerConfig, configure, createLogger } from '@parity/product-sdk-logger';
|
|
3
|
-
export { a as Account, A as App, b as AppConfig,
|
|
3
|
+
export { a as Account, A as App, b as AppConfig, C as ChainApi, c as CloudStorageApi, d as CloudStorageConfig, L as LocalStorageApi, W as WalletApi } from '../types-AjDV1BTd.js';
|
|
4
4
|
export { ChainClient } from '@parity/product-sdk-chain-client';
|
|
5
5
|
export { ChainDefinition, PolkadotClient, TypedApi } from 'polkadot-api';
|
|
6
6
|
import '@parity/product-sdk-host';
|
|
7
7
|
import '@parity/product-sdk-signer';
|
|
8
|
-
import '@parity/product-sdk-storage';
|
|
9
|
-
import '@parity/product-sdk-
|
|
8
|
+
import '@parity/product-sdk-local-storage';
|
|
9
|
+
import '@parity/product-sdk-cloud-storage';
|
package/dist/core/index.js
CHANGED
package/dist/identity/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Identity module types
|
|
3
3
|
*
|
|
4
|
-
* Types for DotNS name resolution and
|
|
4
|
+
* Types for DotNS name resolution and context-alias derivation
|
|
5
5
|
*/
|
|
6
6
|
/** DotNS name resolution result */
|
|
7
7
|
interface DotNsRecord {
|
|
@@ -14,16 +14,16 @@ interface DotNsRecord {
|
|
|
14
14
|
/** Expiration timestamp (if applicable) */
|
|
15
15
|
expiresAt?: number;
|
|
16
16
|
}
|
|
17
|
-
/**
|
|
18
|
-
interface
|
|
19
|
-
/**
|
|
17
|
+
/** Context alias info: a deterministic, context-bound alias derived from a parent account */
|
|
18
|
+
interface ContextAliasInfo {
|
|
19
|
+
/** Alias SS58 address */
|
|
20
20
|
address: string;
|
|
21
21
|
/** H160 EVM address */
|
|
22
22
|
h160Address: `0x${string}`;
|
|
23
23
|
/** Parent account address */
|
|
24
24
|
parentAddress: string;
|
|
25
|
-
/**
|
|
26
|
-
|
|
25
|
+
/** Context string used for derivation */
|
|
26
|
+
context: string;
|
|
27
27
|
}
|
|
28
28
|
/** Ring VRF alias info */
|
|
29
29
|
interface AnonymousAliasInfo {
|
|
@@ -119,41 +119,45 @@ declare function reverseDotNs(address: string): Promise<string | null>;
|
|
|
119
119
|
declare function isDotNsAvailable(name: string): Promise<boolean>;
|
|
120
120
|
|
|
121
121
|
/**
|
|
122
|
-
*
|
|
122
|
+
* Context alias derivation
|
|
123
|
+
*
|
|
124
|
+
* Derives a deterministic, context-bound alias from a parent account using blake2b-256.
|
|
123
125
|
*
|
|
124
|
-
*
|
|
126
|
+
* NOTE: this is NOT the canonical sr25519 product-account derivation used by
|
|
127
|
+
* mobile, desktop, and dotli hosts. For that, use
|
|
128
|
+
* `@parity/product-sdk-keys::deriveProductAccountPublicKey`.
|
|
125
129
|
*/
|
|
126
130
|
|
|
127
131
|
/**
|
|
128
|
-
* Derive a
|
|
132
|
+
* Derive a context-bound alias from a parent account.
|
|
129
133
|
*
|
|
130
|
-
* The
|
|
131
|
-
*
|
|
134
|
+
* The alias is deterministically derived using:
|
|
135
|
+
* aliasPublicKey = blake2b256(parentPublicKey || context)
|
|
132
136
|
*
|
|
133
137
|
* @param parentAddress - Parent account SS58 address
|
|
134
|
-
* @param
|
|
138
|
+
* @param context - Context string for derivation (e.g. an app id or scope label)
|
|
135
139
|
* @param ss58Prefix - SS58 prefix (default: 42)
|
|
136
|
-
* @returns
|
|
140
|
+
* @returns Context alias info
|
|
137
141
|
*
|
|
138
142
|
* @example
|
|
139
143
|
* ```ts
|
|
140
|
-
* const
|
|
144
|
+
* const alias = deriveContextAlias(
|
|
141
145
|
* '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY',
|
|
142
|
-
* '
|
|
146
|
+
* 'voting-round-1'
|
|
143
147
|
* );
|
|
144
|
-
* console.log('
|
|
148
|
+
* console.log('Alias address:', alias.address);
|
|
145
149
|
* ```
|
|
146
150
|
*/
|
|
147
|
-
declare function
|
|
151
|
+
declare function deriveContextAlias(parentAddress: string, context: string, ss58Prefix?: number): ContextAliasInfo;
|
|
148
152
|
/**
|
|
149
|
-
* Verify that a
|
|
153
|
+
* Verify that a context alias was derived from a parent account.
|
|
150
154
|
*
|
|
151
|
-
* @param
|
|
155
|
+
* @param aliasAddress - Context alias SS58 address
|
|
152
156
|
* @param parentAddress - Claimed parent address
|
|
153
|
-
* @param
|
|
157
|
+
* @param context - Context string used for derivation
|
|
154
158
|
* @returns True if derivation is valid
|
|
155
159
|
*/
|
|
156
|
-
declare function
|
|
160
|
+
declare function verifyContextAlias(aliasAddress: string, parentAddress: string, context: string): boolean;
|
|
157
161
|
/**
|
|
158
162
|
* Derive an anonymous alias using Ring VRF
|
|
159
163
|
*
|
|
@@ -183,4 +187,4 @@ declare function createRingProof(message: Uint8Array, ringLocation: RingLocation
|
|
|
183
187
|
*/
|
|
184
188
|
declare function verifyRingProof(message: Uint8Array, proof: Uint8Array, alias: string): Promise<boolean>;
|
|
185
189
|
|
|
186
|
-
export { type AnonymousAliasInfo, type
|
|
190
|
+
export { type AnonymousAliasInfo, type ContextAliasInfo, type DotNsRecord, type OnChainIdentity, type RingLocation, type VerificationResult, createRingProof, deriveAnonymousAlias, deriveContextAlias, isDotNsAvailable, isValidDotNsName, normalizeDotNsName, resolveDotNs, reverseDotNs, verifyContextAlias, verifyRingProof };
|
package/dist/identity/index.js
CHANGED
|
@@ -39,35 +39,35 @@ async function isDotNsAvailable(name) {
|
|
|
39
39
|
return record === null;
|
|
40
40
|
}
|
|
41
41
|
var log2 = createLogger("identity");
|
|
42
|
-
function
|
|
42
|
+
function deriveContextAlias(parentAddress, context, ss58Prefix = 42) {
|
|
43
43
|
const { publicKey: parentPublicKey } = ss58Decode(parentAddress);
|
|
44
|
-
const
|
|
45
|
-
const combined = new Uint8Array(parentPublicKey.length +
|
|
44
|
+
const contextBytes = new TextEncoder().encode(context);
|
|
45
|
+
const combined = new Uint8Array(parentPublicKey.length + contextBytes.length);
|
|
46
46
|
combined.set(parentPublicKey, 0);
|
|
47
|
-
combined.set(
|
|
48
|
-
const
|
|
49
|
-
const address = ss58Encode(
|
|
50
|
-
const h160Address = deriveH160(
|
|
51
|
-
log2.debug("Derived
|
|
47
|
+
combined.set(contextBytes, parentPublicKey.length);
|
|
48
|
+
const aliasPublicKey = blake2b256(combined);
|
|
49
|
+
const address = ss58Encode(aliasPublicKey, ss58Prefix);
|
|
50
|
+
const h160Address = deriveH160(aliasPublicKey);
|
|
51
|
+
log2.debug("Derived context alias", {
|
|
52
52
|
parentAddress,
|
|
53
|
-
|
|
53
|
+
context,
|
|
54
54
|
address
|
|
55
55
|
});
|
|
56
56
|
return {
|
|
57
57
|
address,
|
|
58
58
|
h160Address,
|
|
59
59
|
parentAddress,
|
|
60
|
-
|
|
60
|
+
context
|
|
61
61
|
};
|
|
62
62
|
}
|
|
63
|
-
function
|
|
63
|
+
function verifyContextAlias(aliasAddress, parentAddress, context) {
|
|
64
64
|
try {
|
|
65
|
-
const derived =
|
|
66
|
-
const { publicKey:
|
|
65
|
+
const derived = deriveContextAlias(parentAddress, context);
|
|
66
|
+
const { publicKey: aliasKey } = ss58Decode(aliasAddress);
|
|
67
67
|
const { publicKey: derivedKey } = ss58Decode(derived.address);
|
|
68
|
-
if (
|
|
69
|
-
for (let i = 0; i <
|
|
70
|
-
if (
|
|
68
|
+
if (aliasKey.length !== derivedKey.length) return false;
|
|
69
|
+
for (let i = 0; i < aliasKey.length; i++) {
|
|
70
|
+
if (aliasKey[i] !== derivedKey[i]) return false;
|
|
71
71
|
}
|
|
72
72
|
return true;
|
|
73
73
|
} catch {
|
|
@@ -93,6 +93,6 @@ async function verifyRingProof(message, proof, alias) {
|
|
|
93
93
|
);
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
export { createRingProof, deriveAnonymousAlias,
|
|
96
|
+
export { createRingProof, deriveAnonymousAlias, deriveContextAlias, isDotNsAvailable, isValidDotNsName, normalizeDotNsName, resolveDotNs, reverseDotNs, verifyContextAlias, verifyRingProof };
|
|
97
97
|
//# sourceMappingURL=index.js.map
|
|
98
98
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/identity/dotns.ts","../../src/identity/product-account.ts"],"names":["log","createLogger"],"mappings":";;;;;AASA,IAAM,GAAA,GAAM,aAAa,UAAU,CAAA;AAQ5B,SAAS,iBAAiB,IAAA,EAAuB;AAEpD,EAAA,IAAI,CAAC,IAAA,CAAK,QAAA,CAAS,MAAM,GAAG,OAAO,KAAA;AACnC,EAAA,MAAM,KAAA,GAAQ,IAAA,CAAK,KAAA,CAAM,CAAA,EAAG,EAAE,CAAA;AAC9B,EAAA,IAAI,MAAM,MAAA,GAAS,CAAA,IAAK,KAAA,CAAM,MAAA,GAAS,IAAI,OAAO,KAAA;AAClD,EAAA,OAAO,iCAAA,CAAkC,KAAK,KAAK,CAAA;AACvD;AAQO,SAAS,mBAAmB,IAAA,EAAsB;AACrD,EAAA,IAAI,UAAA,GAAa,IAAA,CAAK,WAAA,EAAY,CAAE,IAAA,EAAK;AACzC,EAAA,IAAI,CAAC,UAAA,CAAW,QAAA,CAAS,MAAM,CAAA,EAAG;AAC9B,IAAA,UAAA,IAAc,MAAA;AAAA,EAClB;AACA,EAAA,OAAO,UAAA;AACX;AAgBA,eAAsB,aAAa,IAAA,EAA2C;AAC1E,EAAA,MAAM,UAAA,GAAa,mBAAmB,IAAI,CAAA;AAE1C,EAAA,IAAI,CAAC,gBAAA,CAAiB,UAAU,CAAA,EAAG;AAC/B,IAAA,GAAA,CAAI,IAAA,CAAK,oBAAA,EAAsB,EAAE,IAAA,EAAM,CAAA;AACvC,IAAA,OAAO,IAAA;AAAA,EACX;AAEA,EAAA,GAAA,CAAI,KAAA,CAAM,sBAAA,EAAwB,EAAE,IAAA,EAAM,YAAY,CAAA;AAGtD,EAAA,MAAM,IAAI,KAAA;AAAA,IACN;AAAA,GAEJ;AACJ;AAQA,eAAsB,aAAa,OAAA,EAAyC;AACxE,EAAA,GAAA,CAAI,KAAA,CAAM,2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,GAAU,oBAAA,CAAqB,aAAA,EAAe,WAAW,CAAA;AAC/D,IAAA,MAAM,EAAE,SAAA,EAAW,UAAA,EAAW,GAAI,WAAW,cAAc,CAAA;AAC3D,IAAA,MAAM,EAAE,SAAA,EAAW,UAAA,EAAW,GAAI,UAAA,CAAW,QAAQ,OAAO,CAAA;AAG5D,IAAA,IAAI,UAAA,CAAW,MAAA,KAAW,UAAA,CAAW,MAAA,EAAQ,OAAO,KAAA;AACpD,IAAA,KAAA,IAAS,CAAA,GAAI,CAAA,EAAG,CAAA,GAAI,UAAA,CAAW,QAAQ,CAAA,EAAA,EAAK;AACxC,MAAA,IAAI,WAAW,CAAC,CAAA,KAAM,UAAA,CAAW,CAAC,GAAG,OAAO,KAAA;AAAA,IAChD;AACA,IAAA,OAAO,IAAA;AAAA,EACX,CAAA,CAAA,MAAQ;AACJ,IAAA,OAAO,KAAA;AAAA,EACX;AACJ;AAYO,SAAS,oBAAA,CACZ,SACA,YAAA,EACkB;AAClB,EAAAA,KAAI,KAAA,CAAM,0BAAA,EAA4B,EAAE,OAAA,EAAS,cAAc,CAAA;AAI/D,EAAA,MAAM,IAAI,KAAA;AAAA,IACN;AAAA,GAEJ;AACJ;AASA,eAAsB,eAAA,CAClB,SACA,YAAA,EACmB;AACnB,EAAAA,IAAAA,CAAI,KAAA,CAAM,qBAAA,EAAuB,EAAE,cAAc,CAAA;AAGjD,EAAA,MAAM,IAAI,KAAA;AAAA,IACN;AAAA,GAEJ;AACJ;AAUA,eAAsB,eAAA,CAClB,OAAA,EACA,KAAA,EACA,KAAA,EACgB;AAChB,EAAAA,IAAAA,CAAI,MAAM,sBAAsB,CAAA;AAGhC,EAAA,MAAM,IAAI,KAAA;AAAA,IACN;AAAA,GAEJ;AACJ","file":"index.js","sourcesContent":["/**\n * DotNS (Polkadot Name Service) utilities\n *\n * Provides name resolution for .dot domains\n */\n\nimport { createLogger } from \"@parity/product-sdk-logger\";\nimport type { DotNsRecord } from \"./types.js\";\n\nconst log = createLogger(\"identity\");\n\n/**\n * Check if a string is a valid DotNS name\n *\n * @param name - Name to validate\n * @returns True if valid DotNS name\n */\nexport function isValidDotNsName(name: string): boolean {\n // Basic validation: alphanumeric, hyphens, ends with .dot\n if (!name.endsWith(\".dot\")) return false;\n const label = name.slice(0, -4);\n if (label.length < 3 || label.length > 63) return false;\n return /^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/.test(label);\n}\n\n/**\n * Normalize a DotNS name (lowercase, trim whitespace)\n *\n * @param name - Name to normalize\n * @returns Normalized name\n */\nexport function normalizeDotNsName(name: string): string {\n let normalized = name.toLowerCase().trim();\n if (!normalized.endsWith(\".dot\")) {\n normalized += \".dot\";\n }\n return normalized;\n}\n\n/**\n * Resolve a DotNS name to an address\n *\n * @param name - DotNS name (e.g., \"alice.dot\")\n * @returns Resolved record or null if not found\n *\n * @example\n * ```ts\n * const record = await resolveDotNs('alice.dot');\n * if (record) {\n * console.log('Address:', record.address);\n * }\n * ```\n */\nexport async function resolveDotNs(name: string): Promise<DotNsRecord | null> {\n const normalized = normalizeDotNsName(name);\n\n if (!isValidDotNsName(normalized)) {\n log.warn(\"Invalid DotNS name\", { name });\n return null;\n }\n\n log.debug(\"Resolving DotNS name\", { name: normalized });\n\n // TODO: Implement via PAPI query to DotNS pallet\n throw new Error(\n \"resolveDotNs() is not yet implemented. \" +\n \"This is a skeleton for the Product SDK structure.\",\n );\n}\n\n/**\n * Reverse resolve an address to a DotNS name\n *\n * @param address - SS58 address\n * @returns Primary name or null if none set\n */\nexport async function reverseDotNs(address: string): Promise<string | null> {\n log.debug(\"Reverse resolving address\", { address });\n\n // TODO: Implement via PAPI query to DotNS pallet\n throw new Error(\n \"reverseDotNs() is not yet implemented. \" +\n \"This is a skeleton for the Product SDK structure.\",\n );\n}\n\n/**\n * Check if a DotNS name is available for registration\n *\n * @param name - Name to check\n * @returns True if available\n */\nexport async function isDotNsAvailable(name: string): Promise<boolean> {\n const record = await resolveDotNs(name).catch(() => null);\n return record === null;\n}\n","/**\n * Product account derivation\n *\n * Derives product-scoped accounts from a parent account\n */\n\nimport { createLogger } from \"@parity/product-sdk-logger\";\nimport { blake2b256 } from \"@parity/product-sdk-crypto\";\nimport { ss58Encode, ss58Decode, deriveH160 } from \"@parity/product-sdk-address\";\nimport type { ProductAccountInfo, AnonymousAliasInfo, RingLocation } from \"./types.js\";\n\nconst log = createLogger(\"identity\");\n\n/**\n * Derive a product-scoped account from a parent account\n *\n * The product account is deterministically derived using:\n * productPublicKey = hash(parentPublicKey || productName)\n *\n * @param parentAddress - Parent account SS58 address\n * @param productName - Product name for derivation\n * @param ss58Prefix - SS58 prefix (default: 42)\n * @returns Product account info\n *\n * @example\n * ```ts\n * const productAccount = deriveProductAccount(\n * '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY',\n * 'my-app'\n * );\n * console.log('Product address:', productAccount.address);\n * ```\n */\nexport function deriveProductAccount(\n parentAddress: string,\n productName: string,\n ss58Prefix = 42,\n): ProductAccountInfo {\n const { publicKey: parentPublicKey } = ss58Decode(parentAddress);\n\n // Derive product public key: blake2b-256(parentPublicKey || productName)\n const productNameBytes = new TextEncoder().encode(productName);\n const combined = new Uint8Array(parentPublicKey.length + productNameBytes.length);\n combined.set(parentPublicKey, 0);\n combined.set(productNameBytes, parentPublicKey.length);\n\n const productPublicKey = blake2b256(combined);\n const address = ss58Encode(productPublicKey, ss58Prefix);\n const h160Address = deriveH160(productPublicKey);\n\n log.debug(\"Derived product account\", {\n parentAddress,\n productName,\n address,\n });\n\n return {\n address,\n h160Address,\n parentAddress,\n productName,\n };\n}\n\n/**\n * Verify that a product account was derived from a parent account\n *\n * @param productAddress - Product account address\n * @param parentAddress - Claimed parent address\n * @param productName - Product name\n * @returns True if derivation is valid\n */\nexport function verifyProductAccount(\n productAddress: string,\n parentAddress: string,\n productName: string,\n): boolean {\n try {\n const derived = deriveProductAccount(parentAddress, productName);\n const { publicKey: productKey } = ss58Decode(productAddress);\n const { publicKey: derivedKey } = ss58Decode(derived.address);\n\n // Compare public keys\n if (productKey.length !== derivedKey.length) return false;\n for (let i = 0; i < productKey.length; i++) {\n if (productKey[i] !== derivedKey[i]) return false;\n }\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Derive an anonymous alias using Ring VRF\n *\n * This creates a context-specific alias that cannot be linked\n * back to the original identity without the ring proof.\n *\n * @param context - Context for alias derivation (e.g., \"voting-round-1\")\n * @param ringLocation - Ring location for proof generation\n * @returns Anonymous alias info\n */\nexport function deriveAnonymousAlias(\n context: string,\n ringLocation: RingLocation,\n): AnonymousAliasInfo {\n log.debug(\"Deriving anonymous alias\", { context, ringLocation });\n\n // TODO: Implement Ring VRF alias derivation\n // This requires the Ring VRF implementation from TruAPI\n throw new Error(\n \"deriveAnonymousAlias() is not yet implemented. \" +\n \"This requires container mode with Ring VRF support.\",\n );\n}\n\n/**\n * Create a Ring VRF proof for a message\n *\n * @param message - Message to prove\n * @param ringLocation - Ring location\n * @returns Proof bytes\n */\nexport async function createRingProof(\n message: Uint8Array,\n ringLocation: RingLocation,\n): Promise<Uint8Array> {\n log.debug(\"Creating ring proof\", { ringLocation });\n\n // TODO: Implement Ring VRF proof creation via TruAPI\n throw new Error(\n \"createRingProof() is not yet implemented. \" +\n \"This requires container mode with Ring VRF support.\",\n );\n}\n\n/**\n * Verify a Ring VRF proof\n *\n * @param message - Original message\n * @param proof - Proof bytes\n * @param alias - Expected alias\n * @returns True if proof is valid\n */\nexport async function verifyRingProof(\n message: Uint8Array,\n proof: Uint8Array,\n alias: string,\n): Promise<boolean> {\n log.debug(\"Verifying ring proof\");\n\n // TODO: Implement Ring VRF proof verification\n throw new Error(\n \"verifyRingProof() is not yet implemented. \" +\n \"This requires container mode with Ring VRF support.\",\n );\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/identity/dotns.ts","../../src/identity/product-account.ts"],"names":["log","createLogger"],"mappings":";;;;;AASA,IAAM,GAAA,GAAM,aAAa,UAAU,CAAA;AA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AA;AAG5D,IAAA,IAAI,QAAA,CAAS,MAAA,KAAW,UAAA,CAAW,MAAA,EAAQ,OAAO,KAAA;AAClD,IAAA,KAAA,IAAS,CAAA,GAAI,CAAA,EAAG,CAAA,GAAI,QAAA,CAAS,QAAQ,CAAA,EAAA,EAAK;AACtC,MAAA,IAAI,SAAS,CAAC,CAAA,KAAM,UAAA,CAAW,CAAC,GAAG,OAAO,KAAA;AAAA,IAC9C;AACA,IAAA,OAAO,IAAA;AAAA,EACX,CAAA,CAAA,MAAQ;AACJ,IAAA,OAAO,KAAA;AAAA,EACX;AACJ;AAYO,SAAS,oBAAA,CACZ,SACA,YAAA,EACkB;AAClB,EAAAA,KAAI,KAAA,CAAM,0BAAA,EAA4B,EAAE,OAAA,EAAS,cAAc,CAAA;AAI/D,EAAA,MAAM,IAAI,KAAA;AAAA,IACN;AAAA,GAEJ;AACJ;AASA,eAAsB,eAAA,CAClB,SACA,YAAA,EACmB;AACnB,EAAAA,IAAAA,CAAI,KAAA,CAAM,qBAAA,EAAuB,EAAE,cAAc,CAAA;AAGjD,EAAA,MAAM,IAAI,KAAA;AAAA,IACN;AAAA,GAEJ;AACJ;AAUA,eAAsB,eAAA,CAClB,OAAA,EACA,KAAA,EACA,KAAA,EACgB;AAChB,EAAAA,IAAAA,CAAI,MAAM,sBAAsB,CAAA;AAGhC,EAAA,MAAM,IAAI,KAAA;AAAA,IACN;AAAA,GAEJ;AACJ","file":"index.js","sourcesContent":["/**\n * DotNS (Polkadot Name Service) utilities\n *\n * Provides name resolution for .dot domains\n */\n\nimport { createLogger } from \"@parity/product-sdk-logger\";\nimport type { DotNsRecord } from \"./types.js\";\n\nconst log = createLogger(\"identity\");\n\n/**\n * Check if a string is a valid DotNS name\n *\n * @param name - Name to validate\n * @returns True if valid DotNS name\n */\nexport function isValidDotNsName(name: string): boolean {\n // Basic validation: alphanumeric, hyphens, ends with .dot\n if (!name.endsWith(\".dot\")) return false;\n const label = name.slice(0, -4);\n if (label.length < 3 || label.length > 63) return false;\n return /^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/.test(label);\n}\n\n/**\n * Normalize a DotNS name (lowercase, trim whitespace)\n *\n * @param name - Name to normalize\n * @returns Normalized name\n */\nexport function normalizeDotNsName(name: string): string {\n let normalized = name.toLowerCase().trim();\n if (!normalized.endsWith(\".dot\")) {\n normalized += \".dot\";\n }\n return normalized;\n}\n\n/**\n * Resolve a DotNS name to an address\n *\n * @param name - DotNS name (e.g., \"alice.dot\")\n * @returns Resolved record or null if not found\n *\n * @example\n * ```ts\n * const record = await resolveDotNs('alice.dot');\n * if (record) {\n * console.log('Address:', record.address);\n * }\n * ```\n */\nexport async function resolveDotNs(name: string): Promise<DotNsRecord | null> {\n const normalized = normalizeDotNsName(name);\n\n if (!isValidDotNsName(normalized)) {\n log.warn(\"Invalid DotNS name\", { name });\n return null;\n }\n\n log.debug(\"Resolving DotNS name\", { name: normalized });\n\n // TODO: Implement via PAPI query to DotNS pallet\n throw new Error(\n \"resolveDotNs() is not yet implemented. \" +\n \"This is a skeleton for the Product SDK structure.\",\n );\n}\n\n/**\n * Reverse resolve an address to a DotNS name\n *\n * @param address - SS58 address\n * @returns Primary name or null if none set\n */\nexport async function reverseDotNs(address: string): Promise<string | null> {\n log.debug(\"Reverse resolving address\", { address });\n\n // TODO: Implement via PAPI query to DotNS pallet\n throw new Error(\n \"reverseDotNs() is not yet implemented. \" +\n \"This is a skeleton for the Product SDK structure.\",\n );\n}\n\n/**\n * Check if a DotNS name is available for registration\n *\n * @param name - Name to check\n * @returns True if available\n */\nexport async function isDotNsAvailable(name: string): Promise<boolean> {\n const record = await resolveDotNs(name).catch(() => null);\n return record === null;\n}\n","/**\n * Context alias derivation\n *\n * Derives a deterministic, context-bound alias from a parent account using blake2b-256.\n *\n * NOTE: this is NOT the canonical sr25519 product-account derivation used by\n * mobile, desktop, and dotli hosts. For that, use\n * `@parity/product-sdk-keys::deriveProductAccountPublicKey`.\n */\n\nimport { createLogger } from \"@parity/product-sdk-logger\";\nimport { blake2b256 } from \"@parity/product-sdk-crypto\";\nimport { ss58Encode, ss58Decode, deriveH160 } from \"@parity/product-sdk-address\";\nimport type { ContextAliasInfo, AnonymousAliasInfo, RingLocation } from \"./types.js\";\n\nconst log = createLogger(\"identity\");\n\n/**\n * Derive a context-bound alias from a parent account.\n *\n * The alias is deterministically derived using:\n * aliasPublicKey = blake2b256(parentPublicKey || context)\n *\n * @param parentAddress - Parent account SS58 address\n * @param context - Context string for derivation (e.g. an app id or scope label)\n * @param ss58Prefix - SS58 prefix (default: 42)\n * @returns Context alias info\n *\n * @example\n * ```ts\n * const alias = deriveContextAlias(\n * '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY',\n * 'voting-round-1'\n * );\n * console.log('Alias address:', alias.address);\n * ```\n */\nexport function deriveContextAlias(\n parentAddress: string,\n context: string,\n ss58Prefix = 42,\n): ContextAliasInfo {\n const { publicKey: parentPublicKey } = ss58Decode(parentAddress);\n\n // Derive alias public key: blake2b-256(parentPublicKey || context)\n const contextBytes = new TextEncoder().encode(context);\n const combined = new Uint8Array(parentPublicKey.length + contextBytes.length);\n combined.set(parentPublicKey, 0);\n combined.set(contextBytes, parentPublicKey.length);\n\n const aliasPublicKey = blake2b256(combined);\n const address = ss58Encode(aliasPublicKey, ss58Prefix);\n const h160Address = deriveH160(aliasPublicKey);\n\n log.debug(\"Derived context alias\", {\n parentAddress,\n context,\n address,\n });\n\n return {\n address,\n h160Address,\n parentAddress,\n context,\n };\n}\n\n/**\n * Verify that a context alias was derived from a parent account.\n *\n * @param aliasAddress - Context alias SS58 address\n * @param parentAddress - Claimed parent address\n * @param context - Context string used for derivation\n * @returns True if derivation is valid\n */\nexport function verifyContextAlias(\n aliasAddress: string,\n parentAddress: string,\n context: string,\n): boolean {\n try {\n const derived = deriveContextAlias(parentAddress, context);\n const { publicKey: aliasKey } = ss58Decode(aliasAddress);\n const { publicKey: derivedKey } = ss58Decode(derived.address);\n\n // Compare public keys\n if (aliasKey.length !== derivedKey.length) return false;\n for (let i = 0; i < aliasKey.length; i++) {\n if (aliasKey[i] !== derivedKey[i]) return false;\n }\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Derive an anonymous alias using Ring VRF\n *\n * This creates a context-specific alias that cannot be linked\n * back to the original identity without the ring proof.\n *\n * @param context - Context for alias derivation (e.g., \"voting-round-1\")\n * @param ringLocation - Ring location for proof generation\n * @returns Anonymous alias info\n */\nexport function deriveAnonymousAlias(\n context: string,\n ringLocation: RingLocation,\n): AnonymousAliasInfo {\n log.debug(\"Deriving anonymous alias\", { context, ringLocation });\n\n // TODO: Implement Ring VRF alias derivation\n // This requires the Ring VRF implementation from TruAPI\n throw new Error(\n \"deriveAnonymousAlias() is not yet implemented. \" +\n \"This requires container mode with Ring VRF support.\",\n );\n}\n\n/**\n * Create a Ring VRF proof for a message\n *\n * @param message - Message to prove\n * @param ringLocation - Ring location\n * @returns Proof bytes\n */\nexport async function createRingProof(\n message: Uint8Array,\n ringLocation: RingLocation,\n): Promise<Uint8Array> {\n log.debug(\"Creating ring proof\", { ringLocation });\n\n // TODO: Implement Ring VRF proof creation via TruAPI\n throw new Error(\n \"createRingProof() is not yet implemented. \" +\n \"This requires container mode with Ring VRF support.\",\n );\n}\n\n/**\n * Verify a Ring VRF proof\n *\n * @param message - Original message\n * @param proof - Proof bytes\n * @param alias - Expected alias\n * @returns True if proof is valid\n */\nexport async function verifyRingProof(\n message: Uint8Array,\n proof: Uint8Array,\n alias: string,\n): Promise<boolean> {\n log.debug(\"Verifying ring proof\");\n\n // TODO: Implement Ring VRF proof verification\n throw new Error(\n \"verifyRingProof() is not yet implemented. \" +\n \"This requires container mode with Ring VRF support.\",\n );\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
export { LogEntry, LogHandler, LogLevel, Logger, LoggerConfig, configure, createLogger } from '@parity/product-sdk-logger';
|
|
2
|
-
import { b as AppConfig, A as App } from './types-
|
|
3
|
-
export { a as Account,
|
|
2
|
+
import { b as AppConfig, A as App } from './types-AjDV1BTd.js';
|
|
3
|
+
export { a as Account, C as ChainApi, c as CloudStorageApi, L as LocalStorageApi, W as WalletApi } from './types-AjDV1BTd.js';
|
|
4
4
|
export { isInsideContainer, isInsideContainerSync } from '@parity/product-sdk-host';
|
|
5
5
|
export { ChainClient, createChainClient } from '@parity/product-sdk-chain-client';
|
|
6
6
|
export { SignerManager } from '@parity/product-sdk-signer';
|
|
7
|
-
export {
|
|
8
|
-
export {
|
|
7
|
+
export { createLocalKvStore } from '@parity/product-sdk-local-storage';
|
|
8
|
+
export { CloudStorageClient, calculateCid } from '@parity/product-sdk-cloud-storage';
|
|
9
9
|
export { ChainDefinition, PolkadotClient, TypedApi } from 'polkadot-api';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* createApp - Main entry point for the Product SDK
|
|
13
13
|
*
|
|
14
|
-
* Creates an App instance with wallet, storage, chain, and
|
|
14
|
+
* Creates an App instance with wallet, storage, chain, and cloud storage APIs.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
/**
|
|
@@ -24,33 +24,33 @@ export { ChainDefinition, PolkadotClient, TypedApi } from 'polkadot-api';
|
|
|
24
24
|
* ```ts
|
|
25
25
|
* import { createApp } from '@parity/product-sdk';
|
|
26
26
|
*
|
|
27
|
-
* // Default:
|
|
27
|
+
* // Default: cloud storage enabled with paseo environment
|
|
28
28
|
* const app = await createApp({
|
|
29
29
|
* name: 'my-app',
|
|
30
30
|
* logLevel: 'info',
|
|
31
31
|
* });
|
|
32
32
|
*
|
|
33
|
-
* // Custom
|
|
33
|
+
* // Custom cloud storage environment
|
|
34
34
|
* const prodApp = await createApp({
|
|
35
35
|
* name: 'my-app',
|
|
36
|
-
*
|
|
36
|
+
* cloudStorage: { environment: 'polkadot' },
|
|
37
37
|
* });
|
|
38
38
|
*
|
|
39
|
-
* // Disable
|
|
40
|
-
* const
|
|
39
|
+
* // Disable cloud storage entirely
|
|
40
|
+
* const noCloudStorageApp = await createApp({
|
|
41
41
|
* name: 'my-app',
|
|
42
|
-
*
|
|
42
|
+
* cloudStorage: false,
|
|
43
43
|
* });
|
|
44
44
|
*
|
|
45
45
|
* // Connect wallet
|
|
46
46
|
* const { accounts } = await app.wallet.connect();
|
|
47
47
|
*
|
|
48
48
|
* // Use storage
|
|
49
|
-
* await app.
|
|
49
|
+
* await app.localStorage.set('key', 'value');
|
|
50
50
|
*
|
|
51
|
-
* // Use
|
|
52
|
-
* if (app.
|
|
53
|
-
* const cid = await app.
|
|
51
|
+
* // Use cloud storage (check for null if it might be disabled)
|
|
52
|
+
* if (app.cloudStorage) {
|
|
53
|
+
* const cid = await app.cloudStorage.upload('hello world');
|
|
54
54
|
* }
|
|
55
55
|
* ```
|
|
56
56
|
*/
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export { configure, createLogger } from './chunk-XSKBA5SR.js';
|
|
2
|
-
export { createApp } from './chunk-
|
|
2
|
+
export { createApp } from './chunk-4U2FP26I.js';
|
|
3
3
|
export { isInsideContainer, isInsideContainerSync } from '@parity/product-sdk-host';
|
|
4
4
|
export { createChainClient } from '@parity/product-sdk-chain-client';
|
|
5
5
|
export { SignerManager } from '@parity/product-sdk-signer';
|
|
6
|
-
export {
|
|
7
|
-
export {
|
|
6
|
+
export { createLocalKvStore } from '@parity/product-sdk-local-storage';
|
|
7
|
+
export { CloudStorageClient, calculateCid } from '@parity/product-sdk-cloud-storage';
|
|
8
8
|
//# sourceMappingURL=index.js.map
|
|
9
9
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@parity/product-sdk-local-storage';
|
package/dist/react/index.d.ts
CHANGED
|
@@ -2,9 +2,9 @@ import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
|
2
2
|
import * as react from 'react';
|
|
3
3
|
import { ReactNode } from 'react';
|
|
4
4
|
import { LogLevel } from '@parity/product-sdk-logger';
|
|
5
|
-
import { A as App, a as Account } from '../types-
|
|
5
|
+
import { A as App, a as Account } from '../types-AjDV1BTd.js';
|
|
6
6
|
import { ChainDefinition, TypedApi } from 'polkadot-api';
|
|
7
|
-
import '@parity/product-sdk-
|
|
7
|
+
import '@parity/product-sdk-cloud-storage';
|
|
8
8
|
import '@parity/product-sdk-chain-client';
|
|
9
9
|
|
|
10
10
|
/** Props for ProductSDKProvider */
|
|
@@ -47,7 +47,7 @@ declare const ProductSDKContext: react.Context<App | null>;
|
|
|
47
47
|
* ```tsx
|
|
48
48
|
* function MyComponent() {
|
|
49
49
|
* const app = useProductSDK();
|
|
50
|
-
* // Use app.wallet, app.
|
|
50
|
+
* // Use app.wallet, app.localStorage, etc.
|
|
51
51
|
* }
|
|
52
52
|
* ```
|
|
53
53
|
*/
|
|
@@ -113,7 +113,7 @@ type UseWalletReturn = UseWalletState & UseWalletActions;
|
|
|
113
113
|
declare function useWallet(): UseWalletReturn;
|
|
114
114
|
|
|
115
115
|
/**
|
|
116
|
-
*
|
|
116
|
+
* useLocalStorage hook
|
|
117
117
|
*/
|
|
118
118
|
/**
|
|
119
119
|
* Hook for key-value storage operations
|
|
@@ -124,7 +124,7 @@ declare function useWallet(): UseWalletReturn;
|
|
|
124
124
|
* @example
|
|
125
125
|
* ```tsx
|
|
126
126
|
* function ThemeToggle() {
|
|
127
|
-
* const [theme, setTheme, { loading }] =
|
|
127
|
+
* const [theme, setTheme, { loading }] = useLocalStorage('theme', 'light');
|
|
128
128
|
*
|
|
129
129
|
* if (loading) return <div>Loading...</div>;
|
|
130
130
|
*
|
|
@@ -136,7 +136,7 @@ declare function useWallet(): UseWalletReturn;
|
|
|
136
136
|
* }
|
|
137
137
|
* ```
|
|
138
138
|
*/
|
|
139
|
-
declare function
|
|
139
|
+
declare function useLocalStorage<T = string>(key: string, defaultValue?: T): [T | null, (value: T) => Promise<void>, {
|
|
140
140
|
loading: boolean;
|
|
141
141
|
error: Error | null;
|
|
142
142
|
}];
|
|
@@ -146,7 +146,7 @@ declare function useStorage<T = string>(key: string, defaultValue?: T): [T | nul
|
|
|
146
146
|
* @param key - Storage key
|
|
147
147
|
* @param defaultValue - Default value
|
|
148
148
|
*/
|
|
149
|
-
declare function
|
|
149
|
+
declare function useLocalStorageString(key: string, defaultValue?: string): [string | null, (value: string) => Promise<void>, {
|
|
150
150
|
loading: boolean;
|
|
151
151
|
}];
|
|
152
152
|
|
|
@@ -174,4 +174,4 @@ declare function useStorageString(key: string, defaultValue?: string): [string |
|
|
|
174
174
|
*/
|
|
175
175
|
declare function useChain<T extends ChainDefinition>(chain: T): TypedApi<T>;
|
|
176
176
|
|
|
177
|
-
export { ProductSDKContext, ProductSDKProvider, type ProductSDKProviderProps, type UseWalletActions, type UseWalletReturn, type UseWalletState, useChain,
|
|
177
|
+
export { ProductSDKContext, ProductSDKProvider, type ProductSDKProviderProps, type UseWalletActions, type UseWalletReturn, type UseWalletState, useChain, useLocalStorage, useLocalStorageString, useProductSDK, useWallet };
|
package/dist/react/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createApp } from '../chunk-
|
|
1
|
+
import { createApp } from '../chunk-4U2FP26I.js';
|
|
2
2
|
import { createContext, useContext, useState, useEffect, useCallback, useMemo } from 'react';
|
|
3
3
|
import { jsx, Fragment } from 'react/jsx-runtime';
|
|
4
4
|
|
|
@@ -109,7 +109,7 @@ function useWallet() {
|
|
|
109
109
|
signMessage
|
|
110
110
|
};
|
|
111
111
|
}
|
|
112
|
-
function
|
|
112
|
+
function useLocalStorage(key, defaultValue) {
|
|
113
113
|
const app = useProductSDK();
|
|
114
114
|
const [value, setValue] = useState(null);
|
|
115
115
|
const [loading, setLoading] = useState(true);
|
|
@@ -119,7 +119,7 @@ function useStorage(key, defaultValue) {
|
|
|
119
119
|
const loadValue = async () => {
|
|
120
120
|
try {
|
|
121
121
|
setLoading(true);
|
|
122
|
-
const stored = await app.
|
|
122
|
+
const stored = await app.localStorage.getJSON(key);
|
|
123
123
|
if (mounted) {
|
|
124
124
|
setValue(stored ?? defaultValue ?? null);
|
|
125
125
|
setLoading(false);
|
|
@@ -140,7 +140,7 @@ function useStorage(key, defaultValue) {
|
|
|
140
140
|
async (newValue) => {
|
|
141
141
|
try {
|
|
142
142
|
setError(null);
|
|
143
|
-
await app.
|
|
143
|
+
await app.localStorage.setJSON(key, newValue);
|
|
144
144
|
setValue(newValue);
|
|
145
145
|
} catch (e) {
|
|
146
146
|
setError(e instanceof Error ? e : new Error(String(e)));
|
|
@@ -151,14 +151,14 @@ function useStorage(key, defaultValue) {
|
|
|
151
151
|
);
|
|
152
152
|
return [value, setStoredValue, { loading, error }];
|
|
153
153
|
}
|
|
154
|
-
function
|
|
154
|
+
function useLocalStorageString(key, defaultValue) {
|
|
155
155
|
const app = useProductSDK();
|
|
156
156
|
const [value, setValue] = useState(null);
|
|
157
157
|
const [loading, setLoading] = useState(true);
|
|
158
158
|
useEffect(() => {
|
|
159
159
|
let mounted = true;
|
|
160
160
|
const loadValue = async () => {
|
|
161
|
-
const stored = await app.
|
|
161
|
+
const stored = await app.localStorage.get(key);
|
|
162
162
|
if (mounted) {
|
|
163
163
|
setValue(stored ?? defaultValue ?? null);
|
|
164
164
|
setLoading(false);
|
|
@@ -171,7 +171,7 @@ function useStorageString(key, defaultValue) {
|
|
|
171
171
|
}, [app, key, defaultValue]);
|
|
172
172
|
const setStoredValue = useCallback(
|
|
173
173
|
async (newValue) => {
|
|
174
|
-
await app.
|
|
174
|
+
await app.localStorage.set(key, newValue);
|
|
175
175
|
setValue(newValue);
|
|
176
176
|
},
|
|
177
177
|
[app, key]
|
|
@@ -185,6 +185,6 @@ function useChain(chain) {
|
|
|
185
185
|
}, [app, chain]);
|
|
186
186
|
}
|
|
187
187
|
|
|
188
|
-
export { ProductSDKContext, ProductSDKProvider, useChain,
|
|
188
|
+
export { ProductSDKContext, ProductSDKProvider, useChain, useLocalStorage, useLocalStorageString, useProductSDK, useWallet };
|
|
189
189
|
//# sourceMappingURL=index.js.map
|
|
190
190
|
//# sourceMappingURL=index.js.map
|