diff --git a/CHANGELOG.md b/CHANGELOG.md index d7c4275c21c1..ca2ed2de3651 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ Changes: - Adjust `pendingRewards` for pools runtime calls +- Support for `AccountId33` (raw/compressed 33-byte ecdsa) - Update to latest Substrate, Polkadot & Kusama metadata diff --git a/packages/types-augment/src/registry/interfaces.ts b/packages/types-augment/src/registry/interfaces.ts index 530ac825b2e2..be57e64572b8 100644 --- a/packages/types-augment/src/registry/interfaces.ts +++ b/packages/types-augment/src/registry/interfaces.ts @@ -52,7 +52,7 @@ import type { ProxyAnnouncement, ProxyDefinition, ProxyType } from '@polkadot/ty import type { AccountStatus, AccountValidity } from '@polkadot/types/interfaces/purchase'; import type { ActiveRecovery, RecoveryConfig } from '@polkadot/types/interfaces/recovery'; import type { RpcMethods } from '@polkadot/types/interfaces/rpc'; -import type { AccountId, AccountId20, AccountId32, AccountIdOf, AccountIndex, Address, AssetId, Balance, BalanceOf, Block, BlockNumber, BlockNumberFor, BlockNumberOf, Call, CallHash, CallHashOf, ChangesTrieConfiguration, ChangesTrieSignal, CodecHash, Consensus, ConsensusEngineId, CrateVersion, Digest, DigestItem, EncodedJustification, ExtrinsicsWeight, Fixed128, Fixed64, FixedI128, FixedI64, FixedU128, FixedU64, H1024, H128, H160, H2048, H256, H32, H512, H64, Hash, Header, HeaderPartial, I32F32, Index, IndicesLookupSource, Justification, Justifications, KeyTypeId, KeyValue, LockIdentifier, LookupSource, LookupTarget, ModuleId, Moment, MultiAddress, MultiSigner, OpaqueCall, Origin, OriginCaller, PalletId, PalletVersion, PalletsOrigin, Pays, PerU16, Perbill, Percent, Permill, Perquintill, Phantom, PhantomData, PreRuntime, Releases, RuntimeDbWeight, Seal, SealV0, SignedBlock, SignedBlockWithJustification, SignedBlockWithJustifications, Slot, SlotDuration, StorageData, StorageInfo, StorageProof, TransactionInfo, TransactionLongevity, TransactionPriority, TransactionStorageProof, TransactionTag, U32F32, ValidatorId, ValidatorIdOf, Weight, WeightMultiplier } from '@polkadot/types/interfaces/runtime'; +import type { AccountId, AccountId20, AccountId32, AccountId33, AccountIdOf, AccountIndex, Address, AssetId, Balance, BalanceOf, Block, BlockNumber, BlockNumberFor, BlockNumberOf, Call, CallHash, CallHashOf, ChangesTrieConfiguration, ChangesTrieSignal, CodecHash, Consensus, ConsensusEngineId, CrateVersion, Digest, DigestItem, EncodedJustification, ExtrinsicsWeight, Fixed128, Fixed64, FixedI128, FixedI64, FixedU128, FixedU64, H1024, H128, H160, H2048, H256, H32, H512, H64, Hash, Header, HeaderPartial, I32F32, Index, IndicesLookupSource, Justification, Justifications, KeyTypeId, KeyValue, LockIdentifier, LookupSource, LookupTarget, ModuleId, Moment, MultiAddress, MultiSigner, OpaqueCall, Origin, OriginCaller, PalletId, PalletVersion, PalletsOrigin, Pays, PerU16, Perbill, Percent, Permill, Perquintill, Phantom, PhantomData, PreRuntime, Releases, RuntimeDbWeight, Seal, SealV0, SignedBlock, SignedBlockWithJustification, SignedBlockWithJustifications, Slot, SlotDuration, StorageData, StorageInfo, StorageProof, TransactionInfo, TransactionLongevity, TransactionPriority, TransactionStorageProof, TransactionTag, U32F32, ValidatorId, ValidatorIdOf, Weight, WeightMultiplier } from '@polkadot/types/interfaces/runtime'; import type { Si0Field, Si0LookupTypeId, Si0Path, Si0Type, Si0TypeDef, Si0TypeDefArray, Si0TypeDefBitSequence, Si0TypeDefCompact, Si0TypeDefComposite, Si0TypeDefPhantom, Si0TypeDefPrimitive, Si0TypeDefSequence, Si0TypeDefTuple, Si0TypeDefVariant, Si0TypeParameter, Si0Variant, Si1Field, Si1LookupTypeId, Si1Path, Si1Type, Si1TypeDef, Si1TypeDefArray, Si1TypeDefBitSequence, Si1TypeDefCompact, Si1TypeDefComposite, Si1TypeDefPrimitive, Si1TypeDefSequence, Si1TypeDefTuple, Si1TypeDefVariant, Si1TypeParameter, Si1Variant, SiField, SiLookupTypeId, SiPath, SiType, SiTypeDef, SiTypeDefArray, SiTypeDefBitSequence, SiTypeDefCompact, SiTypeDefComposite, SiTypeDefPrimitive, SiTypeDefSequence, SiTypeDefTuple, SiTypeDefVariant, SiTypeParameter, SiVariant } from '@polkadot/types/interfaces/scaleInfo'; import type { Period, Priority, SchedulePeriod, SchedulePriority, Scheduled, ScheduledTo254, TaskAddress } from '@polkadot/types/interfaces/scheduler'; import type { BeefyKey, FullIdentification, IdentificationTuple, Keys, MembershipProof, SessionIndex, SessionKeys1, SessionKeys10, SessionKeys10B, SessionKeys2, SessionKeys3, SessionKeys4, SessionKeys5, SessionKeys6, SessionKeys6B, SessionKeys7, SessionKeys7B, SessionKeys8, SessionKeys8B, SessionKeys9, SessionKeys9B, ValidatorCount } from '@polkadot/types/interfaces/session'; @@ -78,6 +78,7 @@ declare module '@polkadot/types/types/registry' { AccountId: AccountId; AccountId20: AccountId20; AccountId32: AccountId32; + AccountId33: AccountId33; AccountIdOf: AccountIdOf; AccountIndex: AccountIndex; AccountInfo: AccountInfo; diff --git a/packages/types/src/generic/AccountId.spec.ts b/packages/types/src/generic/AccountId.spec.ts index 21f4bb4d6170..76c6c4105db5 100644 --- a/packages/types/src/generic/AccountId.spec.ts +++ b/packages/types/src/generic/AccountId.spec.ts @@ -7,7 +7,6 @@ import { Raw } from '@polkadot/types-codec'; import jsonVec from '@polkadot/types-support/json/AccountIdVec.001.json' assert { type: 'json' }; import { TypeRegistry } from '../create'; -import { GenericAccountId as AccountId } from '.'; describe('AccountId', (): void => { const registry = new TypeRegistry(); @@ -37,7 +36,7 @@ describe('AccountId', (): void => { }); describe('decoding', (): void => { - const testDecode = (type: string, input: Uint8Array | string | AccountId, expected: string): void => + const testDecode = (type: string, input: Uint8Array | string, expected: string): void => it(`can decode from ${type}`, (): void => { expect( registry @@ -57,6 +56,11 @@ describe('AccountId', (): void => { registry.createType('AccountId', '0x0102030405060708010203040506070801020304050607080102030405060708'), '5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCtGwF' ); + testDecode( + 'AccountId33', + registry.createType('AccountId33', '0x098765430987654309876543098765430987654309876543098765430987654309'), + '5CHCWUYMmDGeJjiuaQ1LnrsAWacDhiTAV6vCfytSxoqBdCCb' + ); testDecode('hex', '0x0102030405060708010203040506070801020304050607080102030405060708', '5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCtGwF'); testDecode('string', '5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCtGwF', '5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCtGwF'); testDecode( diff --git a/packages/types/src/generic/AccountId.ts b/packages/types/src/generic/AccountId.ts index 57ff045d2986..197ff47e1fc5 100644 --- a/packages/types/src/generic/AccountId.ts +++ b/packages/types/src/generic/AccountId.ts @@ -22,20 +22,14 @@ function decodeAccountId (value?: AnyU8a | AnyString): Uint8Array { throw new Error(`Unknown type passed to AccountId constructor, found typeof ${typeof value}`); } -/** - * @name GenericAccountId - * @description - * A wrapper around an AccountId/PublicKey representation. Since we are dealing with - * underlying PublicKeys (32 bytes in length), we extend from U8aFixed which is - * just a Uint8Array wrapper with a fixed length. - */ -export class GenericAccountId extends U8aFixed { - constructor (registry: Registry, value?: AnyU8a) { +class BaseAccountId extends U8aFixed { + constructor (registry: Registry, allowedBits = 256 | 264, value?: AnyU8a) { const decoded = decodeAccountId(value); + const decodedBits = decoded.length * 8; // Part of stream containing >= 32 bytes or a all empty (defaults) - if (decoded.length < 32 && decoded.some((b) => b)) { - throw new Error(`Invalid AccountId provided, expected 32 bytes, found ${decoded.length}`); + if (decodedBits < allowedBits && decoded.some((b) => b)) { + throw new Error(`Invalid AccountId provided, expected ${allowedBits >> 3} bytes, found ${decoded.length}`); } super(registry, decoded, 256); @@ -83,3 +77,22 @@ export class GenericAccountId extends U8aFixed { return 'AccountId'; } } + +/** + * @name GenericAccountId + * @description + * A wrapper around an AccountId/PublicKey representation. Since we are dealing with + * underlying PublicKeys (32 bytes in length), we extend from U8aFixed which is + * just a Uint8Array wrapper with a fixed length. + */ +export class GenericAccountId extends BaseAccountId { + constructor (registry: Registry, value?: AnyU8a) { + super(registry, 256, value); + } +} + +export class GenericAccountId33 extends BaseAccountId { + constructor (registry: Registry, value?: AnyU8a) { + super(registry, 264, value); + } +} diff --git a/packages/types/src/generic/index.ts b/packages/types/src/generic/index.ts index 4d05e32afa4d..5d10f9bcea91 100644 --- a/packages/types/src/generic/index.ts +++ b/packages/types/src/generic/index.ts @@ -3,7 +3,7 @@ export * from '../ethereum'; -export { GenericAccountId } from './AccountId'; +export { GenericAccountId, GenericAccountId as GenericAccountId32, GenericAccountId33 } from './AccountId'; export { GenericAccountIndex } from './AccountIndex'; export { GenericBlock } from './Block'; export { GenericCall } from './Call'; diff --git a/packages/types/src/interfaces/runtime/definitions.ts b/packages/types/src/interfaces/runtime/definitions.ts index fba5e68a57e2..fed46ec39e16 100644 --- a/packages/types/src/interfaces/runtime/definitions.ts +++ b/packages/types/src/interfaces/runtime/definitions.ts @@ -53,7 +53,8 @@ export default { types: objectSpread({}, numberTypes, { AccountId: 'AccountId32', AccountId20: 'GenericEthereumAccountId', - AccountId32: 'GenericAccountId', + AccountId32: 'GenericAccountId32', + AccountId33: 'GenericAccountId33', AccountIdOf: 'AccountId', AccountIndex: 'GenericAccountIndex', Address: 'MultiAddress', diff --git a/packages/types/src/interfaces/runtime/types.ts b/packages/types/src/interfaces/runtime/types.ts index 6996860f018b..68632ae53856 100644 --- a/packages/types/src/interfaces/runtime/types.ts +++ b/packages/types/src/interfaces/runtime/types.ts @@ -1,7 +1,7 @@ // Auto-generated via `yarn polkadot-types-from-defs`, do not edit /* eslint-disable */ -import type { GenericAccountId, GenericAccountIndex, GenericBlock, GenericCall, GenericConsensusEngineId, GenericEthereumAccountId, GenericLookupSource, GenericMultiAddress, StorageKey } from '@polkadot/types'; +import type { GenericAccountId32, GenericAccountId33, GenericAccountIndex, GenericBlock, GenericCall, GenericConsensusEngineId, GenericEthereumAccountId, GenericLookupSource, GenericMultiAddress, StorageKey } from '@polkadot/types'; import type { Bytes, Compact, DoNotConstruct, Enum, Int, Null, Option, Struct, U8aFixed, UInt, Vec, u16, u32, u64, u8 } from '@polkadot/types-codec'; import type { ITuple } from '@polkadot/types-codec/types'; import type { AuthorityId } from '@polkadot/types/interfaces/consensus'; @@ -15,7 +15,10 @@ export interface AccountId extends AccountId32 {} export interface AccountId20 extends GenericEthereumAccountId {} /** @name AccountId32 */ -export interface AccountId32 extends GenericAccountId {} +export interface AccountId32 extends GenericAccountId32 {} + +/** @name AccountId33 */ +export interface AccountId33 extends GenericAccountId33 {} /** @name AccountIdOf */ export interface AccountIdOf extends AccountId {}