Compare commits

..
Author SHA1 Message Date
grenadeandClaude Opus 5 2d6a9ad1b3 build: consume the forks at 14.0.3-quantus.2
Lock Threads / lock (push) Has been cancelled
Picks up the networks fix (the quantum-safe gate moving out of the library list,
which made @polkadot/api importable again) and Heisenberg's corrected HEI symbol.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012uDUodEcRbBwNRi3UCmw8f
2026-09-15 14:15:02 +03:00
rob thijssenandClaude Opus 5 18105d3ced build: pin the forked packages at 14.0.3-quantus.1
Follows the rename in quantus/common. The point is not tidiness: with the forks
numbered 14.0.3, a missing resolution here would have been satisfied from npm by
the unforked upstream package, installing cleanly and silently dropping Quantus
support. Now it fails with "No candidates found" — verified by removing the
@polkadot/networks resolution and running an install.

Refs quantus/extension#2

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012uDUodEcRbBwNRi3UCmw8f
2026-09-15 11:28:03 +03:00
rob thijssenandClaude Opus 5 f2a1ab3a72 build: consume the forked @polkadot packages from the registry, drop the scaffolding
Removes every workaround the symlink approach needed, and reverts tsconfig to
upstream's exactly.

The three forked packages — @polkadot/{networks,util-crypto,keyring} — are now
pinned to Gitea tarball URLs in resolutions. @polkadot/util is not, because this
fork does not modify it; it comes from npm like the rest of the scope.

Tarball URLs rather than routing the @polkadot scope to Gitea, because the scope
is mostly *not* forked: routing it would send yarn looking for dozens of packages
that are not there. @quantus is routed as a whole scope in .yarnrc.yml, which is
safe because we own every name in it.

