@parity/product-sdk 0.22.0 → 0.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/dist/chunk-BRZNHTLQ.js +89 -0
  2. package/dist/chunk-BRZNHTLQ.js.map +1 -0
  3. package/dist/{chunk-6BI66XUJ.js → chunk-DHRCWMY5.js} +9 -10
  4. package/dist/chunk-DHRCWMY5.js.map +1 -0
  5. package/dist/core/index.d.ts +2 -2
  6. package/dist/core/index.js +2 -2
  7. package/dist/dotns-bswWAmR2.d.ts +136 -0
  8. package/dist/identity/index.d.ts +502 -45
  9. package/dist/identity/index.js +800 -32
  10. package/dist/identity/index.js.map +1 -1
  11. package/dist/index.d.ts +3 -3
  12. package/dist/index.js +2 -2
  13. package/dist/react/index.d.ts +2 -2
  14. package/dist/react/index.js +2 -2
  15. package/dist/testing/index.d.ts +2 -2
  16. package/dist/{types-DTgyMIi0.d.ts → types-B5Zx4RNq.d.ts} +1 -1
  17. package/package.json +10 -10
  18. package/src/core/createApp.ts +10 -8
  19. package/src/identity/dotns-abis.test.ts +43 -0
  20. package/src/identity/dotns-abis.ts +309 -0
  21. package/src/identity/dotns-addresses.test.ts +536 -0
  22. package/src/identity/dotns-addresses.ts +320 -0
  23. package/src/identity/dotns-errors.ts +36 -0
  24. package/src/identity/dotns-namehash.test.ts +155 -0
  25. package/src/identity/dotns-namehash.ts +149 -0
  26. package/src/identity/dotns-owner.test.ts +92 -0
  27. package/src/identity/dotns-registry.test.ts +1309 -0
  28. package/src/identity/dotns-registry.ts +868 -0
  29. package/src/identity/dotns.test.ts +128 -0
  30. package/src/identity/dotns.ts +91 -78
  31. package/src/identity/index.test.ts +43 -0
  32. package/src/identity/index.ts +40 -10
  33. package/src/identity/types.ts +29 -25
  34. package/src/individuality/contract.test.ts +272 -2
  35. package/dist/chunk-6BI66XUJ.js.map +0 -1
  36. package/dist/chunk-BIKT6X54.js +0 -70
  37. package/dist/chunk-BIKT6X54.js.map +0 -1
  38. package/dist/dotns-DIaptENj.d.ts +0 -167
  39. package/src/identity/product-account.test.ts +0 -129
  40. package/src/identity/product-account.ts +0 -115
