diff --git a/framework/src/modules/auth/module.ts b/framework/src/modules/auth/module.ts index 66e99115def..a729f407f4a 100644 --- a/framework/src/modules/auth/module.ts +++ b/framework/src/modules/auth/module.ts @@ -112,15 +112,15 @@ export class AuthModule extends BaseModule { const genesisStore = codec.decode(genesisAuthStoreSchema, assetBytes); const store = this.stores.get(AuthAccountStore); const keys = []; - for (const { storeKey, storeValue } of genesisStore.authDataSubstore) { - if (storeKey.length !== ADDRESS_LENGTH) { + for (const { address, authAccount } of genesisStore.authDataSubstore) { + if (address.length !== ADDRESS_LENGTH) { throw new Error('Invalid store key length for auth module.'); } - keys.push(storeKey); + keys.push(address); - validator.validate(authAccountSchema, storeValue); + validator.validate(authAccountSchema, authAccount); - const { mandatoryKeys, optionalKeys, numberOfSignatures } = storeValue; + const { mandatoryKeys, optionalKeys, numberOfSignatures } = authAccount; if (!objectUtils.isBufferArrayOrdered(mandatoryKeys)) { throw new Error( @@ -165,10 +165,10 @@ export class AuthModule extends BaseModule { throw new Error('The numberOfSignatures is smaller than the count of Mandatory keys.'); } - await store.set(context, storeKey, storeValue); + await store.set(context, address, authAccount); } if (!objectUtils.bufferArrayUniqueItems(keys)) { - throw new Error('Duplicate store key for auth module.'); + throw new Error('Duplicate address in the for auth module.'); } } diff --git a/framework/src/modules/auth/schemas.ts b/framework/src/modules/auth/schemas.ts index 3495e00cbac..aebf8439d7f 100644 --- a/framework/src/modules/auth/schemas.ts +++ b/framework/src/modules/auth/schemas.ts @@ -172,13 +172,13 @@ export const genesisAuthStoreSchema = { fieldNumber: 1, items: { type: 'object', - required: ['storeKey', 'storeValue'], + required: ['address', 'authAccount'], properties: { - storeKey: { + address: { dataType: 'bytes', fieldNumber: 1, }, - storeValue: { + authAccount: { type: 'object', fieldNumber: 2, required: ['nonce', 'numberOfSignatures', 'mandatoryKeys', 'optionalKeys'], @@ -196,6 +196,8 @@ export const genesisAuthStoreSchema = { fieldNumber: 3, items: { dataType: 'bytes', + minLength: ED25519_PUBLIC_KEY_LENGTH, + maxLength: ED25519_PUBLIC_KEY_LENGTH, }, }, optionalKeys: { @@ -203,6 +205,8 @@ export const genesisAuthStoreSchema = { fieldNumber: 4, items: { dataType: 'bytes', + minLength: ED25519_PUBLIC_KEY_LENGTH, + maxLength: ED25519_PUBLIC_KEY_LENGTH, }, }, }, diff --git a/framework/src/modules/auth/types.ts b/framework/src/modules/auth/types.ts index fd8255ebbfc..5bd49462fff 100644 --- a/framework/src/modules/auth/types.ts +++ b/framework/src/modules/auth/types.ts @@ -53,8 +53,8 @@ export interface SortedMultisignatureGroup { export interface GenesisAuthStore { authDataSubstore: { - storeKey: Buffer; - storeValue: AuthAccount; + address: Buffer; + authAccount: AuthAccount; }[]; } diff --git a/framework/test/unit/modules/auth/module.spec.ts b/framework/test/unit/modules/auth/module.spec.ts index 94da0c574c7..0c23a23c720 100644 --- a/framework/test/unit/modules/auth/module.spec.ts +++ b/framework/test/unit/modules/auth/module.spec.ts @@ -99,8 +99,8 @@ describe('AuthModule', () => { const validAsset = { authDataSubstore: [ { - storeKey: address, - storeValue: { + address, + authAccount: { numberOfSignatures: 0, mandatoryKeys: [], optionalKeys: [], @@ -108,8 +108,8 @@ describe('AuthModule', () => { }, }, { - storeKey: utils.getRandomBytes(ADDRESS_LENGTH), - storeValue: { + address: utils.getRandomBytes(ADDRESS_LENGTH), + authAccount: { numberOfSignatures: 3, mandatoryKeys: [utils.getRandomBytes(32), utils.getRandomBytes(32)].sort((a, b) => a.compare(b), @@ -128,8 +128,8 @@ describe('AuthModule', () => { { authDataSubstore: [ { - storeKey: utils.getRandomBytes(8), - storeValue: { + address: utils.getRandomBytes(8), + authAccount: { numberOfSignatures: 0, mandatoryKeys: [], optionalKeys: [], @@ -144,8 +144,8 @@ describe('AuthModule', () => { { authDataSubstore: [ { - storeKey: utils.getRandomBytes(ADDRESS_LENGTH), - storeValue: { + address: utils.getRandomBytes(ADDRESS_LENGTH), + authAccount: { numberOfSignatures: 3, mandatoryKeys: [utils.getRandomBytes(32), utils.getRandomBytes(32)].sort((a, b) => b.compare(a), @@ -162,8 +162,8 @@ describe('AuthModule', () => { { authDataSubstore: [ { - storeKey: utils.getRandomBytes(ADDRESS_LENGTH), - storeValue: { + address: utils.getRandomBytes(ADDRESS_LENGTH), + authAccount: { numberOfSignatures: 2, mandatoryKeys: [publicKey, publicKey], optionalKeys: [], @@ -178,8 +178,8 @@ describe('AuthModule', () => { { authDataSubstore: [ { - storeKey: utils.getRandomBytes(ADDRESS_LENGTH), - storeValue: { + address: utils.getRandomBytes(ADDRESS_LENGTH), + authAccount: { numberOfSignatures: 3, mandatoryKeys: [], optionalKeys: [utils.getRandomBytes(32), utils.getRandomBytes(32)].sort((a, b) => @@ -196,8 +196,8 @@ describe('AuthModule', () => { { authDataSubstore: [ { - storeKey: utils.getRandomBytes(ADDRESS_LENGTH), - storeValue: { + address: utils.getRandomBytes(ADDRESS_LENGTH), + authAccount: { numberOfSignatures: 2, mandatoryKeys: [], optionalKeys: [publicKey, publicKey], @@ -212,8 +212,8 @@ describe('AuthModule', () => { { authDataSubstore: [ { - storeKey: utils.getRandomBytes(ADDRESS_LENGTH), - storeValue: { + address: utils.getRandomBytes(ADDRESS_LENGTH), + authAccount: { numberOfSignatures: 36, mandatoryKeys: Array.from({ length: 33 }, () => utils.getRandomBytes(32)).sort( (a, b) => b.compare(a), @@ -232,8 +232,8 @@ describe('AuthModule', () => { { authDataSubstore: [ { - storeKey: utils.getRandomBytes(ADDRESS_LENGTH), - storeValue: { + address: utils.getRandomBytes(ADDRESS_LENGTH), + authAccount: { numberOfSignatures: 3, mandatoryKeys: [], optionalKeys: [utils.getRandomBytes(32), utils.getRandomBytes(32)].sort((a, b) => @@ -250,8 +250,8 @@ describe('AuthModule', () => { { authDataSubstore: [ { - storeKey: utils.getRandomBytes(ADDRESS_LENGTH), - storeValue: { + address: utils.getRandomBytes(ADDRESS_LENGTH), + authAccount: { numberOfSignatures: 1, mandatoryKeys: [utils.getRandomBytes(32), utils.getRandomBytes(32)].sort((a, b) => b.compare(a), @@ -288,7 +288,7 @@ describe('AuthModule', () => { await expect(authModule.initGenesisState(context)).toResolve(); const authStore = authModule.stores.get(AuthAccountStore); for (const data of validAsset.authDataSubstore) { - await expect(authStore.has(context, data.storeKey)).resolves.toBeTrue(); + await expect(authStore.has(context, data.address)).resolves.toBeTrue(); } });