@parity/product-sdk 0.22.0 → 0.24.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/chunk-7GM3HUZF.js +89 -0
- package/dist/chunk-7GM3HUZF.js.map +1 -0
- package/dist/{chunk-6BI66XUJ.js → chunk-JIO3OZSC.js} +9 -10
- package/dist/chunk-JIO3OZSC.js.map +1 -0
- package/dist/core/index.d.ts +2 -2
- package/dist/core/index.js +2 -2
- package/dist/dotns-CtmOwVQW.d.ts +136 -0
- package/dist/identity/index.d.ts +502 -45
- package/dist/identity/index.js +800 -32
- package/dist/identity/index.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/react/index.d.ts +2 -2
- package/dist/react/index.js +2 -2
- package/dist/testing/index.d.ts +2 -2
- package/dist/{types-DTgyMIi0.d.ts → types-CRYPRNYk.d.ts} +1 -1
- package/package.json +12 -12
- package/src/core/createApp.ts +10 -8
- package/src/identity/dotns-abis.test.ts +43 -0
- package/src/identity/dotns-abis.ts +309 -0
- package/src/identity/dotns-addresses.test.ts +536 -0
- package/src/identity/dotns-addresses.ts +320 -0
- package/src/identity/dotns-errors.ts +36 -0
- package/src/identity/dotns-namehash.test.ts +155 -0
- package/src/identity/dotns-namehash.ts +149 -0
- package/src/identity/dotns-owner.test.ts +92 -0
- package/src/identity/dotns-registry.test.ts +1309 -0
- package/src/identity/dotns-registry.ts +868 -0
- package/src/identity/dotns.test.ts +128 -0
- package/src/identity/dotns.ts +91 -78
- package/src/identity/index.test.ts +43 -0
- package/src/identity/index.ts +40 -10
- package/src/identity/types.ts +29 -25
- package/src/individuality/contract.test.ts +295 -3
- package/dist/chunk-6BI66XUJ.js.map +0 -1
- package/dist/chunk-BIKT6X54.js +0 -70
- package/dist/chunk-BIKT6X54.js.map +0 -1
- package/dist/dotns-DIaptENj.d.ts +0 -167
- package/src/identity/product-account.test.ts +0 -129
- package/src/identity/product-account.ts +0 -115
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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","file":"index.js","sourcesContent":["// Copyright 2026 Parity Technologies (UK) Ltd.\n// SPDX-License-Identifier: Apache-2.0\n/**\n * Context alias derivation (deprecated, removal in 0.23.0)\n *\n * Derives a deterministic, context-bound alias from a parent account using blake2b-256.\n *\n * The output is a hash, not a key, so no signing key exists for the addresses\n * returned here. See the notes on each function for what to use instead.\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 } 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 * @deprecated Returns addresses that no key can spend. The alias public key is a\n * blake2b-256 hash rather than a derived key, so no secret corresponds to the\n * SS58 address or to the H160: both can receive value and neither can ever\n * send it. Removal: `@parity/product-sdk` 0.23.0. Replace by intent:\n *\n * - An account that holds or spends value:\n * `SignerManager.getProductAccount(dotNsIdentifier, index)` from\n * `@parity/product-sdk-signer`. Host-backed and actually signable.\n * - The address offline, with no host: `deriveProductAccountPublicKey` from\n * `@parity/product-sdk-keys`, the canonical sr25519 soft derivation.\n * - An unlinkable per-context alias: select a registered ring-VRF key, then call\n * `SignerManager.getProductAccountAlias(keyHandle, context, location)` or\n * `createRingVRFProof(keyHandle, context, location, message)`.\n * - A context-scoped identifier, never used as an account: `blake2b256` from\n * `@parity/product-sdk/crypto`. Same bytes, without address packaging that\n * invites the mistake.\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 */\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 * @deprecated Recomputes {@link deriveContextAlias} from two public values and\n * compares the result, so it confirms a derivation relationship and nothing\n * more. No secret enters the operation at any point, which means there is\n * nothing here to authenticate: a passing result does not show that anyone\n * controls either account. Removal: `@parity/product-sdk` 0.23.0.\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"]}
|
|
1
|
+
{"version":3,"sources":["../../src/identity/dotns-abis.ts","../../src/identity/dotns-errors.ts","../../src/identity/dotns-addresses.ts","../../src/identity/dotns-registry.ts"],"names":["ok","err"],"mappings":";;;;;;;;;AAgBO,IAAM,kBAAA,GAAiC;AAAA,EAC1C;AAAA,IACI,IAAA,EAAM,UAAA;AAAA,IACN,IAAA,EAAM,UAAA;AAAA,IACN,QAAQ,CAAC,EAAE,MAAM,MAAA,EAAQ,IAAA,EAAM,WAAW,CAAA;AAAA,IAC1C,SAAS,CAAC,EAAE,MAAM,EAAA,EAAI,IAAA,EAAM,WAAW,CAAA;AAAA,IACvC,eAAA,EAAiB;AAAA,GACrB;AAAA,EACA;AAAA,IACI,IAAA,EAAM,UAAA;AAAA,IACN,IAAA,EAAM,OAAA;AAAA,IACN,QAAQ,CAAC,EAAE,MAAM,MAAA,EAAQ,IAAA,EAAM,WAAW,CAAA;AAAA,IAC1C,SAAS,CAAC,EAAE,MAAM,EAAA,EAAI,IAAA,EAAM,WAAW,CAAA;AAAA,IACvC,eAAA,EAAiB;AAAA,GACrB;AAAA,EACA;AAAA,IACI,IAAA,EAAM,UAAA;AAAA,IACN,IAAA,EAAM,aAAA;AAAA,IACN,MAAA,EAAQ;AAAA,MACJ,EAAE,IAAA,EAAM,MAAA,EAAQ,IAAA,EAAM,SAAA,EAAU;AAAA,MAChC,EAAE,IAAA,EAAM,cAAA,EAAgB,IAAA,EAAM,SAAA;AAAU,KAC5C;AAAA,IACA,SAAS,EAAC;AAAA,IACV,eAAA,EAAiB;AAAA;AAEzB,CAAA;AAGO,IAAM,kBAAA,GAAiC;AAAA,EAC1C;AAAA,IACI,IAAA,EAAM,UAAA;AAAA,IACN,IAAA,EAAM,WAAA;AAAA,IACN,QAAQ,CAAC,EAAE,MAAM,MAAA,EAAQ,IA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W,cAAA,EAAgB,qCAAqC,EAAE,KAAA,EAAO,CAAC,CAAA;AAAA,EAC7F;AACJ","file":"index.js","sourcesContent":["// Copyright 2026 Parity Technologies (UK) Ltd.\n// SPDX-License-Identifier: Apache-2.0\n/**\n * Minimal ABIs for the DotNS contracts: the read and write methods this module\n * calls, and nothing else. Sourced from `paritytech/dotns` (`contracts/registry`,\n * `contracts/resolvers`, `contracts/registrars`, `contracts/pop`).\n */\nimport type { AbiEntry } from \"@parity/product-sdk-contracts\";\n\n/**\n * `DotnsRegistry` — node → resolver / owner, plus the owner-gated pointer write.\n *\n * `setResolver` is needed because registration parks `records[node].resolver` on\n * the reverse resolver, so the pointer must be moved once before any address\n * record is readable.\n */\nexport const DOTNS_REGISTRY_ABI: AbiEntry[] = [\n {\n type: \"function\",\n name: \"resolver\",\n inputs: [{ name: \"node\", type: \"bytes32\" }],\n outputs: [{ name: \"\", type: \"address\" }],\n stateMutability: \"view\",\n },\n {\n type: \"function\",\n name: \"owner\",\n inputs: [{ name: \"node\", type: \"bytes32\" }],\n outputs: [{ name: \"\", type: \"address\" }],\n stateMutability: \"view\",\n },\n {\n type: \"function\",\n name: \"setResolver\",\n inputs: [\n { name: \"node\", type: \"bytes32\" },\n { name: \"resolverAddr\", type: \"address\" },\n ],\n outputs: [],\n stateMutability: \"nonpayable\",\n },\n];\n\n/** `DotnsResolver` — node → resolved address. */\nexport const DOTNS_RESOLVER_ABI: AbiEntry[] = [\n {\n type: \"function\",\n name: \"addressOf\",\n inputs: [{ name: \"node\", type: \"bytes32\" }],\n outputs: [{ name: \"value\", type: \"address\" }],\n stateMutability: \"view\",\n },\n];\n\n/** `DotnsReverseResolver` — account → primary name. */\nexport const DOTNS_REVERSE_RESOLVER_ABI: AbiEntry[] = [\n {\n type: \"function\",\n name: \"nameOf\",\n inputs: [{ name: \"addr\", type: \"address\" }],\n outputs: [{ name: \"name\", type: \"string\" }],\n stateMutability: \"view\",\n },\n];\n\n/** `DotnsResolver` write — set a node's resolved address (owner-gated). */\nexport const DOTNS_RESOLVER_WRITE_ABI: AbiEntry[] = [\n {\n type: \"function\",\n name: \"setAddress\",\n inputs: [\n { name: \"node\", type: \"bytes32\" },\n { name: \"value\", type: \"address\" },\n ],\n outputs: [],\n stateMutability: \"nonpayable\",\n },\n];\n\n/**\n * `DotnsRegistrarController` — the commit-reveal registration flow. `register`\n * is payable; the value is the price from {@link DOTNS_POP_RULES_ABI}.\n * `Registration` = (label, owner, secret, reserved).\n */\nexport const DOTNS_REGISTRAR_CONTROLLER_ABI: AbiEntry[] = [\n {\n type: \"function\",\n name: \"available\",\n inputs: [{ name: \"label\", type: \"string\" }],\n outputs: [{ name: \"isAvailable\", type: \"bool\" }],\n stateMutability: \"view\",\n },\n {\n type: \"function\",\n name: \"minCommitmentAge\",\n inputs: [],\n outputs: [{ name: \"\", type: \"uint256\" }],\n stateMutability: \"view\",\n },\n {\n type: \"function\",\n name: \"maxCommitmentAge\",\n inputs: [],\n outputs: [{ name: \"\", type: \"uint256\" }],\n stateMutability: \"view\",\n },\n {\n type: \"function\",\n name: \"makeCommitment\",\n inputs: [\n {\n name: \"registration\",\n type: \"tuple\",\n components: [\n { name: \"label\", type: \"string\" },\n { name: \"owner\", type: \"address\" },\n { name: \"secret\", type: \"bytes32\" },\n { name: \"reserved\", type: \"bool\" },\n ],\n },\n ],\n outputs: [{ name: \"commitment\", type: \"bytes32\" }],\n stateMutability: \"pure\",\n },\n {\n type: \"function\",\n name: \"commit\",\n inputs: [{ name: \"commitment\", type: \"bytes32\" }],\n outputs: [],\n stateMutability: \"nonpayable\",\n },\n {\n type: \"function\",\n name: \"register\",\n inputs: [\n {\n name: \"registration\",\n type: \"tuple\",\n components: [\n { name: \"label\", type: \"string\" },\n { name: \"owner\", type: \"address\" },\n { name: \"secret\", type: \"bytes32\" },\n { name: \"reserved\", type: \"bool\" },\n ],\n },\n ],\n outputs: [],\n stateMutability: \"payable\",\n },\n];\n\n/**\n * `PopRules` — registration pricing.\n *\n * `price` is the label-only cost and runs no eligibility rules, so it is not\n * what `register` charges. `register` uses the owner-aware variants and adds\n * `transferFloor` when the payer is not the owner:\n * `max(priceWithoutCheck(label, owner).price, transferFloor(label, payer, owner))`.\n *\n * `PopStatus` encodes as `uint8`: 0 NoStatus, 1 PopLite, 2 PopFull, 3 Reserved.\n */\nexport const DOTNS_POP_RULES_ABI: AbiEntry[] = [\n {\n type: \"function\",\n name: \"price\",\n inputs: [{ name: \"name\", type: \"string\" }],\n outputs: [{ name: \"cost\", type: \"uint256\" }],\n stateMutability: \"view\",\n },\n {\n type: \"function\",\n name: \"priceWithoutCheck\",\n inputs: [\n { name: \"name\", type: \"string\" },\n { name: \"userAddress\", type: \"address\" },\n ],\n outputs: [\n {\n name: \"metadata\",\n type: \"tuple\",\n components: [\n { name: \"price\", type: \"uint256\" },\n { name: \"status\", type: \"uint8\" },\n { name: \"userStatus\", type: \"uint8\" },\n { name: \"message\", type: \"string\" },\n ],\n },\n ],\n stateMutability: \"view\",\n },\n {\n type: \"function\",\n name: \"classifyName\",\n inputs: [{ name: \"name\", type: \"string\" }],\n outputs: [\n { name: \"requirement\", type: \"uint8\" },\n { name: \"message\", type: \"string\" },\n ],\n stateMutability: \"pure\",\n },\n {\n type: \"function\",\n name: \"transferFloor\",\n inputs: [\n { name: \"name\", type: \"string\" },\n { name: \"from\", type: \"address\" },\n { name: \"to\", type: \"address\" },\n ],\n outputs: [{ name: \"floor\", type: \"uint256\" }],\n stateMutability: \"view\",\n },\n];\n\n/**\n * `IDotnsProtocolRegistry`, the two TLD getters.\n *\n * The TLD is per network: `initialize(tldLabel)` fixes it once at deployment\n * and there is no setter, so these are immutable for the life of a deployment.\n * `tld()` returns the suffix with its leading dot (`\".paseo\"`); `tldNode()`\n * returns `namehash(0, labelhash(label))`, which is derivable from the suffix\n * and so is read only as a cross-check.\n *\n * Deployments predating `dotns` `b4096968` have neither getter — the TLD was a\n * compile-time constant there — and revert with an empty payload.\n */\nexport const DOTNS_PROTOCOL_REGISTRY_ABI: AbiEntry[] = [\n {\n type: \"function\",\n name: \"tld\",\n inputs: [],\n outputs: [{ name: \"suffix\", type: \"string\" }],\n stateMutability: \"view\",\n },\n {\n type: \"function\",\n name: \"tldNode\",\n inputs: [],\n outputs: [{ name: \"node\", type: \"bytes32\" }],\n stateMutability: \"view\",\n },\n {\n type: \"function\",\n name: \"get\",\n inputs: [{ name: \"key\", type: \"bytes32\" }],\n outputs: [{ name: \"addr\", type: \"address\" }],\n stateMutability: \"view\",\n },\n];\n\n/**\n * `RootGatewayDispatcher.TARGET`, the PoP controller it forwards to. `immutable`,\n * so a rotation means a new dispatcher and a new pallet value, which is why\n * discovery starts at the pallet rather than here.\n */\nexport const DOTNS_ROOT_GATEWAY_DISPATCHER_ABI: AbiEntry[] = [\n {\n type: \"function\",\n name: \"TARGET\",\n inputs: [],\n outputs: [{ name: \"\", type: \"address\" }],\n stateMutability: \"view\",\n },\n];\n\n/** `DotnsPopController.protocolRegistry`, the only hop that names the registry. */\nexport const DOTNS_POP_CONTROLLER_ABI: AbiEntry[] = [\n {\n type: \"function\",\n name: \"protocolRegistry\",\n inputs: [],\n outputs: [{ name: \"\", type: \"address\" }],\n stateMutability: \"view\",\n },\n];\n\n/** `IPopRules.PopStatus`. Ordering is meaningful: a user meets a tier when `userStatus >= status`. */\nexport const POP_STATUS = { NoStatus: 0, PopLite: 1, PopFull: 2, Reserved: 3 } as const;\n\n/**\n * The deployed DotNS addresses. The same on every network.\n *\n * Not a per-network table, despite what the old name (`PASEO_ASSETHUB_DOTNS`)\n * implied: every DotNS network is deployed through the same CREATE3 factory, so\n * the addresses are identical everywhere and **only the TLD differs**, `.paseo`\n * on Paseo Asset Hub Next V2 and `.test` on Previewnet. Verified on both:\n * `protocolRegistry.get(...)` returns the same registry on each, and all six\n * addresses hold contracts on both. `paritytech/dotns` `DEPLOYMENTS.md` states the mechanism, and\n * `preview-net-v1` confirms it from the deploy side: the TLD is passed only as\n * registry init calldata, so it moves no address.\n *\n * So extending this module to another network means resolving its TLD, which\n * `resolveTld` already does — not adding a second address table.\n *\n * Five answer `DotnsProtocolRegistry.get(bytes32)` under the keys in\n * `DOTNS_REGISTRY_KEYS`, two of which differ from the field name used here.\n * `protocolRegistry` has no key and comes from the gateway walk. All six have a\n * `Revive.AccountInfoOf` entry.\n *\n * Pinned, not resolved at runtime: re-verify after a redeploy, or have the\n * client do it with `verifyDotNsAddresses`.\n */\nexport const DOTNS_ADDRESSES = {\n registry: \"0xf34054fd76BbF85f216cf9908226D5f0A72E50CA\",\n reverseResolver: \"0xee3883d7eB60Ee9BCD7F3bcD8f2f05302A9Cc035\",\n resolver: \"0xbd1165E549DF96F083c0A16f61590927bC187009\",\n registrarController: \"0xBdaA01bD1bA67d709F2b1fF286Da0d854977EA30\",\n popRules: \"0x747B456bE03aec0b42bd85C51513730FBD45DA31\",\n protocolRegistry: \"0xD19e3D0C97CF501125a04A97405e3e6592fa846E\",\n} as const;\n","// Copyright 2026 Parity Technologies (UK) Ltd.\n// SPDX-License-Identifier: Apache-2.0\nimport type { SdkError } from \"@parity/product-sdk-errors\";\n\n/**\n * Error on the `Err` channel of a DotNS registry read/write. Implements the\n * cross-package {@link SdkError} marker so `isSdkError(e)` recognizes it.\n *\n * `reason` distinguishes the failure kind so callers can branch without string\n * matching.\n */\nexport type DotNsErrorReason =\n | \"InvalidName\" // name failed isValidDotNsName\n | \"InvalidTld\" // the deployment reported a TLD we cannot use, or the caller supplied an inconsistent one\n | \"TldMismatch\" // a well-formed name, but rooted at another deployment's TLD\n | \"MissingOrigin\" // a write was requested without the submitting account\n | \"InvalidOrigin\" // the submitting account was supplied, but is not a decodable SS58 address\n | \"NameUnavailable\" // already registered\n | \"NameReserved\" // governance-held, or a base stem held by another user\n | \"OwnerStatusInsufficient\" // the owner lacks the personhood tier the label requires\n | \"AddressDiscovery\" // the gateway walk could not locate the deployment\n | \"AddressMismatch\" // a discovered address disagrees with the one in use\n | \"RegistryCall\" // the on-chain contract call failed\n | \"Decode\"; // the contract returned something we couldn't decode\n\nexport class DotNsError extends Error implements SdkError {\n readonly isSdkError = true as const;\n readonly source = \"dotns\";\n readonly reason: DotNsErrorReason;\n\n constructor(reason: DotNsErrorReason, message: string, options?: ErrorOptions) {\n super(message, options);\n this.name = \"DotNsError\";\n this.reason = reason;\n }\n}\n","// Copyright 2026 Parity Technologies (UK) Ltd.\n// SPDX-License-Identifier: Apache-2.0\n/**\n * Where the DotNS contract addresses come from.\n *\n * Every entry point in `./dotns-registry.js` asks {@link resolveDotNsAddresses}\n * rather than reaching for a constant, so \"which address do I call?\" has one\n * answer and the gateway walk can plug in behind it without touching them.\n */\nimport {\n type AbiEntry,\n type ContractRuntime,\n QUERY_FALLBACK_ORIGIN,\n createContract,\n} from \"@parity/product-sdk-contracts\";\nimport { type Result, err, ok } from \"@parity/result\";\nimport {\n DOTNS_ADDRESSES,\n DOTNS_POP_CONTROLLER_ABI,\n DOTNS_PROTOCOL_REGISTRY_ABI,\n DOTNS_ROOT_GATEWAY_DISPATCHER_ABI,\n} from \"./dotns-abis.js\";\nimport { DotNsError } from \"./dotns-errors.js\";\nimport type { SS58String } from \"polkadot-api\";\nimport type { DotNsClientOptions } from \"./dotns-registry.js\";\n\ntype HexString = `0x${string}`;\n\nexport interface DotNsAddresses {\n registry: HexString;\n reverseResolver: HexString;\n resolver: HexString;\n registrarController: HexString;\n popRules: HexString;\n protocolRegistry: HexString;\n}\n\n/**\n * The `DotnsProtocolRegistry.get(bytes32)` key each role answers under, from\n * `DotnsConstants`. Solidity's `bytes32(\"name\")` is the UTF-8 bytes\n * right-padded with zeros, which is what these literals are.\n *\n * Two are not the name you would guess, and guessing wrong is silent: `get`\n * answers with a live address for the contract you did not want, and it\n * surfaces much later as a revert. `registrarController` is the commit-reveal\n * controller, key `controller` — `registrar` is the ERC-721 holding name\n * ownership. `resolver` is the forward address resolver — `contentResolver`\n * holds contenthash and text records, which nothing here calls.\n *\n * `protocolRegistry` has no key at all, so it cannot be looked up in the\n * registry it is. The walk reaches it via `popController.protocolRegistry()`.\n */\nexport const DOTNS_REGISTRY_KEYS = {\n registry: \"0x7265676973747279000000000000000000000000000000000000000000000000\",\n registrarController: \"0x636f6e74726f6c6c657200000000000000000000000000000000000000000000\",\n reverseResolver: \"0x726576657273655265736f6c7665720000000000000000000000000000000000\",\n resolver: \"0x7265736f6c766572000000000000000000000000000000000000000000000000\",\n popRules: \"0x706f7052756c6573000000000000000000000000000000000000000000000000\",\n} as const satisfies Record<Exclude<keyof DotNsAddresses, \"protocolRegistry\">, HexString>;\n\nexport const ZERO_ADDRESS = \"0x0000000000000000000000000000000000000000\";\n\nexport function isZero(addr: unknown): boolean {\n return typeof addr === \"string\" && addr.toLowerCase() === ZERO_ADDRESS;\n}\n\n/** viem checksums every decoded `address`, so a read is EIP-55 whatever the chain sent. */\nexport function sameAddress(a: unknown, b: unknown): boolean {\n return typeof a === \"string\" && typeof b === \"string\" && a.toLowerCase() === b.toLowerCase();\n}\n\n/** A per-runtime, per-key cache of chain reads that cannot change under us. */\nexport type RuntimeCache<T> = WeakMap<ContractRuntime, Map<string, Promise<Result<T, DotNsError>>>>;\n\n/**\n * Read `key` once per runtime and hand every later caller the same answer.\n *\n * Stores the in-flight promise rather than the resolved value, so concurrent\n * first calls share one read instead of racing. A failed read is dropped from\n * the cache: those are usually the RPC blinking rather than the deployment\n * moving, and keeping one would strand the client for the life of the runtime.\n */\nexport function cachedPerRuntime<T>(\n cache: RuntimeCache<T>,\n runtime: ContractRuntime,\n key: string,\n load: () => Promise<Result<T, DotNsError>>,\n): Promise<Result<T, DotNsError>> {\n let byKey = cache.get(runtime);\n if (!byKey) {\n byKey = new Map();\n cache.set(runtime, byKey);\n }\n const cached = byKey.get(key);\n if (cached) return cached;\n\n const pending = load();\n byKey.set(key, pending);\n pending.then((result) => {\n if (!result.ok) byKey?.delete(key);\n });\n return pending;\n}\n\nfunction withOverrides(base: DotNsAddresses, opts: DotNsClientOptions): DotNsAddresses {\n return {\n registry: opts.registryAddress ?? base.registry,\n reverseResolver: opts.reverseResolverAddress ?? base.reverseResolver,\n resolver: opts.resolverAddress ?? base.resolver,\n registrarController: opts.registrarControllerAddress ?? base.registrarController,\n popRules: opts.popRulesAddress ?? base.popRules,\n protocolRegistry: opts.protocolRegistryAddress ?? base.protocolRegistry,\n };\n}\n\n/**\n * Async because the discovered source reads the chain. The pinned source does\n * no IO, so a caller that only validates a name still pays nothing for it.\n */\nconst walkCache: RuntimeCache<DotNsAddresses> = new WeakMap();\n\n/**\n * Constant, unlike the TLD cache which keys on the protocol registry address.\n * Nothing else selects the deployment: `gatewayApi` is required to describe the\n * same chain as `runtime`, and the walk derives every address from there.\n */\nconst WALK_KEY = \"discovered\";\n\nexport async function resolveDotNsAddresses(\n opts: DotNsClientOptions,\n): Promise<Result<DotNsAddresses, DotNsError>> {\n if (opts.addressSource !== \"discovered\") return ok(withOverrides(DOTNS_ADDRESSES, opts));\n\n // Cache the walk, not the merged set: two callers differing only in their\n // overrides must share one walk and still each get their own answer.\n const walked = await cachedPerRuntime(walkCache, opts.runtime, WALK_KEY, () =>\n discoverDotNsAddresses(opts),\n );\n return walked.ok ? ok(withOverrides(walked.value, opts)) : walked;\n}\n\n/**\n * Reads `DotnsGateway.DispatcherAddress`, the pallet storage the walk starts\n * from. Structural because `ContractRuntime` does not declare it.\n */\nexport type DotNsGatewayQueryApi = {\n query: {\n DotnsGateway: {\n DispatcherAddress: {\n getValue: () => Promise<{ asHex(): string } | string | undefined>;\n };\n };\n };\n};\n\nconst discoveryFailed = (step: string, cause?: unknown) =>\n err(new DotNsError(\"AddressDiscovery\", `DotNS address discovery failed: ${step}`, { cause }));\n\n/**\n * `createContract` is generic over a typed ABI def; these minimal literal ABIs\n * are called by name via `.query()`, so the handle is untyped by construction.\n */\nexport function contractOf(runtime: ContractRuntime, address: HexString, abi: AbiEntry[]) {\n return createContract(runtime, address, abi as any) as any;\n}\n\n/**\n * Origin for a read. Passing the fallback explicitly rather than letting the\n * contracts layer substitute it keeps each query from logging a warning.\n */\nexport function readOrigin(opts: DotNsClientOptions): SS58String {\n return opts.origin ?? QUERY_FALLBACK_ORIGIN;\n}\n\nasync function readAddress(\n contract: {\n [m: string]: { query: (o: object) => Promise<{ success: boolean; value: unknown }> };\n },\n method: string,\n origin: string,\n): Promise<Result<HexString, DotNsError>> {\n const res = await contract[method].query({ origin });\n if (!res.success) return discoveryFailed(`${method}() failed`, res.value);\n const value = res.value;\n if (typeof value !== \"string\" || isZero(value)) {\n return discoveryFailed(`${method}() returned no address`);\n }\n return ok(value as HexString);\n}\n\n/** PAPI hands back H160 as a wrapper or a hex string depending on the major. */\nfunction asH160(value: unknown): HexString | null {\n if (typeof value === \"string\") return value as HexString;\n if (value && typeof (value as { asHex?: unknown }).asHex === \"function\") {\n return (value as { asHex(): string }).asHex() as HexString;\n }\n return null;\n}\n\nfunction gatewayOf(opts: DotNsClientOptions): DotNsGatewayQueryApi | null {\n if (opts.gatewayApi) return opts.gatewayApi;\n const api = opts.runtime?.api as unknown as Partial<DotNsGatewayQueryApi> | undefined;\n const getValue = api?.query?.DotnsGateway?.DispatcherAddress?.getValue;\n return typeof getValue === \"function\" ? (api as DotNsGatewayQueryApi) : null;\n}\n\n/**\n * Locate the live deployment from chain state, trusting nothing pinned here.\n *\n * Pallet -> `dispatcher.TARGET()` -> `popController.protocolRegistry()` ->\n * `get(key)` per role. The first three are sequential because each answer is\n * the next call's address; the role reads are not, so they go together.\n *\n * A failed or zero read is always an error: falling back to the pinned table\n * would recreate the situation this exists to detect, and hide it better.\n */\nexport async function discoverDotNsAddresses(\n opts: DotNsClientOptions,\n): Promise<Result<DotNsAddresses, DotNsError>> {\n try {\n const gateway = gatewayOf(opts);\n if (!gateway) {\n return discoveryFailed(\n \"no DotnsGateway.DispatcherAddress storage on this runtime; pass opts.gatewayApi\",\n );\n }\n const dispatcher = asH160(await gateway.query.DotnsGateway.DispatcherAddress.getValue());\n if (!dispatcher || isZero(dispatcher)) {\n return discoveryFailed(\"DotnsGateway.DispatcherAddress is unset\");\n }\n\n const origin = readOrigin(opts);\n const target = await readAddress(\n contractOf(opts.runtime, dispatcher, DOTNS_ROOT_GATEWAY_DISPATCHER_ABI),\n \"TARGET\",\n origin,\n );\n if (!target.ok) return target;\n\n const protocolRegistry = await readAddress(\n contractOf(opts.runtime, target.value, DOTNS_POP_CONTROLLER_ABI),\n \"protocolRegistry\",\n origin,\n );\n if (!protocolRegistry.ok) return protocolRegistry;\n\n const registry = contractOf(\n opts.runtime,\n protocolRegistry.value,\n DOTNS_PROTOCOL_REGISTRY_ABI,\n );\n const roles = Object.entries(DOTNS_REGISTRY_KEYS) as [\n keyof typeof DOTNS_REGISTRY_KEYS,\n HexString,\n ][];\n // Not readAddress: that calls the method with no arguments, and these\n // need the role name in the error rather than the method name, since\n // every one of them is the same `get`.\n const found = await Promise.all(\n roles.map(async ([role, key]) => {\n const res = await registry.get.query(key, { origin });\n if (!res.success) return discoveryFailed(`get(${role}) failed`, res.value);\n const value = res.value;\n // A wrong key is not an error on chain: it returns address(0),\n // so the role name is the only clue the caller gets.\n if (typeof value !== \"string\" || isZero(value)) {\n return discoveryFailed(`${role} is unset on the protocol registry`);\n }\n return ok([role, value as HexString] as const);\n }),\n );\n const failed = found.find((r) => !r.ok);\n if (failed && !failed.ok) return failed;\n\n const byRole = Object.fromEntries(found.flatMap((r) => (r.ok ? [r.value] : []))) as Omit<\n DotNsAddresses,\n \"protocolRegistry\"\n >;\n return ok({ ...byRole, protocolRegistry: protocolRegistry.value });\n } catch (cause) {\n return discoveryFailed(\"unexpected error\", cause);\n }\n}\n\n/**\n * Walk the gateway and report every role whose live address differs from the\n * one this client would call. Meant for startup: it fails loudly once, rather\n * than making every later read pay for the check.\n */\nexport async function verifyDotNsAddresses(\n opts: DotNsClientOptions,\n): Promise<Result<DotNsAddresses, DotNsError>> {\n // Through the cache, so verifying at startup and then using the client is\n // one walk rather than two.\n const discovered = await cachedPerRuntime(walkCache, opts.runtime, WALK_KEY, () =>\n discoverDotNsAddresses(opts),\n );\n if (!discovered.ok) return discovered;\n\n // Compare what this client actually calls, which is the pinned table or the\n // walk depending on the source, with the caller's overrides on top either\n // way. A discovered client can still drift, through an override that\n // disagrees with the chain; it is only the pinned base that cannot apply.\n const inUse = withOverrides(\n opts.addressSource === \"discovered\" ? discovered.value : DOTNS_ADDRESSES,\n opts,\n );\n const drift = (Object.keys(inUse) as (keyof DotNsAddresses)[])\n .filter((role) => !sameAddress(inUse[role], discovered.value[role]))\n .map((role) => `${role}: using ${inUse[role]}, chain says ${discovered.value[role]}`);\n\n return drift.length\n ? err(\n new DotNsError(\n \"AddressMismatch\",\n `DotNS addresses disagree with the deployment — ${drift.join(\"; \")}`,\n ),\n )\n : ok(inUse);\n}\n","// Copyright 2026 Parity Technologies (UK) Ltd.\n// SPDX-License-Identifier: Apache-2.0\n/**\n * DotNS registry reads and writes.\n *\n * DotNS is an ENS-style system on Asset Hub: a `DotnsRegistry` maps a node\n * (namehash) to a resolver + owner, a `DotnsResolver` maps a node to an\n * address, and a `DotnsReverseResolver` maps an account back to its name. All\n * are Revive contracts, reached via `@parity/product-sdk-contracts`'\n * `createContract(...).<method>.query(...)`. Contract source:\n * https://github.com/paritytech/dotns\n *\n * **Names are rooted at the network's TLD, which is per deployment.** It is\n * fixed when `DotnsProtocolRegistry.initialize` runs, has no setter, and is\n * published as `tld()`. `.paseo` on Paseo Asset Hub Next V2, `.test` on\n * Previewnet, and operators can choose others. Every entry point that hashes a\n * name therefore asks the chain first, through {@link resolveTld}, and callers\n * can supply `opts.tld` to skip the read. Hashing under the wrong root returns a\n * node the chain never wrote to, so the failure looks exactly like an\n * unregistered name — which is why nothing here assumes a root.\n *\n * **A node's resolver pointer is not necessarily a forward resolver.** The\n * deployment has several — forward, reverse, content, PoP — and only the forward\n * one answers `addressOf`. `resolveDotNs` therefore calls it only when the\n * pointer *is* the forward resolver, and reports every other pointer as\n * \"registered, no forward record\". The content resolver is the common case for a\n * product name.\n *\n * A rule this module holds to throughout: **a failed read must never become a\n * plausible value.** The one deliberate exception is documented on\n * {@link resolveTld}, where a missing getter identifies a deployment whose TLD\n * could only have been `.dot`.\n *\n * Reads (`resolveDotNs` / `reverseDotNs` / `isDotNsAvailable`) query chain.\n * Writes return prepared calls the caller submits with their own signer:\n * `setDotNsRecord` (the resolver pointer, when it needs moving, plus the\n * record) and `prepareDotNsRegistration` (the commit call plus a thunk for the\n * register call, which cannot be built until the commitment is on chain).\n *\n * Note: this deployment has no name-expiry concept (the registrar exposes no\n * expiry getter), so `DotNsRecord.expiresAt` is always omitted.\n */\nimport { err, ok, type Result } from \"@parity/result\";\nimport type { AbiEntry, BatchableCall, ContractRuntime } from \"@parity/product-sdk-contracts\";\nimport { bytesToHex, randomBytes } from \"@parity/product-sdk-crypto\";\nimport { ss58ToH160 } from \"@parity/product-sdk-address\";\nimport { createLogger } from \"@parity/product-sdk-logger\";\nimport type { SS58String } from \"polkadot-api\";\nimport {\n DOTNS_POP_RULES_ABI,\n DOTNS_PROTOCOL_REGISTRY_ABI,\n DOTNS_REGISTRAR_CONTROLLER_ABI,\n DOTNS_REGISTRY_ABI,\n DOTNS_RESOLVER_ABI,\n DOTNS_RESOLVER_WRITE_ABI,\n DOTNS_REVERSE_RESOLVER_ABI,\n DOTNS_ADDRESSES,\n POP_STATUS,\n} from \"./dotns-abis.js\";\nimport { DotNsError } from \"./dotns-errors.js\";\nimport {\n type DotNsGatewayQueryApi,\n type RuntimeCache,\n cachedPerRuntime,\n contractOf,\n isZero,\n readOrigin,\n resolveDotNsAddresses,\n sameAddress,\n} from \"./dotns-addresses.js\";\nimport { isResolvableDotNsName, isValidDotNsName, normalizeDotNsName } from \"./dotns.js\";\nimport {\n DOT_TLD,\n dotNsTld,\n type DotNsTld,\n isConsistentDotNsTld,\n namehash,\n stripSuffix,\n} from \"./dotns-namehash.js\";\nimport type { DotNsRecord } from \"./types.js\";\n\nconst log = createLogger(\"identity:dotns\");\n\ntype HexString = `0x${string}`;\n\n/** Shared inputs for a DotNS registry call. */\nexport interface DotNsClientOptions {\n /** A contract runtime for the chain hosting DotNS (Asset Hub). */\n runtime: ContractRuntime;\n /**\n * SS58 account that will submit the prepared calls.\n *\n * Required by the write helpers, which dry-run against it: `setAddress` and\n * `setResolver` are owner-gated, so a dry-run from anyone else reverts.\n * Optional for reads, which fall back to the pallet-revive query account.\n *\n * Must be SS58, not the account's H160. pallet-revive derives `msg.sender`\n * from it; convert with `h160ToSs58` from `@parity/product-sdk-address`.\n */\n origin?: SS58String;\n /** `DotnsRegistry` address. Defaults to the deployed set, which is the same on every network. */\n registryAddress?: HexString;\n /** `DotnsReverseResolver` address. Defaults to the deployed set. */\n reverseResolverAddress?: HexString;\n /** `DotnsResolver` address (writes: setDotNsRecord). Defaults to Paseo AH. */\n resolverAddress?: HexString;\n /** `DotnsRegistrarController` address (registration). Defaults to Paseo AH. */\n registrarControllerAddress?: HexString;\n /** `PopRules` address (registration price). Defaults to Paseo AH. */\n popRulesAddress?: HexString;\n /**\n * `DotnsProtocolRegistry` address, the contract holding this network's TLD.\n * Defaults to Paseo AH — and the address is the same on every network, since\n * the whole set is CREATE3-deterministic.\n */\n protocolRegistryAddress?: HexString;\n /**\n * Where the addresses come from. `\"pinned\"` (the default) uses the\n * {@link DOTNS_ADDRESSES} table; `\"discovered\"` walks the gateway on the\n * chain `runtime` points at, so nothing is trusted from this bundle.\n *\n * Pinned is the default because the table is currently correct and a walk\n * costs four round trips on the first call. Discovery is the honest choice\n * once a deployment has moved, and its trust root is\n * `DotnsGateway.DispatcherAddress` — a governance-set value on the chain the\n * caller already trusts for every name read. Per-field address overrides win\n * over either source.\n *\n * Discovery also selects the address `setDotNsRecord` and\n * `prepareDotNsRegistration` build calls against, so it decides where a\n * signed transaction goes, not only where a read comes from. A pinned\n * address constrains that destination even against a hostile RPC; a\n * discovered one does not. Use {@link verifyDotNsAddresses} at startup if\n * that matters.\n */\n addressSource?: \"pinned\" | \"discovered\";\n /**\n * Typed API for the chain hosting the `DotnsGateway` pallet, needed only by\n * `\"discovered\"`.\n *\n * Optional because `runtime.api` is usually the same chain and is used when\n * it carries the pallet. `ContractRuntime` does not declare that storage, so\n * it is probed rather than assumed; on a chain without the pallet, discovery\n * fails with `AddressDiscovery` instead of throwing.\n */\n gatewayApi?: DotNsGatewayQueryApi;\n /**\n * The deployment's TLD, when you already know it.\n *\n * Omit it and the client reads `protocolRegistry.tld()` once per runtime and\n * caches it, which is the correct default: the TLD is per network and only\n * the chain knows which one is in play. Supply it to skip the read for\n * offline or test use, or to pin a deployment deliberately. Build it with\n * `dotNsTld(\".paseo\")` rather than by hand — a suffix paired with the wrong\n * node is rejected, because that pairing is the defect this option could\n * otherwise reintroduce.\n */\n tld?: DotNsTld;\n}\n\n/** Arguments for {@link prepareDotNsRegistration}. */\nexport interface RegisterDotNsArgs {\n /** The name to register, e.g. `\"alice.paseo\"` — or the bare label `\"alice\"`. */\n name: string;\n /**\n * The account that will own the registered name: an H160, `0x` and 20\n * bytes. Not SS58 — DotNS is a set of Revive contracts, and the registrar\n * takes the owner as an ABI `address`. Convert with `ss58ToH160` from\n * `@parity/product-sdk-address` if you hold a Substrate-shaped address.\n *\n * Typed `string` rather than `` `0x${string}` `` so callers need no cast,\n * which means the compiler will not catch an SS58 address here: it reaches\n * the contract and reverts on chain.\n */\n owner: string;\n /** Reserved-name registration (default `false`). */\n reserved?: boolean;\n}\n\n/** Arguments for {@link setDotNsRecord}. */\nexport interface SetRecordArgs {\n /** The name whose resolver record is being set. */\n name: string;\n /**\n * The address the name should resolve to: an H160, `0x` and 20 bytes. It is\n * written straight into `resolver.setAddress` as an ABI `address`, so SS58\n * is not accepted — convert with `ss58ToH160` from\n * `@parity/product-sdk-address` first. Unenforced by the type, as with\n * {@link RegisterDotNsArgs.owner}.\n */\n address: string;\n}\n\n// ── The deployment's TLD ─────────────────────────────────────────────\n//\n// Every node hash is rooted at the network's TLD, which is fixed when\n// `DotnsProtocolRegistry.initialize` runs and has no setter. Read it once per\n// (runtime, protocol registry) and cache it: it cannot change under us.\n\n/**\n * Cached TLD per runtime, then per protocol-registry address. Keyed on the\n * address as well because it is overridable, and one runtime pointed at two\n * registries has two TLDs.\n */\nconst tldCache: RuntimeCache<DotNsTld> = new WeakMap();\n\n/** An empty-payload revert: the contract ran and refused, telling us nothing. */\nfunction isEmptyRevert(value: unknown): boolean {\n return (\n typeof value === \"object\" &&\n value !== null &&\n (value as { type?: unknown }).type === \"ContractRevertedWithPayload\" &&\n (value as { data?: unknown }).data === \"0x\"\n );\n}\n\n/**\n * The TLD every name on this deployment is rooted at.\n *\n * Asks `protocolRegistry.tld()` and derives the node from the suffix, which is\n * exactly what `initialize` did — so `tldNode()` is only ever a cross-check, and\n * one read answers the question.\n *\n * Three outcomes, and the middle one is a deliberate exception to this module's\n * rule that a failed read must never become a plausible value:\n *\n * - the getter answers with a usable suffix → that TLD;\n * - the getter **reverts with an empty payload** → `DOT_TLD`, with a warning.\n * That signature means the function does not exist, which dates the\n * deployment before `dotns` `b4096968` (\"make the TLD network-configurable\n * via the protocol registry\"). Before that commit the TLD was a\n * compile-time constant and `.dot` was the only value it could hold, so\n * this is the one case where the fallback is provably right rather than\n * merely plausible. No live deployment is known to still take this\n * branch: Previewnet was cited for it, but reports `.test`;\n * - anything else → `err`. A dispatch failure, a revert carrying a reason, an\n * undecodable answer, or a TLD we cannot use.\n *\n * That last case includes a getter that *succeeds* with an unusable value. The\n * registry is `UUPSUpgradeable` with no reinitializer, so a pre-`b4096968` proxy\n * upgraded to current contracts without a migration reports `_tld` as `\"\"` and\n * `_tldNode` as zero — both getters succeed and hand back the plain ENS root,\n * which would silently reroot every name. {@link isConsistentDotNsTld} is what\n * catches it.\n *\n * @internal Exposed for unit testing; consumers reach it through the entry points.\n */\nexport async function resolveTld(opts: DotNsClientOptions): Promise<Result<DotNsTld, DotNsError>> {\n if (opts.tld) {\n // A caller-supplied pair gets the same consistency check as a chain read:\n // `.paseo` carrying `DOT_NODE` is the original bug via the override path.\n return isConsistentDotNsTld(opts.tld)\n ? ok(opts.tld)\n : err(\n new DotNsError(\n \"InvalidTld\",\n `opts.tld is inconsistent: \"${opts.tld.suffix}\" does not hash to ${opts.tld.node}`,\n ),\n );\n }\n\n const addresses = await resolveDotNsAddresses(opts);\n if (!addresses.ok) return addresses;\n const address = addresses.value.protocolRegistry;\n return cachedPerRuntime(tldCache, opts.runtime, address, () => readTld(opts, address));\n}\n\nasync function readTld(\n opts: DotNsClientOptions,\n address: HexString,\n): Promise<Result<DotNsTld, DotNsError>> {\n try {\n const registry = contractOf(opts.runtime, address, DOTNS_PROTOCOL_REGISTRY_ABI);\n const origin = readOrigin(opts);\n const suffixRes = await registry.tld.query({ origin });\n\n if (!suffixRes.success) {\n if (isEmptyRevert(suffixRes.value)) {\n log.warn(\n \"DotNS protocol registry has no tld() getter; treating this as a \" +\n \"pre-b4096968 deployment, whose TLD was the compile-time .dot\",\n { protocolRegistry: address },\n );\n return ok(DOT_TLD);\n }\n return err(\n new DotNsError(\"RegistryCall\", \"protocolRegistry.tld call failed\", {\n cause: suffixRes.value,\n }),\n );\n }\n\n const suffix = suffixRes.value as string;\n const tld = dotNsTld(suffix);\n if (!isConsistentDotNsTld(tld)) {\n return err(\n new DotNsError(\n \"InvalidTld\",\n `protocolRegistry.tld returned an unusable TLD: ${JSON.stringify(suffix)}`,\n ),\n );\n }\n\n // Cross-check, not the source. A disagreement means the deployment's\n // stored node was not derived from its stored label, which no\n // `initialize` can produce — so trust neither value.\n //\n // Only a well-formed node counts as a disagreement. A revert (the getter\n // is absent) or an unreadable answer means the cross-check did not run,\n // which is not evidence against a suffix that already derived cleanly.\n const nodeRes = await registry.tldNode.query({ origin });\n if (nodeRes.success && isNode(nodeRes.value) && !sameNode(nodeRes.value, tld.node)) {\n return err(\n new DotNsError(\n \"InvalidTld\",\n `protocolRegistry disagrees with itself: tld() ${suffix} derives ` +\n `${tld.node} but tldNode() reports ${String(nodeRes.value)}`,\n ),\n );\n }\n\n log.debug(\"resolveTld\", { protocolRegistry: address, suffix: tld.suffix, node: tld.node });\n return ok(tld);\n } catch (cause) {\n return err(new DotNsError(\"RegistryCall\", \"DotNS TLD read failed\", { cause }));\n }\n}\n\n/**\n * Why a normalized name was refused.\n *\n * Two distinct answers, because they call for different things from the caller.\n * `TldMismatch` means the name is well formed but belongs to another\n * deployment — `alice.dot` handed to a `.paseo` network — which a product may\n * want to offer to correct, and which the SDK must never correct silently:\n * the two are separate registrations that may have different owners.\n * `InvalidName` means the labels themselves are malformed, and no rewrite helps.\n */\nfunction nameError(input: string, normalized: string, tld: DotNsTld): DotNsError {\n if (!normalized.endsWith(tld.suffix)) {\n return new DotNsError(\n \"TldMismatch\",\n `DotNS name \"${input}\" is not on this deployment, which uses \"${tld.suffix}\"`,\n );\n }\n return new DotNsError(\"InvalidName\", `Invalid DotNS name: \"${input}\"`);\n}\n\n/** Whether a value is a readable 32-byte node, and so usable as a cross-check. */\nfunction isNode(value: unknown): value is HexString {\n return typeof value === \"string\" && /^0x[0-9a-fA-F]{64}$/.test(value);\n}\n\n/** Case-insensitive 32-byte node compare, for the same reason as {@link sameAddress}. */\nfunction sameNode(a: string, b: string): boolean {\n return a.toLowerCase() === b.toLowerCase();\n}\n\n/**\n * Resolve a DotNS name. `expiresAt` is omitted (no on-chain expiry here).\n *\n * Three outcomes, because the registry's resolver pointer is configuration, not\n * proof of existence:\n *\n * - `ok(null)` — unregistered (`registry.owner` is zero).\n * - `ok({ name, owner })` — registered, no forward record yet.\n * - `ok({ name, owner, address })` — resolves.\n */\nexport async function resolveDotNs(\n name: string,\n opts: DotNsClientOptions,\n): Promise<Result<DotNsRecord | null, DotNsError>> {\n // The TLD comes first because normalization and validation both need the\n // suffix. One read per runtime, cached; an invalid name therefore costs a\n // chain read on the first call and none after. Do not move validation back\n // in front of this — it cannot know what a valid name looks like yet.\n const tldRes = await resolveTld(opts);\n if (!tldRes.ok) return tldRes;\n const tld = tldRes.value;\n const normalized = normalizeDotNsName(name, tld.suffix);\n if (!isResolvableDotNsName(normalized, tld.suffix)) {\n return err(nameError(name, normalized, tld));\n }\n const node = namehash(normalized, tld);\n const addrs = await resolveDotNsAddresses(opts);\n if (!addrs.ok) return addrs;\n const registryAddr = addrs.value.registry;\n const origin = readOrigin(opts);\n log.debug(\"resolveDotNs\", { name: normalized, node, registry: registryAddr });\n\n try {\n const registry = contractOf(opts.runtime, registryAddr as HexString, DOTNS_REGISTRY_ABI);\n\n const [ownerRes, resolverRes] = await Promise.all([\n registry.owner.query(node, { origin }),\n registry.resolver.query(node, { origin }),\n ]);\n if (!ownerRes.success) {\n return err(\n new DotNsError(\"RegistryCall\", \"registry.owner call failed\", {\n cause: ownerRes.value,\n }),\n );\n }\n if (!resolverRes.success) {\n return err(\n new DotNsError(\"RegistryCall\", \"registry.resolver call failed\", {\n cause: resolverRes.value,\n }),\n );\n }\n\n // Existence check: the getter falls back to the registrar's ERC-721\n // holder, and returns zero for a node with no record.\n const owner = ownerRes.value as HexString;\n if (isZero(owner)) return ok(null);\n\n // Only the forward resolver answers `addressOf`, so that is the one\n // pointer worth calling — an allowlist, not a denylist of the resolvers\n // we happen to have met. A node can legitimately point at the reverse\n // resolver (where registration parks it), the content resolver (a\n // product name serving content, and the ordinary case in practice), the\n // PoP resolver, or one deployed after this was written. None of them has\n // an address record to give, and all of them revert if asked — which\n // would surface as an infrastructure failure for a name that is simply\n // registered without a forward record.\n //\n // `setDotNsRecord` already compares against the forward resolver this\n // way; before this, the read and write paths disagreed about what a\n // pointer meant.\n const resolverAddr = resolverRes.value as HexString;\n const forwardAddr = addrs.value.resolver;\n if (!sameAddress(resolverAddr, forwardAddr)) {\n return ok({ name: normalized, owner });\n }\n\n const resolver = contractOf(opts.runtime, resolverAddr as HexString, DOTNS_RESOLVER_ABI);\n const addrRes = await resolver.addressOf.query(node, { origin });\n if (!addrRes.success) {\n return err(\n new DotNsError(\"RegistryCall\", \"resolver.addressOf call failed\", {\n cause: addrRes.value,\n }),\n );\n }\n const address = addrRes.value as HexString;\n // A forward resolver holding an empty record is still no forward record.\n if (isZero(address)) return ok({ name: normalized, owner });\n\n return ok({ address, name: normalized, owner });\n } catch (cause) {\n return err(\n new DotNsError(\"RegistryCall\", `DotNS resolve failed for \"${normalized}\"`, { cause }),\n );\n }\n}\n\n/**\n * Reverse-resolve an account to its primary DotNS name.\n *\n * Single call: `reverseResolver.nameOf(account)`. `ok(null)` when no primary\n * name is set (empty string on-chain).\n */\nexport async function reverseDotNs(\n address: string,\n opts: DotNsClientOptions,\n): Promise<Result<string | null, DotNsError>> {\n const addrs = await resolveDotNsAddresses(opts);\n if (!addrs.ok) return addrs;\n const reverseAddr = addrs.value.reverseResolver;\n log.debug(\"reverseDotNs\", { address, reverseResolver: reverseAddr });\n try {\n const reverse = contractOf(\n opts.runtime,\n reverseAddr as HexString,\n DOTNS_REVERSE_RESOLVER_ABI,\n );\n const res = await reverse.nameOf.query(address, { origin: readOrigin(opts) });\n if (!res.success) {\n return err(\n new DotNsError(\"RegistryCall\", \"reverseResolver.nameOf call failed\", {\n cause: res.value,\n }),\n );\n }\n const name = res.value as string;\n return ok(name && name.length > 0 ? name : null);\n } catch (cause) {\n return err(\n new DotNsError(\"RegistryCall\", `DotNS reverse failed for \"${address}\"`, { cause }),\n );\n }\n}\n\n/**\n * Whether a DotNS name is available to claim.\n *\n * Two reads, because \"not minted\" and \"claimable\" are different questions:\n *\n * - `registrarController.available(label)`, the predicate `register` enforces\n * through `_requireAvailableLabel`. Deliberately not inferred from\n * resolution: a registered name has no forward record until its owner sets\n * one, so that would report owned names as free.\n * - `PopRules.classifyName(label)`, which is pure and owner-independent.\n * Labels of 5 base characters or fewer are reserved for governance and can\n * never be claimed, though the registrar still reports them as unminted.\n *\n * `ok(true)` means the name can be registered by someone. It does not mean the\n * caller can register it: labels of 6 to 8 characters additionally require a\n * personhood tier, which depends on the owner and is checked by\n * {@link prepareDotNsRegistration}.\n *\n * Validated first because both reads revert on labels we already reject.\n */\nexport async function isDotNsAvailable(\n name: string,\n opts: DotNsClientOptions,\n): Promise<Result<boolean, DotNsError>> {\n const tldRes = await resolveTld(opts);\n if (!tldRes.ok) return tldRes;\n const tld = tldRes.value;\n const normalized = normalizeDotNsName(name, tld.suffix);\n if (!isValidDotNsName(normalized, tld.suffix)) {\n return err(nameError(name, normalized, tld));\n }\n // The registrar takes the bare label, without the TLD suffix.\n const label = stripSuffix(normalized, tld.suffix);\n const addrs = await resolveDotNsAddresses(opts);\n if (!addrs.ok) return addrs;\n const controllerAddr = addrs.value.registrarController;\n log.debug(\"isDotNsAvailable\", { name: normalized, label, controller: controllerAddr });\n\n try {\n const controller = contractOf(\n opts.runtime,\n controllerAddr as HexString,\n DOTNS_REGISTRAR_CONTROLLER_ABI,\n );\n const popRules = contractOf(opts.runtime, addrs.value.popRules, DOTNS_POP_RULES_ABI);\n const origin = readOrigin(opts);\n const [res, classified] = await Promise.all([\n controller.available.query(label, { origin }),\n popRules.classifyName.query(label, { origin }),\n ]);\n if (!res.success) {\n return err(\n new DotNsError(\"RegistryCall\", \"registrarController.available call failed\", {\n cause: res.value,\n }),\n );\n }\n if (res.value !== true) return ok(false);\n\n // classifyName reverts on a label shape the registrar rejects, so a\n // failure here is surfaced rather than folded into `false`.\n if (!classified.success) {\n return err(\n new DotNsError(\"RegistryCall\", \"PopRules.classifyName call failed\", {\n cause: classified.value,\n }),\n );\n }\n const { requirement } = classified.value as { requirement: number; message: string };\n return ok(requirement !== POP_STATUS.Reserved);\n } catch (cause) {\n return err(\n new DotNsError(\"RegistryCall\", `DotNS availability check failed for \"${normalized}\"`, {\n cause,\n }),\n );\n }\n}\n\n// ── Writes ───────────────────────────────────────────────────────────\n//\n// Writes return prepared calls (`BatchableCall`) the caller submits with their\n// own signer via `@parity/product-sdk-tx` — the surface stays signer-free, like\n// the reads. Registration is a two-transaction commit-reveal, so it can't be a\n// single call; `prepareDotNsRegistration` returns both plus the timing window.\n\n/**\n * Prepare the calls binding a name to an address. Submit them in order with the\n * owner's signer via `batchSubmitAndWatch`; both are owner-gated.\n *\n * Returns two calls when the node still points at the reverse resolver (the\n * post-registration default): `registry.setResolver` first, or the record\n * written by `setAddress` is real but unreadable. One call once it is pointed.\n */\nexport async function setDotNsRecord(\n args: SetRecordArgs,\n opts: DotNsClientOptions,\n): Promise<Result<BatchableCall[], DotNsError>> {\n const tldRes = await resolveTld(opts);\n if (!tldRes.ok) return tldRes;\n const tld = tldRes.value;\n const normalized = normalizeDotNsName(args.name, tld.suffix);\n if (!isResolvableDotNsName(normalized, tld.suffix)) {\n return err(nameError(args.name, normalized, tld));\n }\n // Both calls are owner-gated, so a dry-run from the fallback account would\n // revert and the error would look like a contract problem.\n const origin = opts.origin;\n if (!origin) {\n return err(new DotNsError(\"MissingOrigin\", \"setDotNsRecord needs opts.origin (SS58)\"));\n }\n const node = namehash(normalized, tld);\n const addrs = await resolveDotNsAddresses(opts);\n if (!addrs.ok) return addrs;\n const registryAddr = addrs.value.registry;\n const resolverAddr = addrs.value.resolver;\n try {\n const registry = contractOf(opts.runtime, registryAddr as HexString, DOTNS_REGISTRY_ABI);\n const currentRes = await registry.resolver.query(node, { origin });\n if (!currentRes.success) {\n return err(\n new DotNsError(\"RegistryCall\", \"registry.resolver call failed\", {\n cause: currentRes.value,\n }),\n );\n }\n\n const calls: BatchableCall[] = [];\n if (!sameAddress(currentRes.value, resolverAddr)) {\n const pointer = await registry.setResolver.prepare(node, resolverAddr, { origin });\n if (!pointer.ok) {\n return err(\n new DotNsError(\"RegistryCall\", \"registry.setResolver prepare failed\", {\n cause: pointer.error,\n }),\n );\n }\n calls.push(pointer.value as BatchableCall);\n }\n\n const resolver = contractOf(\n opts.runtime,\n resolverAddr as HexString,\n DOTNS_RESOLVER_WRITE_ABI,\n );\n const prepared = await resolver.setAddress.prepare(node, args.address, { origin });\n if (!prepared.ok) {\n return err(\n new DotNsError(\"RegistryCall\", \"resolver.setAddress prepare failed\", {\n cause: prepared.error,\n }),\n );\n }\n calls.push(prepared.value as BatchableCall);\n\n return ok(calls);\n } catch (cause) {\n return err(new DotNsError(\"RegistryCall\", \"DotNS setRecord failed\", { cause }));\n }\n}\n\n/** The prepared pieces of a DotNS registration. */\nexport interface DotNsRegistration {\n /** The random secret bound into both commit and register. */\n secret: HexString;\n /** The commitment hash (also encoded inside `commitCall`). */\n commitment: HexString;\n /** Submit first, with the owner's signer. */\n commitCall: BatchableCall;\n /** Seconds to wait after `commit` before `register` is accepted. */\n minCommitmentAge: bigint;\n /** Seconds after which the commitment expires and `register` is rejected. */\n maxCommitmentAge: bigint;\n /** Quote at prepare time, for display. The submitted value is re-read below. */\n price: bigint;\n /**\n * Build the register call, once `minCommitmentAge` has elapsed.\n *\n * Deferred rather than returned up front: `register` consumes the\n * commitment, so dry-running it before `commitCall` lands reverts with\n * `CommitmentNotFound` and no call could be built at all. Deferring also\n * prices and sizes it against the state it will actually execute in.\n */\n prepareRegisterCall: () => Promise<Result<BatchableCall, DotNsError>>;\n}\n\n/** What `register` will charge, and whether it will accept the owner at all. */\nasync function quoteRegistration(\n popRules: ReturnType<typeof contractOf>,\n label: string,\n owner: string,\n payer: string,\n origin: SS58String,\n): Promise<Result<bigint, DotNsError>> {\n // `price(label)` is not what register charges: it skips every eligibility\n // rule and ignores the owner. The owner-aware variant reports the same\n // classification register applies, without reverting on it.\n const quote = await popRules.priceWithoutCheck.query(label, owner, { origin });\n if (!quote.success) {\n return err(\n new DotNsError(\"RegistryCall\", \"PopRules.priceWithoutCheck failed\", {\n cause: quote.value,\n }),\n );\n }\n const { price, status, userStatus, message } = quote.value as {\n price: bigint;\n status: number;\n userStatus: number;\n message: string;\n };\n if (status === POP_STATUS.Reserved) {\n return err(new DotNsError(\"NameReserved\", `\"${label}\" is reserved: ${message}`));\n }\n if (userStatus < status) {\n return err(\n new DotNsError(\n \"OwnerStatusInsufficient\",\n `\"${label}\" requires personhood tier ${status}, owner has ${userStatus}: ${message}`,\n ),\n );\n }\n\n // Cross-payer registrations add a friction floor; register charges the\n // larger of the two.\n if (sameAddress(payer, owner)) return ok(BigInt(price));\n const floor = await popRules.transferFloor.query(label, payer, owner, { origin });\n if (!floor.success) {\n return err(\n new DotNsError(\"RegistryCall\", \"PopRules.transferFloor failed\", {\n cause: floor.value,\n }),\n );\n }\n const friction = BigInt(floor.value as string | number | bigint);\n const base = BigInt(price);\n return ok(base > friction ? base : friction);\n}\n\n/**\n * Prepare a DotNS registration: the commit call, the shared secret, the timing\n * window, and a thunk that builds the register call afterwards.\n *\n * 1. submit `commitCall`\n * 2. wait `minCommitmentAge`, and register before `maxCommitmentAge`\n * 3. `await prepareRegisterCall()`, then submit what it returns\n *\n * Eligibility is checked here, before the caller pays for the commit: a\n * governance-reserved label, or an owner below the tier the label requires,\n * fails now rather than on the second transaction.\n */\nexport async function prepareDotNsRegistration(\n args: RegisterDotNsArgs,\n opts: DotNsClientOptions,\n): Promise<Result<DotNsRegistration, DotNsError>> {\n const tldRes = await resolveTld(opts);\n if (!tldRes.ok) return tldRes;\n const tld = tldRes.value;\n const normalized = normalizeDotNsName(args.name, tld.suffix);\n if (!isValidDotNsName(normalized, tld.suffix)) {\n return err(nameError(args.name, normalized, tld));\n }\n const origin = opts.origin;\n if (!origin) {\n return err(\n new DotNsError(\"MissingOrigin\", \"prepareDotNsRegistration needs opts.origin (SS58)\"),\n );\n }\n // The registrar takes the bare label, without the TLD suffix.\n const label = stripSuffix(normalized, tld.suffix);\n const addrs = await resolveDotNsAddresses(opts);\n if (!addrs.ok) return addrs;\n const controllerAddr = addrs.value.registrarController;\n const popRulesAddr = addrs.value.popRules;\n const secret = `0x${bytesToHex(randomBytes(32))}` as HexString;\n const registration = { label, owner: args.owner, secret, reserved: args.reserved ?? false };\n // register compares msg.sender against the owner; msg.sender is derived\n // from the SS58 origin, so derive it the same way to predict the branch.\n // ss58ToH160 throws on an undecodable address, and this sits outside the\n // try below, so guard it here rather than letting it escape the Result.\n let payer: HexString;\n try {\n payer = ss58ToH160(origin);\n } catch (cause) {\n return err(\n new DotNsError(\"InvalidOrigin\", `opts.origin is not a valid SS58 address: ${origin}`, {\n cause,\n }),\n );\n }\n\n try {\n const controller = contractOf(\n opts.runtime,\n controllerAddr as HexString,\n DOTNS_REGISTRAR_CONTROLLER_ABI,\n );\n const popRules = contractOf(opts.runtime, popRulesAddr as HexString, DOTNS_POP_RULES_ABI);\n\n const [commitmentRes, availableRes, quote, minRes, maxRes] = await Promise.all([\n controller.makeCommitment.query(registration, { origin }),\n controller.available.query(label, { origin }),\n quoteRegistration(popRules, label, args.owner, payer, origin),\n controller.minCommitmentAge.query({ origin }),\n controller.maxCommitmentAge.query({ origin }),\n ]);\n // `register` runs _requireAvailableLabel before anything else, so a\n // taken name costs the caller a commit fee and then reverts.\n if (!availableRes.success) {\n return err(\n new DotNsError(\"RegistryCall\", \"registrarController.available call failed\", {\n cause: availableRes.value,\n }),\n );\n }\n if (availableRes.value !== true) {\n return err(new DotNsError(\"NameUnavailable\", `\"${label}\" is already registered`));\n }\n if (!commitmentRes.success) {\n return err(\n new DotNsError(\"RegistryCall\", \"makeCommitment failed\", {\n cause: commitmentRes.value,\n }),\n );\n }\n if (!quote.ok) return quote;\n if (!minRes.success || !maxRes.success) {\n return err(\n new DotNsError(\"RegistryCall\", \"commitment window read failed\", {\n cause: minRes.success ? maxRes.value : minRes.value,\n }),\n );\n }\n const commitment = commitmentRes.value as HexString;\n\n const commitPrep = await controller.commit.prepare(commitment, { origin });\n if (!commitPrep.ok) {\n return err(\n new DotNsError(\"RegistryCall\", \"controller.commit prepare failed\", {\n cause: commitPrep.error,\n }),\n );\n }\n\n return ok({\n secret,\n commitment,\n commitCall: commitPrep.value as BatchableCall,\n minCommitmentAge: BigInt(minRes.value as string | number),\n maxCommitmentAge: BigInt(maxRes.value as string | number),\n price: quote.value,\n prepareRegisterCall: async () => {\n // Re-quoted, not reused: the price and the owner's tier can both\n // move during the mandatory wait.\n const current = await quoteRegistration(popRules, label, args.owner, payer, origin);\n if (!current.ok) return current;\n const prep = await controller.register.prepare(registration, {\n value: current.value,\n origin,\n });\n if (!prep.ok) {\n return err(\n new DotNsError(\"RegistryCall\", \"controller.register prepare failed\", {\n cause: prep.error,\n }),\n );\n }\n return ok(prep.value as BatchableCall);\n },\n });\n } catch (cause) {\n return err(new DotNsError(\"RegistryCall\", \"DotNS registration prepare failed\", { cause }));\n }\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { LogEntry, LogHandler, LogLevel, Logger, LoggerConfig, configure, createLogger } from '@parity/product-sdk-logger';
|
|
2
|
-
import { c as AppConfig, b as App } from './types-
|
|
3
|
-
export { A as Account, C as ChainApi, a as CloudStorageApi, D as DotNsIdentitySignature, L as LocalStorageApi, S as SignMessageWithDotNsIdentityArgs, W as WalletApi } from './types-
|
|
2
|
+
import { c as AppConfig, b as App } from './types-CRYPRNYk.js';
|
|
3
|
+
export { A as Account, C as ChainApi, a as CloudStorageApi, D as DotNsIdentitySignature, L as LocalStorageApi, S as SignMessageWithDotNsIdentityArgs, W as WalletApi } from './types-CRYPRNYk.js';
|
|
4
4
|
export { Result, err, isErrorOf, ok } from '@parity/result';
|
|
5
5
|
export { SdkError, isSdkError } from '@parity/product-sdk-errors';
|
|
6
6
|
export { isInsideContainer, isInsideContainerSync } from '@parity/product-sdk-host';
|
|
@@ -9,7 +9,7 @@ export { SignerManager } from '@parity/product-sdk-signer';
|
|
|
9
9
|
export { createLocalKvStore } from '@parity/product-sdk-local-storage';
|
|
10
10
|
export { CloudStorageClient, calculateCid } from '@parity/product-sdk-cloud-storage';
|
|
11
11
|
export { ChainDefinition, PolkadotClient, TypedApi } from 'polkadot-api';
|
|
12
|
-
import './dotns-
|
|
12
|
+
import './dotns-CtmOwVQW.js';
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* createApp - Main entry point for the Product SDK
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { configure, createLogger } from './chunk-JVJ552RU.js';
|
|
2
|
-
export { createApp } from './chunk-
|
|
3
|
-
import './chunk-
|
|
2
|
+
export { createApp } from './chunk-JIO3OZSC.js';
|
|
3
|
+
import './chunk-7GM3HUZF.js';
|
|
4
4
|
export { err, isErrorOf, ok } from '@parity/result';
|
|
5
5
|
export { isSdkError } from '@parity/product-sdk-errors';
|
|
6
6
|
export { isInsideContainer, isInsideContainerSync } from '@parity/product-sdk-host';
|
package/dist/react/index.d.ts
CHANGED
|
@@ -2,12 +2,12 @@ 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 { b as App, S as SignMessageWithDotNsIdentityArgs, D as DotNsIdentitySignature, A as Account } from '../types-
|
|
5
|
+
import { b as App, S as SignMessageWithDotNsIdentityArgs, D as DotNsIdentitySignature, A as Account } from '../types-CRYPRNYk.js';
|
|
6
6
|
import { ChainDefinition, TypedApi } from 'polkadot-api';
|
|
7
7
|
import '@parity/product-sdk-cloud-storage';
|
|
8
8
|
import '@parity/result';
|
|
9
9
|
import '@parity/product-sdk-chain-client';
|
|
10
|
-
import '../dotns-
|
|
10
|
+
import '../dotns-CtmOwVQW.js';
|
|
11
11
|
|
|
12
12
|
/** Props for ProductSDKProvider */
|
|
13
13
|
interface ProductSDKProviderProps {
|
package/dist/react/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { createApp } from '../chunk-
|
|
2
|
-
import '../chunk-
|
|
1
|
+
import { createApp } from '../chunk-JIO3OZSC.js';
|
|
2
|
+
import '../chunk-7GM3HUZF.js';
|
|
3
3
|
import { createContext, useContext, useState, useEffect, useCallback, useMemo } from 'react';
|
|
4
4
|
import { jsx, Fragment } from 'react/jsx-runtime';
|
|
5
5
|
|
package/dist/testing/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as Account, L as LocalStorageApi, C as ChainApi, a as CloudStorageApi, b as App } from '../types-
|
|
1
|
+
import { A as Account, L as LocalStorageApi, C as ChainApi, a as CloudStorageApi, b as App } from '../types-CRYPRNYk.js';
|
|
2
2
|
export * from '@parity/product-sdk-local-storage/testing';
|
|
3
3
|
export * from '@parity/product-sdk-signer/testing';
|
|
4
4
|
export * from '@parity/product-sdk-contracts/testing';
|
|
@@ -7,7 +7,7 @@ import '@parity/product-sdk-logger';
|
|
|
7
7
|
import '@parity/product-sdk-cloud-storage';
|
|
8
8
|
import '@parity/result';
|
|
9
9
|
import '@parity/product-sdk-chain-client';
|
|
10
|
-
import '../dotns-
|
|
10
|
+
import '../dotns-CtmOwVQW.js';
|
|
11
11
|
import 'polkadot-api';
|
|
12
12
|
|
|
13
13
|
/** Configurable behavior for the fake {@link WalletApi}. */
|
|
@@ -2,7 +2,7 @@ import { LogLevel } from '@parity/product-sdk-logger';
|
|
|
2
2
|
import { ProductCloudStorageError, CloudStorageEnvironment } from '@parity/product-sdk-cloud-storage';
|
|
3
3
|
import { Result } from '@parity/result';
|
|
4
4
|
import { ChainClient } from '@parity/product-sdk-chain-client';
|
|
5
|
-
import { P as PeopleUsernameChain } from './dotns-
|
|
5
|
+
import { P as PeopleUsernameChain } from './dotns-CtmOwVQW.js';
|
|
6
6
|
import { ChainDefinition, TypedApi, PolkadotClient } from 'polkadot-api';
|
|
7
7
|
|
|
8
8
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parity/product-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.0",
|
|
4
4
|
"description": "Unified SDK for building products in the Polkadot ecosystem - umbrella package",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -71,20 +71,20 @@
|
|
|
71
71
|
],
|
|
72
72
|
"dependencies": {
|
|
73
73
|
"polkadot-api": "^2.1.6",
|
|
74
|
-
"@parity/product-sdk-
|
|
75
|
-
"@parity/product-sdk-
|
|
76
|
-
"@parity/product-sdk-
|
|
77
|
-
"@parity/product-sdk-
|
|
74
|
+
"@parity/product-sdk-contracts": "0.10.4",
|
|
75
|
+
"@parity/product-sdk-address": "0.2.0",
|
|
76
|
+
"@parity/product-sdk-chain-client": "0.12.0",
|
|
77
|
+
"@parity/product-sdk-cloud-storage": "0.11.0",
|
|
78
78
|
"@parity/product-sdk-crypto": "0.1.1",
|
|
79
|
-
"@parity/product-sdk-
|
|
80
|
-
"@parity/product-sdk-
|
|
81
|
-
"@parity/product-sdk-keys": "0.3.
|
|
82
|
-
"@parity/product-sdk-logger": "0.1.1",
|
|
79
|
+
"@parity/product-sdk-individuality": "0.2.0",
|
|
80
|
+
"@parity/product-sdk-host": "0.17.0",
|
|
81
|
+
"@parity/product-sdk-keys": "0.3.21",
|
|
83
82
|
"@parity/product-sdk-errors": "0.2.0",
|
|
83
|
+
"@parity/product-sdk-logger": "0.1.1",
|
|
84
84
|
"@parity/result": "0.2.0",
|
|
85
|
-
"@parity/product-sdk-signer": "0.
|
|
86
|
-
"@parity/product-sdk-tx": "0.4.
|
|
87
|
-
"@parity/product-sdk-local-storage": "0.3.
|
|
85
|
+
"@parity/product-sdk-signer": "0.14.1",
|
|
86
|
+
"@parity/product-sdk-tx": "0.4.4",
|
|
87
|
+
"@parity/product-sdk-local-storage": "0.3.6"
|
|
88
88
|
},
|
|
89
89
|
"peerDependencies": {
|
|
90
90
|
"react": "^18.0.0 || ^19.0.0"
|
package/src/core/createApp.ts
CHANGED
|
@@ -32,9 +32,10 @@ import {
|
|
|
32
32
|
isConnected,
|
|
33
33
|
destroyAll,
|
|
34
34
|
} from "@parity/product-sdk-chain-client";
|
|
35
|
+
import { accountIdBytes } from "@parity/product-sdk-address";
|
|
35
36
|
import { getAccountsProvider } from "@parity/product-sdk-host";
|
|
36
37
|
import {
|
|
37
|
-
|
|
38
|
+
accountIdBytesToHex,
|
|
38
39
|
type PeopleUsernameQueryApi,
|
|
39
40
|
resolvePeopleUsernameOwner,
|
|
40
41
|
} from "../identity/dotns.js";
|
|
@@ -321,16 +322,17 @@ function createWalletApi(signerManager: SignerManager): WalletApi {
|
|
|
321
322
|
const peopleApi = peopleClient.getTypedApi(
|
|
322
323
|
args.peopleChain,
|
|
323
324
|
) as unknown as PeopleUsernameQueryApi;
|
|
324
|
-
const
|
|
325
|
-
if (!
|
|
325
|
+
const owner = await resolvePeopleUsernameOwner(username, peopleApi);
|
|
326
|
+
if (!owner) {
|
|
326
327
|
throw new Error(`No account owns DotNS username "${username}"`);
|
|
327
328
|
}
|
|
328
329
|
|
|
329
|
-
const
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
330
|
+
const publicKey = accountIdBytes(owner);
|
|
331
|
+
// This field is hex, not the SS58 the resolver now returns. Converted
|
|
332
|
+
// here and not in the try, so an address failure is not reported as a
|
|
333
|
+
// signing failure.
|
|
334
|
+
const accountId = accountIdBytesToHex(publicKey);
|
|
335
|
+
const signer = accountsProvider.getLegacyAccountSigner({ publicKey, name: username });
|
|
334
336
|
|
|
335
337
|
try {
|
|
336
338
|
return {
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// Copyright 2026 Parity Technologies (UK) Ltd.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
//
|
|
4
|
+
// Guards on the transcribed deployment table. These check the shape of the
|
|
5
|
+
// table, not that it names the live deployment: only a diff against
|
|
6
|
+
// `paritytech/dotns` `deployments/paseo-assethub/420420417.json` can do that,
|
|
7
|
+
// and it is a network fetch. See the comment on DOTNS_ADDRESSES for the
|
|
8
|
+
// commit the values were copied from, and re-check it when bumping.
|
|
9
|
+
import { isValidH160 } from "@parity/product-sdk-address";
|
|
10
|
+
import { describe, expect, test } from "vitest";
|
|
11
|
+
import { DOTNS_ADDRESSES } from "./dotns-abis.js";
|
|
12
|
+
|
|
13
|
+
describe("DOTNS_ADDRESSES", () => {
|
|
14
|
+
test("every entry is a well-formed H160", () => {
|
|
15
|
+
for (const [name, address] of Object.entries(DOTNS_ADDRESSES)) {
|
|
16
|
+
expect(isValidH160(address), `${name} = ${address}`).toBe(true);
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test("no two entries share an address", () => {
|
|
21
|
+
// Six addresses transcribed by hand: a duplicated paste is the
|
|
22
|
+
// transcription error most likely to go unnoticed, because the wrong
|
|
23
|
+
// contract still answers and only the decode looks odd.
|
|
24
|
+
const entries = Object.entries(DOTNS_ADDRESSES);
|
|
25
|
+
const seen = new Map<string, string>();
|
|
26
|
+
for (const [name, address] of entries) {
|
|
27
|
+
const key = address.toLowerCase();
|
|
28
|
+
expect(seen.get(key), `${name} duplicates ${seen.get(key)}`).toBeUndefined();
|
|
29
|
+
seen.set(key, name);
|
|
30
|
+
}
|
|
31
|
+
expect(seen.size).toBe(entries.length);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test("the resolver and the reverse resolver are different contracts", () => {
|
|
35
|
+
// Load-bearing beyond general distinctness: resolveDotNs decides whether
|
|
36
|
+
// a node has a forward record by comparing the registry's resolver
|
|
37
|
+
// pointer against the reverse resolver, so collapsing these two would
|
|
38
|
+
// make every registered name look resolvable.
|
|
39
|
+
expect(DOTNS_ADDRESSES.resolver.toLowerCase()).not.toBe(
|
|
40
|
+
DOTNS_ADDRESSES.reverseResolver.toLowerCase(),
|
|
41
|
+
);
|
|
42
|
+
});
|
|
43
|
+
});
|