@@ -1,129 +0,0 @@
1
- // Copyright 2026 Parity Technologies (UK) Ltd.
2
- // SPDX-License-Identifier: Apache-2.0
3
- /**
4
- * Frozen vectors for the deprecated context-alias helpers.
5
- *
6
- * These pin current behaviour so the deprecation cannot silently alter the
7
- * derivation. Never re-derive: a caller may use the value as a plain
8
- * identifier, where different output bytes would be a silent break.
9
- */
10
- import { ss58Decode, ss58Encode } from "@parity/product-sdk-address";
11
- import { blake2b256 } from "@parity/product-sdk-crypto";
12
- import { describe, expect, it } from "vitest";
13
- import * as identity from "./index.js";
14
- import { deriveContextAlias, verifyContextAlias } from "./product-account.js";
15
-
16
- const ALICE = "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY";
17
- const CONTEXT = "voting-round-1";
18
-
19
- /** Recomputes the documented formula from primitives, independent of the implementation. */
20
- function expectedAliasPublicKey(parentAddress: string, context: string): Uint8Array {
21
- const { publicKey } = ss58Decode(parentAddress);
22
- const contextBytes = new TextEncoder().encode(context);
23
- const combined = new Uint8Array(publicKey.length + contextBytes.length);
24
- combined.set(publicKey, 0);
25
- combined.set(contextBytes, publicKey.length);
26
- return blake2b256(combined);
27
- }
28
-
29
- describe("deriveContextAlias", () => {
30
- it("returns blake2b256(parentPublicKey || context), encoded at the given prefix", () => {
31
- const alias = deriveContextAlias(ALICE, CONTEXT);
32
- const expected = expectedAliasPublicKey(ALICE, CONTEXT);
33
-
34
- expect(alias.address).toBe(ss58Encode(expected, 42));
35
- });
36
-
37
- it("matches a frozen vector for a known parent and context", () => {
38
- const alias = deriveContextAlias(ALICE, CONTEXT);
39
-
40
- expect(alias.address).toBe("5GPTdhxkG9wNKhCSN1vZrCwrf3fwvAf4j487vqrkVzvRMH6F");
41
- expect(alias.h160Address).toBe("0x93d10a91de267ba79b27fbec373e5a3b2e86a283");
42
- expect(alias.parentAddress).toBe(ALICE);
43
- expect(alias.context).toBe(CONTEXT);
44
- });
45
-
46
- it("defaults to ss58 prefix 42", () => {
47
- expect(deriveContextAlias(ALICE, CONTEXT).address).toBe(
48
- deriveContextAlias(ALICE, CONTEXT, 42).address,
49
- );
50
- });
51
-
52
- it("changes only the encoding when the ss58 prefix changes, not the key", () => {
53
- const at42 = deriveContextAlias(ALICE, CONTEXT, 42);
54
- const at0 = deriveContextAlias(ALICE, CONTEXT, 0);
55
-
56
- expect(at0.address).not.toBe(at42.address);
57
- expect(Array.from(ss58Decode(at0.address).publicKey)).toEqual(
58
- Array.from(ss58Decode(at42.address).publicKey),
59
- );
60
- });
61
-
62
- it("derives a different alias for a different context", () => {
63
- expect(deriveContextAlias(ALICE, "round-1").address).not.toBe(
64
- deriveContextAlias(ALICE, "round-2").address,
65
- );
66
- });
67
- });
68
-
69
- describe("verifyContextAlias", () => {
70
- it("accepts an alias derived from the same parent and context", () => {
71
- const alias = deriveContextAlias(ALICE, CONTEXT);
72
-
73
- expect(verifyContextAlias(alias.address, ALICE, CONTEXT)).toBe(true);
74
- });
75
-
76
- it("rejects a different context", () => {
77
- const alias = deriveContextAlias(ALICE, CONTEXT);
78
-
79
- expect(verifyContextAlias(alias.address, ALICE, "voting-round-2")).toBe(false);
80
- });
81
-
82
- it("rejects a different parent", () => {
83
- const alias = deriveContextAlias(ALICE, CONTEXT);
84
- const bob = "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty";
85
-
86
- expect(verifyContextAlias(alias.address, bob, CONTEXT)).toBe(false);
87
- });
88
-
89
- it("returns false rather than throwing on an undecodable address", () => {
90
- expect(verifyContextAlias("not-an-address", ALICE, CONTEXT)).toBe(false);
91
- });
92
-
93
- // Guards the byte-level comparison: `addressesEqual` from
94
- // @parity/product-sdk-address compares SS58 strings exactly and would
95
- // return false here, silently narrowing behaviour.
96
- it("compares public keys, so it accepts an alias encoded at another prefix", () => {
97
- const alias = deriveContextAlias(ALICE, CONTEXT, 42);
98
- const reencoded = ss58Encode(ss58Decode(alias.address).publicKey, 0);
99
-
100
- expect(reencoded).not.toBe(alias.address);
101
- expect(verifyContextAlias(reencoded, ALICE, CONTEXT)).toBe(true);
102
- });
103
- });
104
-
105
- describe("the identity export surface", () => {
106
- // These threw on every call, so no working consumer could exist. Deleting
107
- // turns a guaranteed runtime throw into a compile error.
108
- it("no longer exports the unimplemented ring helpers", () => {
109
- for (const name of ["deriveAnonymousAlias", "createRingProof", "verifyRingProof"]) {
110
- expect(name in identity).toBe(false);
111
- }
112
- });
113
-
114
- it("still exports the DotNS helpers and the deprecated context-alias pair", () => {
115
- for (const name of [
116
- "resolveDotNs",
117
- "reverseDotNs",
118
- "isDotNsAvailable",
119
- "resolvePeopleUsernameOwner",
120
- "isValidDotNsName",
121
- "normalizeDotNsName",
122
- "accountIdHexToBytes",
123
- "deriveContextAlias",
124
- "verifyContextAlias",
125
- ]) {
126
- expect(name in identity).toBe(true);
127
- }
128
- });
129
- });
@@ -1,115 +0,0 @@
1
- // Copyright 2026 Parity Technologies (UK) Ltd.
2
- // SPDX-License-Identifier: Apache-2.0
3
- /**
4
- * Context alias derivation (deprecated, removal in 0.23.0)
5
- *
6
- * Derives a deterministic, context-bound alias from a parent account using blake2b-256.
7
- *
8
- * The output is a hash, not a key, so no signing key exists for the addresses
9
- * returned here. See the notes on each function for what to use instead.
10
- *
11
- * NOTE: this is NOT the canonical sr25519 product-account derivation used by
12
- * mobile, desktop, and dotli hosts. For that, use
13
- * `@parity/product-sdk-keys::deriveProductAccountPublicKey`.
14
- */
15
-
16
- import { createLogger } from "@parity/product-sdk-logger";
17
- import { blake2b256 } from "@parity/product-sdk-crypto";
18
- import { ss58Encode, ss58Decode, deriveH160 } from "@parity/product-sdk-address";
19
- import type { ContextAliasInfo } from "./types.js";
20
-
21
- const log = createLogger("identity");
22
-
23
- /**
24
- * Derive a context-bound alias from a parent account.
25
- *
26
- * The alias is deterministically derived using:
27
- * aliasPublicKey = blake2b256(parentPublicKey || context)
28
- *
29
- * @deprecated Returns addresses that no key can spend. The alias public key is a
30
- * blake2b-256 hash rather than a derived key, so no secret corresponds to the
31
- * SS58 address or to the H160: both can receive value and neither can ever
32
- * send it. Removal: `@parity/product-sdk` 0.23.0. Replace by intent:
33
- *
34
- * - An account that holds or spends value:
35
- * `SignerManager.getProductAccount(dotNsIdentifier, index)` from
36
- * `@parity/product-sdk-signer`. Host-backed and actually signable.
37
- * - The address offline, with no host: `deriveProductAccountPublicKey` from
38
- * `@parity/product-sdk-keys`, the canonical sr25519 soft derivation.
39
- * - An unlinkable per-context alias: select a registered ring-VRF key, then call
40
- * `SignerManager.getProductAccountAlias(keyHandle, context, location)` or
41
- * `createRingVRFProof(keyHandle, context, location, message)`.
42
- * - A context-scoped identifier, never used as an account: `blake2b256` from
43
- * `@parity/product-sdk/crypto`. Same bytes, without address packaging that
44
- * invites the mistake.
45
- *
46
- * @param parentAddress - Parent account SS58 address
47
- * @param context - Context string for derivation (e.g. an app id or scope label)
48
- * @param ss58Prefix - SS58 prefix (default: 42)
49
- * @returns Context alias info
50
- */
51
- export function deriveContextAlias(
52
- parentAddress: string,
53
- context: string,
54
- ss58Prefix = 42,
55
- ): ContextAliasInfo {
56
- const { publicKey: parentPublicKey } = ss58Decode(parentAddress);
57
-
58
- // Derive alias public key: blake2b-256(parentPublicKey || context)
59
- const contextBytes = new TextEncoder().encode(context);
60
- const combined = new Uint8Array(parentPublicKey.length + contextBytes.length);
61
- combined.set(parentPublicKey, 0);
62
- combined.set(contextBytes, parentPublicKey.length);
63
-
64
- const aliasPublicKey = blake2b256(combined);
65
- const address = ss58Encode(aliasPublicKey, ss58Prefix);
66
- const h160Address = deriveH160(aliasPublicKey);
67
-
68
- log.debug("Derived context alias", {
69
- parentAddress,
70
- context,
71
- address,
72
- });
73
-
74
- return {
75
- address,
76
- h160Address,
77
- parentAddress,
78
- context,
79
- };
80
- }
81
-
82
- /**
83
- * Verify that a context alias was derived from a parent account.
84
- *
85
- * @deprecated Recomputes {@link deriveContextAlias} from two public values and
86
- * compares the result, so it confirms a derivation relationship and nothing
87
- * more. No secret enters the operation at any point, which means there is
88
- * nothing here to authenticate: a passing result does not show that anyone
89
- * controls either account. Removal: `@parity/product-sdk` 0.23.0.
90
- *
91
- * @param aliasAddress - Context alias SS58 address
92
- * @param parentAddress - Claimed parent address
93
- * @param context - Context string used for derivation
94
- * @returns True if derivation is valid
95
- */
96
- export function verifyContextAlias(
97
- aliasAddress: string,
98
- parentAddress: string,
99
- context: string,
100
- ): boolean {
101
- try {
102
- const derived = deriveContextAlias(parentAddress, context);
103
- const { publicKey: aliasKey } = ss58Decode(aliasAddress);
104
- const { publicKey: derivedKey } = ss58Decode(derived.address);
105
-
106
- // Compare public keys
107
- if (aliasKey.length !== derivedKey.length) return false;
108
- for (let i = 0; i < aliasKey.length; i++) {
109
- if (aliasKey[i] !== derivedKey[i]) return false;
110
- }
111
- return true;
112
- } catch {
113
- return false;
114
- }
115
- }