Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2d6a9ad1b3
|
||
|
|
18105d3ced
|
||
|
|
f2a1ab3a72
|
||
|
|
ec1399f3f3
|
@@ -13,3 +13,11 @@ logFilters:
|
||||
nodeLinker: node-modules
|
||||
|
||||
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/"
|
||||
|
||||
@@ -42,6 +42,9 @@
|
||||
"react-native": "^0.73.1"
|
||||
},
|
||||
"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"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,13 +17,13 @@
|
||||
"./packageDetect.cjs"
|
||||
],
|
||||
"type": "module",
|
||||
"version": "3.16.7",
|
||||
"version": "3.16.7-quantus.2",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@polkadot/keyring": "^14.0.3",
|
||||
"@polkadot/keyring": "14.0.3-quantus.2",
|
||||
"@polkadot/ui-settings": "3.16.7",
|
||||
"@polkadot/util": "^14.0.3",
|
||||
"@polkadot/util-crypto": "^14.0.3",
|
||||
"@polkadot/util-crypto": "14.0.3-quantus.2",
|
||||
"mkdirp": "^3.0.1",
|
||||
"rxjs": "^7.8.1",
|
||||
"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');
|
||||
});
|
||||
});
|
||||
@@ -11,7 +11,7 @@ import type { CreateResult, KeyringAddress, KeyringAddressType, KeyringItemType,
|
||||
import { createPair } from '@polkadot/keyring';
|
||||
import { chains } from '@polkadot/ui-settings';
|
||||
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 { KeyringOption } from './options/index.js';
|
||||
@@ -327,11 +327,29 @@ export class Keyring extends Base implements KeyringStruct {
|
||||
}
|
||||
|
||||
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 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(
|
||||
{ toSS58: this.encodeAddress, type: cryptoType as KeypairType },
|
||||
{ publicKey: this.decodeAddress(json.address, true) },
|
||||
{ toSS58: this.encodeAddress, type: cryptoType },
|
||||
isDilithium(cryptoType)
|
||||
? { accountId: raw, publicKey: new Uint8Array(), secretKey: new Uint8Array() }
|
||||
: { publicKey: raw },
|
||||
json.meta,
|
||||
isHex(json.encoded) ? hexToU8a(json.encoded) : base64Decode(json.encoded),
|
||||
encType
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// 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' };
|
||||
|
||||
@@ -1596,28 +1596,29 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@polkadot/keyring@npm:^14.0.3":
|
||||
version: 14.0.3
|
||||
resolution: "@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-quantus.2
|
||||
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:
|
||||
"@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"
|
||||
peerDependencies:
|
||||
"@polkadot/util": 14.0.3
|
||||
"@polkadot/util-crypto": 14.0.3
|
||||
checksum: 10/69f9f776363f8327d72b43794262ae709fc2824182637e499ed6e9ca94315645d78005bf1f25bdfb7305e5d79879cb932c114e6612467ddf21a760117834e8a2
|
||||
checksum: 10/e3885d6a75b4c006887d24dadbfc25fff562baae84d42fd2125878af60daecbf789deed12c975edfef0884a3caff4dd469dcdcd8b63eacbd1a5fbf8bbfe48815
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@polkadot/networks@npm:14.0.3, @polkadot/networks@npm:^14.0.3":
|
||||
version: 14.0.3
|
||||
resolution: "@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-quantus.2
|
||||
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:
|
||||
"@polkadot/util": "npm:14.0.3"
|
||||
"@substrate/ss58-registry": "npm:^1.51.0"
|
||||
tslib: "npm:^2.8.0"
|
||||
checksum: 10/eb006f537f103b0d417e52966d0098b528326d1ebbae84e4c7834627bb3e863b7b849856992aa58c4a0aeb0ed1e1838a9619aeba7610d0e7c75e99ffcc6c9ecd
|
||||
checksum: 10/3d2f0a08cde4be418d073f63587bed451a6ce4c91a8872a5e0c4191ff3e62d57a7942c1a1b6c183ed9c22742f5b95b7496fe4e32e3565baf2093d879ac51a55e
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -1691,10 +1692,10 @@ __metadata:
|
||||
version: 0.0.0-use.local
|
||||
resolution: "@polkadot/ui-keyring@workspace:packages/ui-keyring"
|
||||
dependencies:
|
||||
"@polkadot/keyring": "npm:^14.0.3"
|
||||
"@polkadot/keyring": "npm:14.0.3-quantus.2"
|
||||
"@polkadot/ui-settings": "npm:3.16.7"
|
||||
"@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/store": "npm:^2.0.5"
|
||||
mkdirp: "npm:^3.0.1"
|
||||
@@ -1740,24 +1741,25 @@ __metadata:
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
"@polkadot/util-crypto@npm:14.0.3, @polkadot/util-crypto@npm:^14.0.3":
|
||||
version: 14.0.3
|
||||
resolution: "@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-quantus.2
|
||||
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:
|
||||
"@noble/curves": "npm:^1.3.0"
|
||||
"@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/wasm-crypto": "npm:^7.5.3"
|
||||
"@polkadot/wasm-util": "npm:^7.5.3"
|
||||
"@polkadot/x-bigint": "npm:14.0.3"
|
||||
"@polkadot/x-randomvalues": "npm:14.0.3"
|
||||
"@quantus/crypto": "npm:^0.1.0"
|
||||
"@scure/base": "npm:^1.1.7"
|
||||
"@scure/sr25519": "npm:^0.2.0"
|
||||
tslib: "npm:^2.8.0"
|
||||
peerDependencies:
|
||||
"@polkadot/util": 14.0.3
|
||||
checksum: 10/e8f2da806cb81d3c014415bdd633f0fc5871132ce790ca892f65899010386d64fa25f7c047574cc96402afa03b5ff77e4dff904e69b90e714a7150e18ef0f507
|
||||
checksum: 10/78f04147ddfe8ae0bca4cba2f235715615a140de9ab95f10d6e4bbabee4a2865e6f8a84f70668722ab688094a8519eeb019ed5122620b355a3ea40b0d8cfdeb8
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -1936,6 +1938,16 @@ __metadata:
|
||||
languageName: node
|
||||
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":
|
||||
version: 12.3.0
|
||||
resolution: "@react-native-community/cli-clean@npm:12.3.0"
|
||||
@@ -6436,6 +6448,13 @@ __metadata:
|
||||
languageName: node
|
||||
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":
|
||||
version: 3.2.0
|
||||
resolution: "figures@npm:3.2.0"
|
||||
|
||||
Reference in New Issue
Block a user