@parity/product-sdk 0.1.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/LICENSE +201 -0
- package/dist/address/index.d.ts +8 -0
- package/dist/address/index.js +3 -0
- package/dist/address/index.js.map +1 -0
- package/dist/bulletin/index.d.ts +1 -0
- package/dist/bulletin/index.js +3 -0
- package/dist/bulletin/index.js.map +1 -0
- package/dist/chain/index.d.ts +1 -0
- package/dist/chain/index.js +3 -0
- package/dist/chain/index.js.map +1 -0
- package/dist/chunk-NVGSGXGH.js +177 -0
- package/dist/chunk-NVGSGXGH.js.map +1 -0
- package/dist/chunk-XSKBA5SR.js +8 -0
- package/dist/chunk-XSKBA5SR.js.map +1 -0
- package/dist/contracts/index.d.ts +1 -0
- package/dist/contracts/index.js +3 -0
- package/dist/contracts/index.js.map +1 -0
- package/dist/core/index.d.ts +9 -0
- package/dist/core/index.js +13 -0
- package/dist/core/index.js.map +1 -0
- package/dist/crypto/index.d.ts +1 -0
- package/dist/crypto/index.js +3 -0
- package/dist/crypto/index.js.map +1 -0
- package/dist/host/index.d.ts +1 -0
- package/dist/host/index.js +3 -0
- package/dist/host/index.js.map +1 -0
- package/dist/identity/index.d.ts +186 -0
- package/dist/identity/index.js +109 -0
- package/dist/identity/index.js.map +1 -0
- package/dist/index.d.ts +59 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/dist/react/index.d.ts +177 -0
- package/dist/react/index.js +213 -0
- package/dist/react/index.js.map +1 -0
- package/dist/storage/index.d.ts +1 -0
- package/dist/storage/index.js +3 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/types-CZQDzQ53.d.ts +142 -0
- package/dist/wallet/index.d.ts +1 -0
- package/dist/wallet/index.js +3 -0
- package/dist/wallet/index.js.map +1 -0
- package/package.json +105 -0
- package/src/address/index.ts +6 -0
- package/src/bulletin/index.ts +6 -0
- package/src/chain/index.ts +6 -0
- package/src/contracts/index.ts +6 -0
- package/src/core/createApp.ts +284 -0
- package/src/core/index.ts +10 -0
- package/src/core/logger.ts +13 -0
- package/src/core/types.ts +155 -0
- package/src/crypto/index.ts +6 -0
- package/src/host/index.ts +6 -0
- package/src/identity/dotns.ts +96 -0
- package/src/identity/index.ts +34 -0
- package/src/identity/product-account.ts +158 -0
- package/src/identity/types.ts +75 -0
- package/src/index.ts +49 -0
- package/src/react/context.ts +33 -0
- package/src/react/index.ts +41 -0
- package/src/react/provider.tsx +76 -0
- package/src/react/useChain.ts +33 -0
- package/src/react/useStorage.ts +125 -0
- package/src/react/useWallet.ts +138 -0
- package/src/storage/index.ts +6 -0
- package/src/wallet/index.ts +9 -0
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Identity module types
|
|
3
|
+
*
|
|
4
|
+
* Types for DotNS name resolution and product account derivation
|
|
5
|
+
*/
|
|
6
|
+
/** DotNS name resolution result */
|
|
7
|
+
interface DotNsRecord {
|
|
8
|
+
/** Resolved SS58 address */
|
|
9
|
+
address: string;
|
|
10
|
+
/** Name that was resolved */
|
|
11
|
+
name: string;
|
|
12
|
+
/** Owner address */
|
|
13
|
+
owner: string;
|
|
14
|
+
/** Expiration timestamp (if applicable) */
|
|
15
|
+
expiresAt?: number;
|
|
16
|
+
}
|
|
17
|
+
/** Product account info */
|
|
18
|
+
interface ProductAccountInfo {
|
|
19
|
+
/** Product-scoped SS58 address */
|
|
20
|
+
address: string;
|
|
21
|
+
/** H160 EVM address */
|
|
22
|
+
h160Address: `0x${string}`;
|
|
23
|
+
/** Parent account address */
|
|
24
|
+
parentAddress: string;
|
|
25
|
+
/** Product name used for derivation */
|
|
26
|
+
productName: string;
|
|
27
|
+
}
|
|
28
|
+
/** Ring VRF alias info */
|
|
29
|
+
interface AnonymousAliasInfo {
|
|
30
|
+
/** Anonymous alias identifier */
|
|
31
|
+
alias: string;
|
|
32
|
+
/** Ring location for proof generation */
|
|
33
|
+
ringLocation: RingLocation;
|
|
34
|
+
/** Context used for alias derivation */
|
|
35
|
+
context: string;
|
|
36
|
+
}
|
|
37
|
+
/** Ring location for VRF proofs */
|
|
38
|
+
interface RingLocation {
|
|
39
|
+
/** Ring index */
|
|
40
|
+
ringIndex: number;
|
|
41
|
+
/** Member index within ring */
|
|
42
|
+
memberIndex: number;
|
|
43
|
+
}
|
|
44
|
+
/** Identity verification result */
|
|
45
|
+
interface VerificationResult {
|
|
46
|
+
/** Whether identity is verified */
|
|
47
|
+
verified: boolean;
|
|
48
|
+
/** Verification method used */
|
|
49
|
+
method: "on-chain" | "judgement" | "social";
|
|
50
|
+
/** Verification details */
|
|
51
|
+
details?: Record<string, unknown>;
|
|
52
|
+
}
|
|
53
|
+
/** On-chain identity info */
|
|
54
|
+
interface OnChainIdentity {
|
|
55
|
+
/** Display name */
|
|
56
|
+
display?: string;
|
|
57
|
+
/** Legal name */
|
|
58
|
+
legal?: string;
|
|
59
|
+
/** Web URL */
|
|
60
|
+
web?: string;
|
|
61
|
+
/** Email */
|
|
62
|
+
email?: string;
|
|
63
|
+
/** Twitter handle */
|
|
64
|
+
twitter?: string;
|
|
65
|
+
/** Riot/Matrix handle */
|
|
66
|
+
riot?: string;
|
|
67
|
+
/** Additional fields */
|
|
68
|
+
additional: Array<[string, string]>;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* DotNS (Polkadot Name Service) utilities
|
|
73
|
+
*
|
|
74
|
+
* Provides name resolution for .dot domains
|
|
75
|
+
*/
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Check if a string is a valid DotNS name
|
|
79
|
+
*
|
|
80
|
+
* @param name - Name to validate
|
|
81
|
+
* @returns True if valid DotNS name
|
|
82
|
+
*/
|
|
83
|
+
declare function isValidDotNsName(name: string): boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Normalize a DotNS name (lowercase, trim whitespace)
|
|
86
|
+
*
|
|
87
|
+
* @param name - Name to normalize
|
|
88
|
+
* @returns Normalized name
|
|
89
|
+
*/
|
|
90
|
+
declare function normalizeDotNsName(name: string): string;
|
|
91
|
+
/**
|
|
92
|
+
* Resolve a DotNS name to an address
|
|
93
|
+
*
|
|
94
|
+
* @param name - DotNS name (e.g., "alice.dot")
|
|
95
|
+
* @returns Resolved record or null if not found
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```ts
|
|
99
|
+
* const record = await resolveDotNs('alice.dot');
|
|
100
|
+
* if (record) {
|
|
101
|
+
* console.log('Address:', record.address);
|
|
102
|
+
* }
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
declare function resolveDotNs(name: string): Promise<DotNsRecord | null>;
|
|
106
|
+
/**
|
|
107
|
+
* Reverse resolve an address to a DotNS name
|
|
108
|
+
*
|
|
109
|
+
* @param address - SS58 address
|
|
110
|
+
* @returns Primary name or null if none set
|
|
111
|
+
*/
|
|
112
|
+
declare function reverseDotNs(address: string): Promise<string | null>;
|
|
113
|
+
/**
|
|
114
|
+
* Check if a DotNS name is available for registration
|
|
115
|
+
*
|
|
116
|
+
* @param name - Name to check
|
|
117
|
+
* @returns True if available
|
|
118
|
+
*/
|
|
119
|
+
declare function isDotNsAvailable(name: string): Promise<boolean>;
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Product account derivation
|
|
123
|
+
*
|
|
124
|
+
* Derives product-scoped accounts from a parent account
|
|
125
|
+
*/
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Derive a product-scoped account from a parent account
|
|
129
|
+
*
|
|
130
|
+
* The product account is deterministically derived using:
|
|
131
|
+
* productPublicKey = hash(parentPublicKey || productName)
|
|
132
|
+
*
|
|
133
|
+
* @param parentAddress - Parent account SS58 address
|
|
134
|
+
* @param productName - Product name for derivation
|
|
135
|
+
* @param ss58Prefix - SS58 prefix (default: 42)
|
|
136
|
+
* @returns Product account info
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* ```ts
|
|
140
|
+
* const productAccount = deriveProductAccount(
|
|
141
|
+
* '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY',
|
|
142
|
+
* 'my-app'
|
|
143
|
+
* );
|
|
144
|
+
* console.log('Product address:', productAccount.address);
|
|
145
|
+
* ```
|
|
146
|
+
*/
|
|
147
|
+
declare function deriveProductAccount(parentAddress: string, productName: string, ss58Prefix?: number): ProductAccountInfo;
|
|
148
|
+
/**
|
|
149
|
+
* Verify that a product account was derived from a parent account
|
|
150
|
+
*
|
|
151
|
+
* @param productAddress - Product account address
|
|
152
|
+
* @param parentAddress - Claimed parent address
|
|
153
|
+
* @param productName - Product name
|
|
154
|
+
* @returns True if derivation is valid
|
|
155
|
+
*/
|
|
156
|
+
declare function verifyProductAccount(productAddress: string, parentAddress: string, productName: string): boolean;
|
|
157
|
+
/**
|
|
158
|
+
* Derive an anonymous alias using Ring VRF
|
|
159
|
+
*
|
|
160
|
+
* This creates a context-specific alias that cannot be linked
|
|
161
|
+
* back to the original identity without the ring proof.
|
|
162
|
+
*
|
|
163
|
+
* @param context - Context for alias derivation (e.g., "voting-round-1")
|
|
164
|
+
* @param ringLocation - Ring location for proof generation
|
|
165
|
+
* @returns Anonymous alias info
|
|
166
|
+
*/
|
|
167
|
+
declare function deriveAnonymousAlias(context: string, ringLocation: RingLocation): AnonymousAliasInfo;
|
|
168
|
+
/**
|
|
169
|
+
* Create a Ring VRF proof for a message
|
|
170
|
+
*
|
|
171
|
+
* @param message - Message to prove
|
|
172
|
+
* @param ringLocation - Ring location
|
|
173
|
+
* @returns Proof bytes
|
|
174
|
+
*/
|
|
175
|
+
declare function createRingProof(message: Uint8Array, ringLocation: RingLocation): Promise<Uint8Array>;
|
|
176
|
+
/**
|
|
177
|
+
* Verify a Ring VRF proof
|
|
178
|
+
*
|
|
179
|
+
* @param message - Original message
|
|
180
|
+
* @param proof - Proof bytes
|
|
181
|
+
* @param alias - Expected alias
|
|
182
|
+
* @returns True if proof is valid
|
|
183
|
+
*/
|
|
184
|
+
declare function verifyRingProof(message: Uint8Array, proof: Uint8Array, alias: string): Promise<boolean>;
|
|
185
|
+
|
|
186
|
+
export { type AnonymousAliasInfo, type DotNsRecord, type OnChainIdentity, type ProductAccountInfo, type RingLocation, type VerificationResult, createRingProof, deriveAnonymousAlias, deriveProductAccount, isDotNsAvailable, isValidDotNsName, normalizeDotNsName, resolveDotNs, reverseDotNs, verifyProductAccount, verifyRingProof };
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// src/identity/dotns.ts
|
|
2
|
+
import { createLogger } from "@parity/product-sdk-logger";
|
|
3
|
+
var log = createLogger("identity");
|
|
4
|
+
function isValidDotNsName(name) {
|
|
5
|
+
if (!name.endsWith(".dot")) return false;
|
|
6
|
+
const label = name.slice(0, -4);
|
|
7
|
+
if (label.length < 3 || label.length > 63) return false;
|
|
8
|
+
return /^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/.test(label);
|
|
9
|
+
}
|
|
10
|
+
function normalizeDotNsName(name) {
|
|
11
|
+
let normalized = name.toLowerCase().trim();
|
|
12
|
+
if (!normalized.endsWith(".dot")) {
|
|
13
|
+
normalized += ".dot";
|
|
14
|
+
}
|
|
15
|
+
return normalized;
|
|
16
|
+
}
|
|
17
|
+
async function resolveDotNs(name) {
|
|
18
|
+
const normalized = normalizeDotNsName(name);
|
|
19
|
+
if (!isValidDotNsName(normalized)) {
|
|
20
|
+
log.warn("Invalid DotNS name", { name });
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
log.debug("Resolving DotNS name", { name: normalized });
|
|
24
|
+
throw new Error(
|
|
25
|
+
"resolveDotNs() is not yet implemented. This is a skeleton for the Product SDK structure."
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
async function reverseDotNs(address) {
|
|
29
|
+
log.debug("Reverse resolving address", { address });
|
|
30
|
+
throw new Error(
|
|
31
|
+
"reverseDotNs() is not yet implemented. This is a skeleton for the Product SDK structure."
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
async function isDotNsAvailable(name) {
|
|
35
|
+
const record = await resolveDotNs(name).catch(() => null);
|
|
36
|
+
return record === null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// src/identity/product-account.ts
|
|
40
|
+
import { createLogger as createLogger2 } from "@parity/product-sdk-logger";
|
|
41
|
+
import { blake2b256 } from "@parity/product-sdk-crypto";
|
|
42
|
+
import { ss58Encode, ss58Decode, deriveH160 } from "@parity/product-sdk-address";
|
|
43
|
+
var log2 = createLogger2("identity");
|
|
44
|
+
function deriveProductAccount(parentAddress, productName, ss58Prefix = 42) {
|
|
45
|
+
const { publicKey: parentPublicKey } = ss58Decode(parentAddress);
|
|
46
|
+
const productNameBytes = new TextEncoder().encode(productName);
|
|
47
|
+
const combined = new Uint8Array(parentPublicKey.length + productNameBytes.length);
|
|
48
|
+
combined.set(parentPublicKey, 0);
|
|
49
|
+
combined.set(productNameBytes, parentPublicKey.length);
|
|
50
|
+
const productPublicKey = blake2b256(combined);
|
|
51
|
+
const address = ss58Encode(productPublicKey, ss58Prefix);
|
|
52
|
+
const h160Address = deriveH160(productPublicKey);
|
|
53
|
+
log2.debug("Derived product account", {
|
|
54
|
+
parentAddress,
|
|
55
|
+
productName,
|
|
56
|
+
address
|
|
57
|
+
});
|
|
58
|
+
return {
|
|
59
|
+
address,
|
|
60
|
+
h160Address,
|
|
61
|
+
parentAddress,
|
|
62
|
+
productName
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
function verifyProductAccount(productAddress, parentAddress, productName) {
|
|
66
|
+
try {
|
|
67
|
+
const derived = deriveProductAccount(parentAddress, productName);
|
|
68
|
+
const { publicKey: productKey } = ss58Decode(productAddress);
|
|
69
|
+
const { publicKey: derivedKey } = ss58Decode(derived.address);
|
|
70
|
+
if (productKey.length !== derivedKey.length) return false;
|
|
71
|
+
for (let i = 0; i < productKey.length; i++) {
|
|
72
|
+
if (productKey[i] !== derivedKey[i]) return false;
|
|
73
|
+
}
|
|
74
|
+
return true;
|
|
75
|
+
} catch {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function deriveAnonymousAlias(context, ringLocation) {
|
|
80
|
+
log2.debug("Deriving anonymous alias", { context, ringLocation });
|
|
81
|
+
throw new Error(
|
|
82
|
+
"deriveAnonymousAlias() is not yet implemented. This requires container mode with Ring VRF support."
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
async function createRingProof(message, ringLocation) {
|
|
86
|
+
log2.debug("Creating ring proof", { ringLocation });
|
|
87
|
+
throw new Error(
|
|
88
|
+
"createRingProof() is not yet implemented. This requires container mode with Ring VRF support."
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
async function verifyRingProof(message, proof, alias) {
|
|
92
|
+
log2.debug("Verifying ring proof");
|
|
93
|
+
throw new Error(
|
|
94
|
+
"verifyRingProof() is not yet implemented. This requires container mode with Ring VRF support."
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
export {
|
|
98
|
+
createRingProof,
|
|
99
|
+
deriveAnonymousAlias,
|
|
100
|
+
deriveProductAccount,
|
|
101
|
+
isDotNsAvailable,
|
|
102
|
+
isValidDotNsName,
|
|
103
|
+
normalizeDotNsName,
|
|
104
|
+
resolveDotNs,
|
|
105
|
+
reverseDotNs,
|
|
106
|
+
verifyProductAccount,
|
|
107
|
+
verifyRingProof
|
|
108
|
+
};
|
|
109
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/identity/dotns.ts","../../src/identity/product-account.ts"],"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"],"mappings":"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","names":["createLogger","log"]}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
export { LogEntry, LogHandler, LogLevel, Logger, LoggerConfig, configure, createLogger } from '@parity/product-sdk-logger';
|
|
2
|
+
import { b as AppConfig, A as App } from './types-CZQDzQ53.js';
|
|
3
|
+
export { a as Account, B as BulletinApi, C as ChainApi, S as StorageApi, W as WalletApi } from './types-CZQDzQ53.js';
|
|
4
|
+
export { isInsideContainer, isInsideContainerSync } from '@parity/product-sdk-host';
|
|
5
|
+
export { ChainClient, createChainClient } from '@parity/product-sdk-chain-client';
|
|
6
|
+
export { SignerManager } from '@parity/product-sdk-signer';
|
|
7
|
+
export { createKvStore } from '@parity/product-sdk-storage';
|
|
8
|
+
export { BulletinClient, computeCid } from '@parity/product-sdk-bulletin';
|
|
9
|
+
export { ChainDefinition, PolkadotClient, TypedApi } from 'polkadot-api';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* createApp - Main entry point for the Product SDK
|
|
13
|
+
*
|
|
14
|
+
* Creates an App instance with wallet, storage, chain, and bulletin APIs.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Create a new Product SDK app instance
|
|
19
|
+
*
|
|
20
|
+
* @param config - Application configuration
|
|
21
|
+
* @returns App instance with all APIs
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* import { createApp } from '@parity/product-sdk';
|
|
26
|
+
*
|
|
27
|
+
* // Default: bulletin enabled with paseo environment
|
|
28
|
+
* const app = await createApp({
|
|
29
|
+
* name: 'my-app',
|
|
30
|
+
* logLevel: 'info',
|
|
31
|
+
* });
|
|
32
|
+
*
|
|
33
|
+
* // Custom bulletin environment
|
|
34
|
+
* const prodApp = await createApp({
|
|
35
|
+
* name: 'my-app',
|
|
36
|
+
* bulletin: { environment: 'polkadot' },
|
|
37
|
+
* });
|
|
38
|
+
*
|
|
39
|
+
* // Disable bulletin entirely
|
|
40
|
+
* const noBulletinApp = await createApp({
|
|
41
|
+
* name: 'my-app',
|
|
42
|
+
* bulletin: false,
|
|
43
|
+
* });
|
|
44
|
+
*
|
|
45
|
+
* // Connect wallet
|
|
46
|
+
* const { accounts } = await app.wallet.connect();
|
|
47
|
+
*
|
|
48
|
+
* // Use storage
|
|
49
|
+
* await app.storage.set('key', 'value');
|
|
50
|
+
*
|
|
51
|
+
* // Use bulletin (check for null if it might be disabled)
|
|
52
|
+
* if (app.bulletin) {
|
|
53
|
+
* const cid = await app.bulletin.upload('hello world');
|
|
54
|
+
* }
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
declare function createApp(config: AppConfig): Promise<App>;
|
|
58
|
+
|
|
59
|
+
export { App, AppConfig, createApp };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import {
|
|
2
|
+
configure,
|
|
3
|
+
createLogger
|
|
4
|
+
} from "./chunk-XSKBA5SR.js";
|
|
5
|
+
import {
|
|
6
|
+
createApp
|
|
7
|
+
} from "./chunk-NVGSGXGH.js";
|
|
8
|
+
|
|
9
|
+
// src/index.ts
|
|
10
|
+
import { isInsideContainer, isInsideContainerSync } from "@parity/product-sdk-host";
|
|
11
|
+
import { createChainClient } from "@parity/product-sdk-chain-client";
|
|
12
|
+
import { SignerManager } from "@parity/product-sdk-signer";
|
|
13
|
+
import { createKvStore } from "@parity/product-sdk-storage";
|
|
14
|
+
import { BulletinClient, computeCid } from "@parity/product-sdk-bulletin";
|
|
15
|
+
export {
|
|
16
|
+
BulletinClient,
|
|
17
|
+
SignerManager,
|
|
18
|
+
computeCid,
|
|
19
|
+
configure,
|
|
20
|
+
createApp,
|
|
21
|
+
createChainClient,
|
|
22
|
+
createKvStore,
|
|
23
|
+
createLogger,
|
|
24
|
+
isInsideContainer,
|
|
25
|
+
isInsideContainerSync
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * @parity/product-sdk\n *\n * Unified SDK for building products on the Polkadot ecosystem.\n *\n * @example\n * ```ts\n * import { createApp } from '@parity/product-sdk';\n *\n * const app = createApp({\n * name: 'my-app',\n * logLevel: 'info',\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 *\n * @packageDocumentation\n */\n\n// Core exports\nexport { createApp } from \"./core/createApp.js\";\nexport { configure, createLogger } from \"./core/logger.js\";\nexport type {\n App,\n AppConfig,\n LogLevel,\n WalletApi,\n StorageApi,\n ChainApi,\n BulletinApi,\n Account,\n ChainClient,\n ChainDefinition,\n TypedApi,\n PolkadotClient,\n} from \"./core/types.js\";\nexport type { LogEntry, LogHandler, LoggerConfig, Logger } from \"./core/logger.js\";\n\n// Re-export common utilities from leaf packages\nexport { isInsideContainer, isInsideContainerSync } from \"@parity/product-sdk-host\";\nexport { createChainClient } from \"@parity/product-sdk-chain-client\";\nexport { SignerManager } from \"@parity/product-sdk-signer\";\nexport { createKvStore } from \"@parity/product-sdk-storage\";\nexport { BulletinClient, computeCid } from \"@parity/product-sdk-bulletin\";\n"],"mappings":";;;;;;;;;AA4CA,SAAS,mBAAmB,6BAA6B;AACzD,SAAS,yBAAyB;AAClC,SAAS,qBAAqB;AAC9B,SAAS,qBAAqB;AAC9B,SAAS,gBAAgB,kBAAkB;","names":[]}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import * as react from 'react';
|
|
3
|
+
import { ReactNode } from 'react';
|
|
4
|
+
import { LogLevel } from '@parity/product-sdk-logger';
|
|
5
|
+
import { A as App, a as Account } from '../types-CZQDzQ53.js';
|
|
6
|
+
import { ChainDefinition, TypedApi } from 'polkadot-api';
|
|
7
|
+
import '@parity/product-sdk-bulletin';
|
|
8
|
+
import '@parity/product-sdk-chain-client';
|
|
9
|
+
|
|
10
|
+
/** Props for ProductSDKProvider */
|
|
11
|
+
interface ProductSDKProviderProps {
|
|
12
|
+
/** Application name - used for storage namespacing and product account derivation */
|
|
13
|
+
name: string;
|
|
14
|
+
/** Log level (default: 'info') */
|
|
15
|
+
logLevel?: LogLevel;
|
|
16
|
+
/** Child components */
|
|
17
|
+
children: ReactNode;
|
|
18
|
+
/** Fallback to show while loading */
|
|
19
|
+
fallback?: ReactNode;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Provider component that initializes the Product SDK
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```tsx
|
|
26
|
+
* import { ProductSDKProvider } from '@parity/product-sdk/react';
|
|
27
|
+
*
|
|
28
|
+
* function App() {
|
|
29
|
+
* return (
|
|
30
|
+
* <ProductSDKProvider name="my-app" fallback={<Loading />}>
|
|
31
|
+
* <MyApp />
|
|
32
|
+
* </ProductSDKProvider>
|
|
33
|
+
* );
|
|
34
|
+
* }
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
declare function ProductSDKProvider({ name, logLevel, children, fallback, }: ProductSDKProviderProps): react_jsx_runtime.JSX.Element;
|
|
38
|
+
|
|
39
|
+
/** Context for the Product SDK app instance */
|
|
40
|
+
declare const ProductSDKContext: react.Context<App | null>;
|
|
41
|
+
/**
|
|
42
|
+
* Hook to access the Product SDK app instance
|
|
43
|
+
*
|
|
44
|
+
* @throws If used outside of ProductSDKProvider
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```tsx
|
|
48
|
+
* function MyComponent() {
|
|
49
|
+
* const app = useProductSDK();
|
|
50
|
+
* // Use app.wallet, app.storage, etc.
|
|
51
|
+
* }
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
declare function useProductSDK(): App;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* useWallet hook
|
|
58
|
+
*/
|
|
59
|
+
|
|
60
|
+
/** Wallet hook state */
|
|
61
|
+
interface UseWalletState {
|
|
62
|
+
/** Whether wallet is connected */
|
|
63
|
+
isConnected: boolean;
|
|
64
|
+
/** Whether connection is in progress */
|
|
65
|
+
isConnecting: boolean;
|
|
66
|
+
/** Available accounts */
|
|
67
|
+
accounts: Account[];
|
|
68
|
+
/** Currently selected account */
|
|
69
|
+
selectedAccount: Account | null;
|
|
70
|
+
/** Last error */
|
|
71
|
+
error: Error | null;
|
|
72
|
+
}
|
|
73
|
+
/** Wallet hook actions */
|
|
74
|
+
interface UseWalletActions {
|
|
75
|
+
/** Connect to wallet */
|
|
76
|
+
connect: () => Promise<void>;
|
|
77
|
+
/** Disconnect from wallet */
|
|
78
|
+
disconnect: () => Promise<void>;
|
|
79
|
+
/** Select an account */
|
|
80
|
+
selectAccount: (address: string) => void;
|
|
81
|
+
/** Sign a message */
|
|
82
|
+
signMessage: (message: string | Uint8Array) => Promise<Uint8Array>;
|
|
83
|
+
}
|
|
84
|
+
/** Return type of useWallet */
|
|
85
|
+
type UseWalletReturn = UseWalletState & UseWalletActions;
|
|
86
|
+
/**
|
|
87
|
+
* Hook for wallet connection and signing
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```tsx
|
|
91
|
+
* function WalletButton() {
|
|
92
|
+
* const { isConnected, accounts, connect, disconnect, selectAccount } = useWallet();
|
|
93
|
+
*
|
|
94
|
+
* if (!isConnected) {
|
|
95
|
+
* return <button onClick={connect}>Connect Wallet</button>;
|
|
96
|
+
* }
|
|
97
|
+
*
|
|
98
|
+
* return (
|
|
99
|
+
* <div>
|
|
100
|
+
* <select onChange={(e) => selectAccount(e.target.value)}>
|
|
101
|
+
* {accounts.map((a) => (
|
|
102
|
+
* <option key={a.address} value={a.address}>
|
|
103
|
+
* {a.name || a.address}
|
|
104
|
+
* </option>
|
|
105
|
+
* ))}
|
|
106
|
+
* </select>
|
|
107
|
+
* <button onClick={disconnect}>Disconnect</button>
|
|
108
|
+
* </div>
|
|
109
|
+
* );
|
|
110
|
+
* }
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
declare function useWallet(): UseWalletReturn;
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* useStorage hook
|
|
117
|
+
*/
|
|
118
|
+
/**
|
|
119
|
+
* Hook for key-value storage operations
|
|
120
|
+
*
|
|
121
|
+
* @param key - Storage key
|
|
122
|
+
* @param defaultValue - Default value if key doesn't exist
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```tsx
|
|
126
|
+
* function ThemeToggle() {
|
|
127
|
+
* const [theme, setTheme, { loading }] = useStorage('theme', 'light');
|
|
128
|
+
*
|
|
129
|
+
* if (loading) return <div>Loading...</div>;
|
|
130
|
+
*
|
|
131
|
+
* return (
|
|
132
|
+
* <button onClick={() => setTheme(theme === 'light' ? 'dark' : 'light')}>
|
|
133
|
+
* Current: {theme}
|
|
134
|
+
* </button>
|
|
135
|
+
* );
|
|
136
|
+
* }
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
declare function useStorage<T = string>(key: string, defaultValue?: T): [T | null, (value: T) => Promise<void>, {
|
|
140
|
+
loading: boolean;
|
|
141
|
+
error: Error | null;
|
|
142
|
+
}];
|
|
143
|
+
/**
|
|
144
|
+
* Hook for string storage (simpler API)
|
|
145
|
+
*
|
|
146
|
+
* @param key - Storage key
|
|
147
|
+
* @param defaultValue - Default value
|
|
148
|
+
*/
|
|
149
|
+
declare function useStorageString(key: string, defaultValue?: string): [string | null, (value: string) => Promise<void>, {
|
|
150
|
+
loading: boolean;
|
|
151
|
+
}];
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* useChain hook
|
|
155
|
+
*/
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Hook to get a typed chain client
|
|
159
|
+
*
|
|
160
|
+
* @param chain - Chain descriptor (PAPI ChainDefinition)
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* ```tsx
|
|
164
|
+
* import { paseo_asset_hub } from '@parity/product-sdk-descriptors/paseo-asset-hub';
|
|
165
|
+
* import { useChain } from '@parity/product-sdk/react';
|
|
166
|
+
*
|
|
167
|
+
* function AssetHubBalance() {
|
|
168
|
+
* const assetHub = useChain(paseo_asset_hub);
|
|
169
|
+
*
|
|
170
|
+
* // assetHub is typed for Asset Hub queries
|
|
171
|
+
* const balance = await assetHub.query.System.Account.getValue(address);
|
|
172
|
+
* }
|
|
173
|
+
* ```
|
|
174
|
+
*/
|
|
175
|
+
declare function useChain<T extends ChainDefinition>(chain: T): TypedApi<T>;
|
|
176
|
+
|
|
177
|
+
export { ProductSDKContext, ProductSDKProvider, type ProductSDKProviderProps, type UseWalletActions, type UseWalletReturn, type UseWalletState, useChain, useProductSDK, useStorage, useStorageString, useWallet };
|