Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
160d97c19b
|
||
|
|
c7c23b7958
|
+3
-3
@@ -42,9 +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",
|
||||
"@polkadot/keyring": "https://git.lair.cafe/api/packages/quantus/npm/%40polkadot%2Fkeyring/-/14.0.3-quantus.3/keyring-14.0.3-quantus.3.tgz",
|
||||
"@polkadot/networks": "https://git.lair.cafe/api/packages/quantus/npm/%40polkadot%2Fnetworks/-/14.0.3-quantus.3/networks-14.0.3-quantus.3.tgz",
|
||||
"@polkadot/util-crypto": "https://git.lair.cafe/api/packages/quantus/npm/%40polkadot%2Futil-crypto/-/14.0.3-quantus.3/util-crypto-14.0.3-quantus.3.tgz",
|
||||
"typescript": "5.5.4"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,19 +17,20 @@
|
||||
"./packageDetect.cjs"
|
||||
],
|
||||
"type": "module",
|
||||
"version": "3.16.7-quantus.2",
|
||||
"version": "3.16.7-quantus.3",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@polkadot/keyring": "14.0.3-quantus.2",
|
||||
"@polkadot/keyring": "14.0.3-quantus.3",
|
||||
"@polkadot/ui-settings": "3.16.7",
|
||||
"@polkadot/util": "^14.0.3",
|
||||
"@polkadot/util-crypto": "14.0.3-quantus.2",
|
||||
"@polkadot/util-crypto": "14.0.3-quantus.3",
|
||||
"mkdirp": "^3.0.1",
|
||||
"rxjs": "^7.8.1",
|
||||
"store": "^2.0.12",
|
||||
"tslib": "^2.8.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@quantus/crypto": "^0.3.0",
|
||||
"@types/mkdirp": "^2.0.0",
|
||||
"@types/store": "^2.0.5"
|
||||
},
|
||||
|
||||
@@ -125,8 +125,9 @@ export class Base {
|
||||
this.setDevMode(options.isDevelopment);
|
||||
}
|
||||
|
||||
// set Ethereum state
|
||||
this.#isEthereum = keyring.type === 'ethereum';
|
||||
// Never Ethereum: the keyring holds only ML-DSA keys (quantus/common#6). Kept
|
||||
// as a property so callers written against upstream still read a boolean.
|
||||
this.#isEthereum = false;
|
||||
|
||||
this.#keyring = keyring;
|
||||
this._genesisHash = options.genesisHash && (
|
||||
|
||||
@@ -72,17 +72,23 @@ describe('ui-keyring restoreAccount', (): void => {
|
||||
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);
|
||||
// quantus/common#6: a backup of a quantum-unsafe key is refused with the
|
||||
// reason, not decoded. This is the JSON a polkadot{.js} export of an ed25519
|
||||
// account carries.
|
||||
it('refuses a polkadot{.js} backup of a quantum-unsafe key, saying why', (): void => {
|
||||
const json = {
|
||||
address: '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY',
|
||||
encoded: '0x00',
|
||||
encoding: { content: ['pkcs8', 'sr25519'], type: ['scrypt', 'xsalsa20-poly1305'], version: '3' },
|
||||
meta: { name: 'polkadot account' }
|
||||
} as unknown as KeyringPair$Json;
|
||||
|
||||
expect(restored.publicKey).toEqual(pair.publicKey);
|
||||
expect(restored.addressRaw).toEqual(pair.addressRaw);
|
||||
expect(restored.type).toEqual('sr25519');
|
||||
expect(() => uiKeyring.restoreAccount(json, PASSWORD)).toThrow(/sr25519 keys are not quantum-safe and cannot be held here/);
|
||||
});
|
||||
|
||||
it('refuses a file that does not record its key type', (): void => {
|
||||
const json = { ...backup(), encoding: { content: 'pkcs8', type: 'none', version: '0' } } as unknown as KeyringPair$Json;
|
||||
|
||||
expect(() => uiKeyring.restoreAccount(json, PASSWORD)).toThrow(/does not record its key type/);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -8,10 +8,9 @@ import type { KeypairType } from '@polkadot/util-crypto/types';
|
||||
import type { AddressSubject, SingleAddress } from './observable/types.js';
|
||||
import type { CreateResult, KeyringAddress, KeyringAddressType, KeyringItemType, KeyringJson, KeyringJson$Meta, KeyringOptions, KeyringPairs$Json, KeyringStruct } from './types.js';
|
||||
|
||||
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, isDilithium, jsonDecrypt, jsonEncrypt } from '@polkadot/util-crypto';
|
||||
import { createKeyMulti, jsonDecrypt, jsonEncrypt } from '@polkadot/util-crypto';
|
||||
|
||||
import { env } from './observable/env.js';
|
||||
import { KeyringOption } from './options/index.js';
|
||||
@@ -21,7 +20,7 @@ import { accountKey, accountRegex, addressKey, addressRegex, contractKey, contra
|
||||
const RECENT_EXPIRY = 24 * 60 * 60;
|
||||
|
||||
// No accounts (or test accounts) should be loaded until after the chain determination.
|
||||
// Chain determination occurs outside of Keyring. Loading `keyring.loadAll({ type: 'ed25519' | 'sr25519' })` is triggered
|
||||
// Chain determination occurs outside of Keyring. Loading `keyring.loadAll({ type: 'dilithium65' | 'dilithium87' })` is triggered
|
||||
// from the API after the chain is received
|
||||
export class Keyring extends Base implements KeyringStruct {
|
||||
public readonly keyringOption = new KeyringOption();
|
||||
@@ -327,33 +326,18 @@ export class Keyring extends Base implements KeyringStruct {
|
||||
}
|
||||
|
||||
public restoreAccount (json: KeyringPair$Json, password: string): KeyringPair {
|
||||
// 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);
|
||||
// Version-0 JSON predates recording the key type, so it cannot be an ML-DSA
|
||||
// account. Upstream guessed ed25519; this keyring cannot hold one.
|
||||
if (!Array.isArray(json.encoding.content)) {
|
||||
throw new Error('This account file does not record its key type, so it is not an ML-DSA account and cannot be restored here');
|
||||
}
|
||||
|
||||
// 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 },
|
||||
isDilithium(cryptoType)
|
||||
? { accountId: raw, publicKey: new Uint8Array(), secretKey: new Uint8Array() }
|
||||
: { publicKey: raw },
|
||||
json.meta,
|
||||
isHex(json.encoded) ? hexToU8a(json.encoded) : base64Decode(json.encoded),
|
||||
encType
|
||||
);
|
||||
// Through the keyring rather than createPair directly, so a restore gets the
|
||||
// same refusal as every other entry point: a polkadot{.js} backup of an
|
||||
// sr25519 or ed25519 account is told it is not quantum-safe, not decoded.
|
||||
// createFromJson also carries the address as an account id until the real
|
||||
// public key is decrypted, and checks the two agree when it is.
|
||||
const pair = this.keyring.createFromJson(json, true);
|
||||
|
||||
// unlock, save account and then lock (locking cleans secretKey, so needs to be last)
|
||||
pair.decodePkcs8(password);
|
||||
|
||||
@@ -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-quantus.2' };
|
||||
export const packageInfo = { name: '@polkadot/ui-keyring', path: 'auto', type: 'auto', version: '3.16.7-quantus.3' };
|
||||
|
||||
@@ -1596,29 +1596,29 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@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"
|
||||
"@polkadot/keyring@https://git.lair.cafe/api/packages/quantus/npm/%40polkadot%2Fkeyring/-/14.0.3-quantus.3/keyring-14.0.3-quantus.3.tgz":
|
||||
version: 14.0.3-quantus.3
|
||||
resolution: "@polkadot/keyring@https://git.lair.cafe/api/packages/quantus/npm/%40polkadot%2Fkeyring/-/14.0.3-quantus.3/keyring-14.0.3-quantus.3.tgz"
|
||||
dependencies:
|
||||
"@polkadot/util": "npm:14.0.3"
|
||||
"@polkadot/util-crypto": "npm:14.0.3-quantus.2"
|
||||
"@quantus/crypto": "npm:^0.1.0"
|
||||
"@polkadot/util-crypto": "npm:14.0.3-quantus.3"
|
||||
"@quantus/crypto": "npm:^0.3.0"
|
||||
tslib: "npm:^2.8.0"
|
||||
peerDependencies:
|
||||
"@polkadot/util": 14.0.3
|
||||
"@polkadot/util-crypto": 14.0.3
|
||||
checksum: 10/e3885d6a75b4c006887d24dadbfc25fff562baae84d42fd2125878af60daecbf789deed12c975edfef0884a3caff4dd469dcdcd8b63eacbd1a5fbf8bbfe48815
|
||||
checksum: 10/2264245c4fc2505c852d5a874bda2fcd86a1269cb6545f7bb578a6efdf58beea3deccf28d27ba6e41f9fdf9a8ea50cf230c626b69afe775a7629e069149164f7
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@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"
|
||||
"@polkadot/networks@https://git.lair.cafe/api/packages/quantus/npm/%40polkadot%2Fnetworks/-/14.0.3-quantus.3/networks-14.0.3-quantus.3.tgz":
|
||||
version: 14.0.3-quantus.3
|
||||
resolution: "@polkadot/networks@https://git.lair.cafe/api/packages/quantus/npm/%40polkadot%2Fnetworks/-/14.0.3-quantus.3/networks-14.0.3-quantus.3.tgz"
|
||||
dependencies:
|
||||
"@polkadot/util": "npm:14.0.3"
|
||||
"@substrate/ss58-registry": "npm:^1.51.0"
|
||||
tslib: "npm:^2.8.0"
|
||||
checksum: 10/3d2f0a08cde4be418d073f63587bed451a6ce4c91a8872a5e0c4191ff3e62d57a7942c1a1b6c183ed9c22742f5b95b7496fe4e32e3565baf2093d879ac51a55e
|
||||
checksum: 10/04228325c8472901fc04e5570e6d3450539c4ee51bbbae5c6eea945c721dc86b4bd9a581503e9f65c0132317ecc3c915b7f2c4cc2774b169f49d6eb2524bd8c2
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -1692,10 +1692,11 @@ __metadata:
|
||||
version: 0.0.0-use.local
|
||||
resolution: "@polkadot/ui-keyring@workspace:packages/ui-keyring"
|
||||
dependencies:
|
||||
"@polkadot/keyring": "npm:14.0.3-quantus.2"
|
||||
"@polkadot/keyring": "npm:14.0.3-quantus.3"
|
||||
"@polkadot/ui-settings": "npm:3.16.7"
|
||||
"@polkadot/util": "npm:^14.0.3"
|
||||
"@polkadot/util-crypto": "npm:14.0.3-quantus.2"
|
||||
"@polkadot/util-crypto": "npm:14.0.3-quantus.3"
|
||||
"@quantus/crypto": "npm:^0.3.0"
|
||||
"@types/mkdirp": "npm:^2.0.0"
|
||||
"@types/store": "npm:^2.0.5"
|
||||
mkdirp: "npm:^3.0.1"
|
||||
@@ -1741,25 +1742,25 @@ __metadata:
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
"@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"
|
||||
"@polkadot/util-crypto@https://git.lair.cafe/api/packages/quantus/npm/%40polkadot%2Futil-crypto/-/14.0.3-quantus.3/util-crypto-14.0.3-quantus.3.tgz":
|
||||
version: 14.0.3-quantus.3
|
||||
resolution: "@polkadot/util-crypto@https://git.lair.cafe/api/packages/quantus/npm/%40polkadot%2Futil-crypto/-/14.0.3-quantus.3/util-crypto-14.0.3-quantus.3.tgz"
|
||||
dependencies:
|
||||
"@noble/curves": "npm:^1.3.0"
|
||||
"@noble/hashes": "npm:^1.3.3"
|
||||
"@polkadot/networks": "npm:14.0.3-quantus.2"
|
||||
"@polkadot/networks": "npm:14.0.3-quantus.3"
|
||||
"@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"
|
||||
"@quantus/crypto": "npm:^0.3.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/78f04147ddfe8ae0bca4cba2f235715615a140de9ab95f10d6e4bbabee4a2865e6f8a84f70668722ab688094a8519eeb019ed5122620b355a3ea40b0d8cfdeb8
|
||||
checksum: 10/ffbbb1a45a45abf51376276674e223b1adbbb9355b8881811c558d428ca84e6d07370d11ff07329cf5c32032b4c710a955b84c02462b6c4f0dc52b5f1117e17e
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -1938,13 +1939,13 @@ __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"
|
||||
"@quantus/crypto@npm:^0.3.0":
|
||||
version: 0.3.0
|
||||
resolution: "@quantus/crypto@npm:0.3.0::__archiveUrl=https%3A%2F%2Fgit.lair.cafe%2Fapi%2Fpackages%2Fquantus%2Fnpm%2F%2540quantus%252Fcrypto%2F-%2F0.3.0%2Fcrypto-0.3.0.tgz"
|
||||
dependencies:
|
||||
fflate: "npm:^0.8.2"
|
||||
tslib: "npm:^2.7.0"
|
||||
checksum: 10/c6e531e0350d74d863cfa8acfbed0eeacaa2814c2f2628976b73b59a2ff4b6a382dd0d734e34c1c2442ba7e575f0ae12dd153b44fdbfec51b61f212c1ef41fbd
|
||||
checksum: 10/fa40dbe5206d1ff28038c35825f65f113e4ccf503b3e0126c1d67c7645081c3855b972dfd7e6d76a142b73b1dbfc8947a22354d587b09515f0acf065d6507f13
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
|
||||
Reference in New Issue
Block a user