Skip to content

Commit 4402287

Browse files
committed
ClaimId generator should be taking the node's own NodeId
1 parent 2fe2e24 commit 4402287

3 files changed

Lines changed: 12 additions & 6 deletions

File tree

src/claims/utils.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type {
77
SignatureData,
88
ClaimIntermediary,
99
} from './types';
10-
import type { NodeIdEncoded } from '../nodes/types';
10+
import type { NodeId, NodeIdEncoded } from '../nodes/types';
1111
import type { PublicKeyPem, PrivateKeyPem } from '../keys/types';
1212
import type { POJO } from '../types';
1313
import type { GeneralJWSInput } from 'jose';
@@ -492,10 +492,14 @@ function decodeClaimId(claimIdEncoded: string): ClaimId | undefined {
492492
return claimId;
493493
}
494494

495-
function createClaimIdGenerator(nodeId: NodeIdEncoded, lastClaimId?: ClaimId) {
495+
/**
496+
* Generator for `ClaimId`
497+
* Make sure the `nodeId` is set to this node's own `NodeId`
498+
*/
499+
function createClaimIdGenerator(nodeId: NodeId, lastClaimId?: ClaimId) {
496500
const generator = new IdSortable<ClaimId>({
497501
lastId: lastClaimId,
498-
nodeId: IdInternal.fromString(nodeId).toBuffer(),
502+
nodeId,
499503
});
500504
return () => generator.get();
501505
}

src/sigchain/Sigchain.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import {
1919
} from '@matrixai/async-init/dist/CreateDestroyStartStop';
2020
import * as sigchainErrors from './errors';
2121
import * as claimsUtils from '../claims/utils';
22-
import { utils as nodesUtils } from '../nodes';
2322

2423
interface Sigchain extends CreateDestroyStartStop {}
2524
@CreateDestroyStartStop(
@@ -138,7 +137,7 @@ class Sigchain {
138137
// Creating the ID generator
139138
const latestId = await this.getLatestClaimId();
140139
this.generateClaimId = claimsUtils.createClaimIdGenerator(
141-
nodesUtils.encodeNodeId(this.keyManager.getNodeId()),
140+
this.keyManager.getNodeId(),
142141
latestId,
143142
);
144143
this.logger.info(`Started ${this.constructor.name}`);

tests/client/service/identitiesClaim.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import * as identitiesPB from '@/proto/js/polykey/v1/identities/identities_pb';
2323
import * as clientUtils from '@/client/utils/utils';
2424
import * as keysUtils from '@/keys/utils';
2525
import * as claimsUtils from '@/claims/utils';
26+
import * as nodesUtils from '@/nodes/utils';
2627
import * as validationErrors from '@/validation/errors';
2728
import * as testUtils from '../../utils';
2829
import TestProvider from '../../identities/TestProvider';
@@ -47,7 +48,9 @@ describe('identitiesClaim', () => {
4748
provider: testToken.providerId,
4849
identity: testToken.identityId,
4950
};
50-
const claimId = claimsUtils.createClaimIdGenerator(claimData.node)();
51+
const claimId = claimsUtils.createClaimIdGenerator(
52+
nodesUtils.decodeNodeId(claimData.node)!,
53+
)();
5154
let mockedGenerateKeyPair: jest.SpyInstance;
5255
let mockedGenerateDeterministicKeyPair: jest.SpyInstance;
5356
let mockedAddClaim: jest.SpyInstance;

0 commit comments

Comments
 (0)