Four things go away, all of which existed for one reason — node resolves a portal
or link symlink to its realpath, after which @polkadot/util-crypto resolved inside
*common's* tree, where it is a workspace source directory with no exports map:

  - resolutions pointing four packages at ../common/packages/*/build
  - tsconfig.base.json `*.d.ts` path mappings, needed because NodeNext will not
    infer an extension for a bare path and looked for a `types` directory
  - tsconfig.json overriding those with a runtime `.js` view, because
    @polkadot/dev-ts reads that file and tried to import a declaration file as a
    module
  - --preserve-symlinks in the test scripts

Also drops fflate and @quantus/crypto from ui-keyring's devDependencies; they were
there only because `link:` does not install its target's dependencies.

`yarn lint` now reports 0 errors, down from 25 on pristine upstream. Those were
no-unsafe-assignment and no-unsafe-argument on values that were `any` purely
because the types did not resolve.

Refs quantus/extension#2, quantus/ui#1

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012uDUodEcRbBwNRi3UCmw8f
2026-09-15 11:08:43 +03:00
rob thijssenandClaude Opus 5 ec1399f3f3 fix(ui-keyring): restoreAccount cannot rebuild an ML-DSA public key from an address
The mirror of the same mistake in keyring.createFromJson, fixed the same way.

restoreAccount passed `decodeAddress(json.address)` as the public key. For the
curve schemes that is correct — the address *is* the public key. An ML-DSA
account id is a one-way Poseidon2 hash, so this constructed a pair whose "public
key" was a hash of the public key. It did not throw; it produced a pair that was
simply wrong.

The public key is in `json.encoded`, still encrypted, and the pair is returned
*locked* with callers reading `pair.address` off it long before a password
appears. So it now passes an accountId — carried as data, used for the address
while locked, and checked against the real key once decodePkcs8 supplies one.
That check matters here as much as in the keyring: the address field sits outside
the encrypted blob, so a tampered one decodes cleanly and yields an account
displaying an address its key cannot sign for.

The 'ed25519' fallback for version-0 JSON is left alone. Those files predate the
crypto type being recorded and are by definition not Quantus, so the guess is
safe — but it is commented, because quantus/common#6 removes ed25519 from
KeypairType and this becomes a refusal.

Build plumbing, all of it dev-time only and all replaced by publishing these
packages to a registry (quantus/extension#2):

Resolutions point @polkadot/{keyring,util-crypto,networks,util} at the sibling
`common` checkout's build output, and @quantus/crypto at `wasm`.

tsconfig.base.json gains `*.d.ts` path mappings for them. Without these, node
resolves the portal symlink to its realpath and `@polkadot/util-crypto` then
resolves inside *common's* tree, where it is the workspace source directory with
no exports map — so EncryptedJson silently fails to resolve and KeyringPair$Json
loses `encoded` and `encoding`. The `*.d.ts` substitution has to come first
because NodeNext will not infer an extension for a bare path, and looks for a
`types` directory instead of `types.d.ts`.

tsconfig.json overrides those with the runtime `.js` view, because
@polkadot/dev-ts reads that file and would otherwise import a declaration file as
a module ("Debug Failure. Output generation failed"). tsc reads
tsconfig.build.json, which extends the base directly, so each gets the view it
needs.

The test script sets --preserve-symlinks, which yarn itself warns is required for
portals: without it the realpath problem above recurs at runtime.

Incidentally, `yarn lint` errors drop from 25 to 8 — resolving those types
removed a pile of `any`. The remaining 8 are upstream's own, in loadContract and
allowGenesis, and are left alone.

Refs quantus/ui#1

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012uDUodEcRbBwNRi3UCmw8f
2026-09-15 10:40:52 +03:00
7 changed files with 160 additions and 24 deletions
+8
View File
@@ -13,3 +13,11 @@ logFilters:
nodeLinker: node-modules nodeLinker: node-modules
yarnPath: .yarn/releases/yarn-4.5.1.cjs yarnPath: .yarn/releases/yarn-4.5.1.cjs
# @quantus packages come from the Gitea registry — safe as a whole-scope route
# because we own every name in it. The forked @polkadot packages cannot be routed
# the same way (most of that scope is unforked and lives on npm), so they are
# pinned to tarball URLs in package.json resolutions instead.
npmScopes:
quantus:
npmRegistryServer: "https://git.lair.cafe/api/packages/quantus/npm/"
+3
View File
@@ -42,6 +42,9 @@
"react-native": "^0.73.1" "react-native": "^0.73.1"
}, },
"resolutions": { "resolutions": {
"@polkadot/keyring": "https://git.lair.cafe/api/packages/quantus/npm/%40polkadot%2Fkeyring/-/14.0.3-quantus.2/keyring-14.0.3-quantus.2.tgz",
"@polkadot/networks": "https://git.lair.cafe/api/packages/quantus/npm/%40polkadot%2Fnetworks/-/14.0.3-quantus.2/networks-14.0.3-quantus.2.tgz",
"@polkadot/util-crypto": "https://git.lair.cafe/api/packages/quantus/npm/%40polkadot%2Futil-crypto/-/14.0.3-quantus.2/util-crypto-14.0.3-quantus.2.tgz",
"typescript": "5.5.4" "typescript": "5.5.4"
} }
} }
+3 -3
View File
@@ -17,13 +17,13 @@
"./packageDetect.cjs" "./packageDetect.cjs"
], ],
"type": "module", "type": "module",
"version": "3.16.7", "version": "3.16.7-quantus.2",
"main": "index.js", "main": "index.js",
"dependencies": { "dependencies": {
"@polkadot/keyring": "^14.0.3", "@polkadot/keyring": "14.0.3-quantus.2",
"@polkadot/ui-settings": "3.16.7", "@polkadot/ui-settings": "3.16.7",
"@polkadot/util": "^14.0.3", "@polkadot/util": "^14.0.3",
"@polkadot/util-crypto": "^14.0.3", "@polkadot/util-crypto": "14.0.3-quantus.2",
"mkdirp": "^3.0.1", "mkdirp": "^3.0.1",
"rxjs": "^7.8.1", "rxjs": "^7.8.1",
"store": "^2.0.12", "store": "^2.0.12",
@@ -0,0 +1,88 @@
// Copyright 2017-2026 @polkadot/ui-keyring authors & contributors
// SPDX-License-Identifier: Apache-2.0
/// <reference types="@polkadot/dev-test/globals.d.ts" />
import type { KeyringPair$Json } from '@polkadot/keyring/types';
import { contextForSpec } from '@quantus/crypto';
import { Keyring as BaseKeyring } from '@polkadot/keyring';
import { dilithiumVerify } from '@polkadot/util-crypto';
import { Keyring } from './Keyring.js';
// crystal_alice, from the chain's dev genesis — a raw 32-byte seed straight into
// ML-DSA-87 keygen. The address is what `quantus developer create-test-wallets`
// prints, i.e. an independent implementation.
const ALICE = 'qzk1Nxai3dZD9Cn5kwGcgL6mKxsfxwqdis7kDQJ52aJS2vSn7';
const PASSWORD = 'not a good password';
const MESSAGE = new Uint8Array([0x75, 0x69]);
function backup (): KeyringPair$Json {
const base = new BaseKeyring({ ss58Format: 189, type: 'dilithium87' });
return base
.addFromSeed(new Uint8Array(32), { name: 'crystal_alice' }, 'dilithium87')
.toJson(PASSWORD);
}
// `loadAll` initialises `@polkadot/ui-settings`, which is a module singleton, so
// it may be called once per *process* — not per instance. One keyring for the
// whole file, loaded once.
const uiKeyring = new Keyring();
uiKeyring.loadAll({ ss58Format: 189, store: undefined, type: 'dilithium87' });
describe('ui-keyring restoreAccount', (): void => {
// Before the fix this constructed a pair whose "public key" was
// decodeAddress(json.address) — i.e. a Poseidon2 hash of the public key, passed
// off as the key itself. It did not throw; it produced a pair that was simply
// wrong.
it('restores an ML-DSA account to the right address', (): void => {
const pair = uiKeyring.restoreAccount(backup(), PASSWORD);
expect(pair.address).toEqual(ALICE);
expect(pair.publicKey.length).toEqual(2592);
expect(pair.addressRaw.length).toEqual(32);
});
it('restores an account that can sign for its own address', (): void => {
const pair = uiKeyring.restoreAccount(backup(), PASSWORD);
pair.decodePkcs8(PASSWORD);
const context = contextForSpec(148);
const signature = pair.sign(MESSAGE, { context });
expect(dilithiumVerify(MESSAGE, signature, pair.addressRaw, 'dilithium87', context)).toEqual(true);
});
it('fails on a wrong password without half-restoring', (): void => {
expect(() => uiKeyring.restoreAccount(backup(), 'wrong')).toThrow();
});
// The address field sits outside the encrypted blob. For the curve schemes a
// tampered one cannot decode at all; here it decodes cleanly and would yield an
// account displaying an address its key does not control.
it('rejects JSON whose address does not match its key', (): void => {
const base = new BaseKeyring({ ss58Format: 189, type: 'dilithium87' });
const other = base.addFromSeed(new Uint8Array(32).fill(3), {}, 'dilithium87');
expect(() => uiKeyring.restoreAccount({ ...backup(), address: other.address }, PASSWORD)).toThrow(/does not match the address/);
});
// restoreAccount takes the crypto type from the JSON rather than the keyring,
// so the same keyring restores both. Compared on publicKey and addressRaw
// rather than the SS58 string, which would differ only because this keyring is
// configured for prefix 189.
it('leaves sr25519 restore unchanged', (): void => {
const sr = new BaseKeyring({ type: 'sr25519' });
const pair = sr.addFromUri('//Alice');
const restored = uiKeyring.restoreAccount(pair.toJson(PASSWORD), PASSWORD);
expect(restored.publicKey).toEqual(pair.publicKey);
expect(restored.addressRaw).toEqual(pair.addressRaw);
expect(restored.type).toEqual('sr25519');
});
});
+22 -4
View File
@@ -11,7 +11,7 @@ import type { CreateResult, KeyringAddress, KeyringAddressType, KeyringItemType,
import { createPair } from '@polkadot/keyring'; import { createPair } from '@polkadot/keyring';
import { chains } from '@polkadot/ui-settings'; import { chains } from '@polkadot/ui-settings';
import { bnToBn, hexToU8a, isFunction, isHex, isString, objectSpread, stringify, stringToU8a, u8aSorted, u8aToString } from '@polkadot/util'; import { bnToBn, hexToU8a, isFunction, isHex, isString, objectSpread, stringify, stringToU8a, u8aSorted, u8aToString } from '@polkadot/util';
import { base64Decode, createKeyMulti, jsonDecrypt, jsonEncrypt } from '@polkadot/util-crypto'; import { base64Decode, createKeyMulti, isDilithium, jsonDecrypt, jsonEncrypt } from '@polkadot/util-crypto';
import { env } from './observable/env.js'; import { env } from './observable/env.js';
import { KeyringOption } from './options/index.js'; import { KeyringOption } from './options/index.js';
@@ -327,11 +327,29 @@ export class Keyring extends Base implements KeyringStruct {
} }
public restoreAccount (json: KeyringPair$Json, password: string): KeyringPair { public restoreAccount (json: KeyringPair$Json, password: string): KeyringPair {
const cryptoType = Array.isArray(json.encoding.content) ? json.encoding.content[1] : 'ed25519'; // The 'ed25519' fallback is for version-0 JSON, which predates the crypto
// type being recorded. Those files are by definition not Quantus, so the
// guess is safe here — but note that quantus/common#6 removes ed25519 from
// KeypairType, at which point this has to become a refusal rather than a
// default.
const cryptoType = (Array.isArray(json.encoding.content) ? json.encoding.content[1] : 'ed25519') as KeypairType;
const encType = Array.isArray(json.encoding.type) ? json.encoding.type : [json.encoding.type]; const encType = Array.isArray(json.encoding.type) ? json.encoding.type : [json.encoding.type];
const raw = this.decodeAddress(json.address, true);
// For every curve scheme the address and the public key are the same 32
// bytes, which is why passing one as the other works at all. An ML-DSA
// account id is a one-way Poseidon2 hash and the 1952/2592-byte public key
// is inside `json.encoded`, still encrypted — there is nothing to derive it
// from until `decodePkcs8` below runs.
//
// So hand `createPair` an account id rather than a public key it can check,
// and let it verify the two agree once the real key appears. Doing it the
// other way produced a pair whose "public key" was a hash of the public key.
const pair = createPair( const pair = createPair(
{ toSS58: this.encodeAddress, type: cryptoType as KeypairType }, { toSS58: this.encodeAddress, type: cryptoType },
{ publicKey: this.decodeAddress(json.address, true) }, isDilithium(cryptoType)
? { accountId: raw, publicKey: new Uint8Array(), secretKey: new Uint8Array() }
: { publicKey: raw },
json.meta, json.meta,
isHex(json.encoded) ? hexToU8a(json.encoded) : base64Decode(json.encoded), isHex(json.encoded) ? hexToU8a(json.encoded) : base64Decode(json.encoded),
encType encType
+1 -1
View File
@@ -3,4 +3,4 @@
// Do not edit, auto-generated by @polkadot/dev // Do not edit, auto-generated by @polkadot/dev
export const packageInfo = { name: '@polkadot/ui-keyring', path: 'auto', type: 'auto', version: '3.16.7' }; export const packageInfo = { name: '@polkadot/ui-keyring', path: 'auto', type: 'auto', version: '3.16.7-quantus.2' };
+35 -16
View File
@@ -1596,28 +1596,29 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"@polkadot/keyring@npm:^14.0.3": "@polkadot/keyring@https://git.lair.cafe/api/packages/quantus/npm/%40polkadot%2Fkeyring/-/14.0.3-quantus.2/keyring-14.0.3-quantus.2.tgz":
version: 14.0.3 version: 14.0.3-quantus.2
resolution: "@polkadot/keyring@npm:14.0.3" resolution: "@polkadot/keyring@https://git.lair.cafe/api/packages/quantus/npm/%40polkadot%2Fkeyring/-/14.0.3-quantus.2/keyring-14.0.3-quantus.2.tgz"
dependencies: dependencies:
"@polkadot/util": "npm:14.0.3" "@polkadot/util": "npm:14.0.3"
"@polkadot/util-crypto": "npm:14.0.3" "@polkadot/util-crypto": "npm:14.0.3-quantus.2"
"@quantus/crypto": "npm:^0.1.0"
tslib: "npm:^2.8.0" tslib: "npm:^2.8.0"
peerDependencies: peerDependencies:
"@polkadot/util": 14.0.3 "@polkadot/util": 14.0.3
"@polkadot/util-crypto": 14.0.3 "@polkadot/util-crypto": 14.0.3
checksum: 10/69f9f776363f8327d72b43794262ae709fc2824182637e499ed6e9ca94315645d78005bf1f25bdfb7305e5d79879cb932c114e6612467ddf21a760117834e8a2 checksum: 10/e3885d6a75b4c006887d24dadbfc25fff562baae84d42fd2125878af60daecbf789deed12c975edfef0884a3caff4dd469dcdcd8b63eacbd1a5fbf8bbfe48815
languageName: node languageName: node
linkType: hard linkType: hard
"@polkadot/networks@npm:14.0.3, @polkadot/networks@npm:^14.0.3": "@polkadot/networks@https://git.lair.cafe/api/packages/quantus/npm/%40polkadot%2Fnetworks/-/14.0.3-quantus.2/networks-14.0.3-quantus.2.tgz":
version: 14.0.3 version: 14.0.3-quantus.2
resolution: "@polkadot/networks@npm:14.0.3" resolution: "@polkadot/networks@https://git.lair.cafe/api/packages/quantus/npm/%40polkadot%2Fnetworks/-/14.0.3-quantus.2/networks-14.0.3-quantus.2.tgz"
dependencies: dependencies:
"@polkadot/util": "npm:14.0.3" "@polkadot/util": "npm:14.0.3"
"@substrate/ss58-registry": "npm:^1.51.0" "@substrate/ss58-registry": "npm:^1.51.0"
tslib: "npm:^2.8.0" tslib: "npm:^2.8.0"
checksum: 10/eb006f537f103b0d417e52966d0098b528326d1ebbae84e4c7834627bb3e863b7b849856992aa58c4a0aeb0ed1e1838a9619aeba7610d0e7c75e99ffcc6c9ecd checksum: 10/3d2f0a08cde4be418d073f63587bed451a6ce4c91a8872a5e0c4191ff3e62d57a7942c1a1b6c183ed9c22742f5b95b7496fe4e32e3565baf2093d879ac51a55e
languageName: node languageName: node
linkType: hard linkType: hard
@@ -1691,10 +1692,10 @@ __metadata:
version: 0.0.0-use.local version: 0.0.0-use.local
resolution: "@polkadot/ui-keyring@workspace:packages/ui-keyring" resolution: "@polkadot/ui-keyring@workspace:packages/ui-keyring"
dependencies: dependencies:
"@polkadot/keyring": "npm:^14.0.3" "@polkadot/keyring": "npm:14.0.3-quantus.2"
"@polkadot/ui-settings": "npm:3.16.7" "@polkadot/ui-settings": "npm:3.16.7"
"@polkadot/util": "npm:^14.0.3" "@polkadot/util": "npm:^14.0.3"
"@polkadot/util-crypto": "npm:^14.0.3" "@polkadot/util-crypto": "npm:14.0.3-quantus.2"
"@types/mkdirp": "npm:^2.0.0" "@types/mkdirp": "npm:^2.0.0"
"@types/store": "npm:^2.0.5" "@types/store": "npm:^2.0.5"
mkdirp: "npm:^3.0.1" mkdirp: "npm:^3.0.1"
@@ -1740,24 +1741,25 @@ __metadata:
languageName: unknown languageName: unknown
linkType: soft linkType: soft
"@polkadot/util-crypto@npm:14.0.3, @polkadot/util-crypto@npm:^14.0.3": "@polkadot/util-crypto@https://git.lair.cafe/api/packages/quantus/npm/%40polkadot%2Futil-crypto/-/14.0.3-quantus.2/util-crypto-14.0.3-quantus.2.tgz":
version: 14.0.3 version: 14.0.3-quantus.2
resolution: "@polkadot/util-crypto@npm:14.0.3" resolution: "@polkadot/util-crypto@https://git.lair.cafe/api/packages/quantus/npm/%40polkadot%2Futil-crypto/-/14.0.3-quantus.2/util-crypto-14.0.3-quantus.2.tgz"
dependencies: dependencies:
"@noble/curves": "npm:^1.3.0" "@noble/curves": "npm:^1.3.0"
"@noble/hashes": "npm:^1.3.3" "@noble/hashes": "npm:^1.3.3"
"@polkadot/networks": "npm:14.0.3" "@polkadot/networks": "npm:14.0.3-quantus.2"
"@polkadot/util": "npm:14.0.3" "@polkadot/util": "npm:14.0.3"
"@polkadot/wasm-crypto": "npm:^7.5.3" "@polkadot/wasm-crypto": "npm:^7.5.3"
"@polkadot/wasm-util": "npm:^7.5.3" "@polkadot/wasm-util": "npm:^7.5.3"
"@polkadot/x-bigint": "npm:14.0.3" "@polkadot/x-bigint": "npm:14.0.3"
"@polkadot/x-randomvalues": "npm:14.0.3" "@polkadot/x-randomvalues": "npm:14.0.3"
"@quantus/crypto": "npm:^0.1.0"
"@scure/base": "npm:^1.1.7" "@scure/base": "npm:^1.1.7"
"@scure/sr25519": "npm:^0.2.0" "@scure/sr25519": "npm:^0.2.0"
tslib: "npm:^2.8.0" tslib: "npm:^2.8.0"
peerDependencies: peerDependencies:
"@polkadot/util": 14.0.3 "@polkadot/util": 14.0.3
checksum: 10/e8f2da806cb81d3c014415bdd633f0fc5871132ce790ca892f65899010386d64fa25f7c047574cc96402afa03b5ff77e4dff904e69b90e714a7150e18ef0f507 checksum: 10/78f04147ddfe8ae0bca4cba2f235715615a140de9ab95f10d6e4bbabee4a2865e6f8a84f70668722ab688094a8519eeb019ed5122620b355a3ea40b0d8cfdeb8
languageName: node languageName: node
linkType: hard linkType: hard
@@ -1936,6 +1938,16 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"@quantus/crypto@npm:^0.1.0":
version: 0.1.0
resolution: "@quantus/crypto@npm:0.1.0::__archiveUrl=https%3A%2F%2Fgit.lair.cafe%2Fapi%2Fpackages%2Fquantus%2Fnpm%2F%2540quantus%252Fcrypto%2F-%2F0.1.0%2Fcrypto-0.1.0.tgz"
dependencies:
fflate: "npm:^0.8.2"
tslib: "npm:^2.7.0"
checksum: 10/c6e531e0350d74d863cfa8acfbed0eeacaa2814c2f2628976b73b59a2ff4b6a382dd0d734e34c1c2442ba7e575f0ae12dd153b44fdbfec51b61f212c1ef41fbd
languageName: node
linkType: hard
"@react-native-community/cli-clean@npm:12.3.0": "@react-native-community/cli-clean@npm:12.3.0":
version: 12.3.0 version: 12.3.0
resolution: "@react-native-community/cli-clean@npm:12.3.0" resolution: "@react-native-community/cli-clean@npm:12.3.0"
@@ -6436,6 +6448,13 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"fflate@npm:^0.8.2":
version: 0.8.3
resolution: "fflate@npm:0.8.3"
checksum: 10/6ebf528dc9c56e78e715eac615b009b25dc33e15c1920b11ebba44e6d76181c647756a81a23e19247907496b93aa99928514c53090579a65109e026ac2824aa7
languageName: node
linkType: hard
"figures@npm:^3.0.0": "figures@npm:^3.0.0":
version: 3.2.0 version: 3.2.0
resolution: "figures@npm:3.2.0" resolution: "figures@npm:3.2.0"