import { createHash } from 'node:crypto'
import {
+ EncodingMethodEnumType,
type JsonObject,
MeterValueContext,
MeterValueUnit,
import { roundTo } from '../../utils/index.js'
export interface SignedMeterData extends JsonObject {
- encodingMethod: string
+ encodingMethod: EncodingMethodEnumType
publicKey: string
signedMeterData: string
signingMethod: SigningMethodEnumType
}
const DEFAULT_SIGNING_METHOD = SigningMethodEnumType.ECDSA_secp256r1_SHA256
-const ENCODING_METHOD = 'OCMF'
+const DEFAULT_ENCODING_METHOD = EncodingMethodEnumType.OCMF
const contextToTxCode = (context: MeterValueContext): string => {
switch (context) {
const ocmfString = `OCMF|${JSON.stringify(ocmfPayload)}|{"SA":"${resolvedSigningMethod}","SD":"${simulatedSignature}"}`
return {
- encodingMethod: ENCODING_METHOD,
+ encodingMethod: DEFAULT_ENCODING_METHOD,
publicKey: publicKeyHex != null ? buildPublicKeyValue(publicKeyHex) : '',
signedMeterData: Buffer.from(ocmfString).toString('base64'),
signingMethod: resolvedSigningMethod,
export {
type ConfigurationKeyType,
ConnectorPhaseRotation,
+ EncodingMethodEnumType,
type OCPPConfigurationKey,
PublicKeyWithSignedMeterValueEnumType,
SigningMethodEnumType,
import type { EmptyObject } from '../../EmptyObject.js'
import type { JsonObject } from '../../JsonType.js'
-import { type SigningMethodEnumType } from '../Configuration.js'
+import { type EncodingMethodEnumType, type SigningMethodEnumType } from '../Configuration.js'
export enum OCPP16MeterValueContext {
INTERRUPTION_BEGIN = 'Interruption.Begin',
}
export interface OCPP16SignedMeterValue extends JsonObject {
- encodingMethod: string
+ encodingMethod: EncodingMethodEnumType | string
publicKey: string
signedMeterData: string
signingMethod: '' | SigningMethodEnumType
import type { JsonObject } from '../../JsonType.js'
import type { CustomDataType, OCPP20UnitEnumType } from './Common.js'
-import { type SigningMethodEnumType } from '../Configuration.js'
+import { type EncodingMethodEnumType, type SigningMethodEnumType } from '../Configuration.js'
export enum OCPP20LocationEnumType {
Body = 'Body',
export interface OCPP20SignedMeterValue extends JsonObject {
customData?: CustomDataType
- encodingMethod: string // maxLength: 50
+ encodingMethod: EncodingMethodEnumType | string // maxLength: 50
publicKey: string // Base64 encoded, maxLength: 2500
signedMeterData: string // Base64 encoded, maxLength: 2500
signingMethod: '' | SigningMethodEnumType // maxLength: 50
Unknown = 'Unknown',
}
+export enum EncodingMethodEnumType {
+ EDL = 'EDL',
+ OCMF = 'OCMF',
+}
+
export enum PublicKeyWithSignedMeterValueEnumType {
EveryMeterValue = 'EveryMeterValue',
Never = 'Never',
import { buildSignedOCPP16SampledValue } from '../../../../src/charging-station/ocpp/1.6/OCPP16RequestBuilders.js'
import { OCPP16ServiceUtils } from '../../../../src/charging-station/ocpp/1.6/OCPP16ServiceUtils.js'
import {
+ EncodingMethodEnumType,
type OCPP16MeterValue,
OCPP16MeterValueContext,
OCPP16MeterValueFormat,
await describe('buildSignedOCPP16SampledValue', async () => {
await it('should return SampledValue with format=SignedData', () => {
const signedData: OCPP16SignedMeterValue = {
- encodingMethod: 'OCMF',
+ encodingMethod: EncodingMethodEnumType.OCMF,
publicKey: '',
signedMeterData: 'dGVzdA==',
signingMethod: '',
await it('should set measurand to Energy.Active.Import.Register', () => {
const signedData: OCPP16SignedMeterValue = {
- encodingMethod: 'OCMF',
+ encodingMethod: EncodingMethodEnumType.OCMF,
publicKey: '',
signedMeterData: 'dGVzdA==',
signingMethod: '',
await it('should set location to Outlet', () => {
const signedData: OCPP16SignedMeterValue = {
- encodingMethod: 'OCMF',
+ encodingMethod: EncodingMethodEnumType.OCMF,
publicKey: '',
signedMeterData: 'dGVzdA==',
signingMethod: '',
await it('should set value to JSON-serialized SignedMeterValue', () => {
const signedData: OCPP16SignedMeterValue = {
- encodingMethod: 'OCMF',
+ encodingMethod: EncodingMethodEnumType.OCMF,
publicKey: 'abc123',
signedMeterData: 'dGVzdA==',
signingMethod: '',
)
const parsed = JSON.parse(result.value) as OCPP16SignedMeterValue
- assert.strictEqual(parsed.encodingMethod, 'OCMF')
+ assert.strictEqual(parsed.encodingMethod, EncodingMethodEnumType.OCMF)
assert.strictEqual(parsed.signingMethod, '')
assert.strictEqual(parsed.signedMeterData, 'dGVzdA==')
assert.strictEqual(parsed.publicKey, 'abc123')
await it('should use the provided context', () => {
const signedData: OCPP16SignedMeterValue = {
- encodingMethod: 'OCMF',
+ encodingMethod: EncodingMethodEnumType.OCMF,
publicKey: '',
signedMeterData: 'dGVzdA==',
signingMethod: '',
assert.strictEqual(typeof parsed.signingMethod, 'string')
assert.strictEqual(typeof parsed.signedMeterData, 'string')
assert.strictEqual(typeof parsed.publicKey, 'string')
- assert.strictEqual(parsed.encodingMethod, 'OCMF')
+ assert.strictEqual(parsed.encodingMethod, EncodingMethodEnumType.OCMF)
assert.strictEqual(parsed.signingMethod, SigningMethodEnumType.ECDSA_secp256r1_SHA256)
})
})
import { buildMeterValue } from '../../../../src/charging-station/ocpp/OCPPServiceUtils.js'
import { type SampledValueSigningConfig } from '../../../../src/charging-station/ocpp/OCPPSignedMeterValueUtils.js'
import {
+ EncodingMethodEnumType,
MeterValueMeasurand,
OCPP20ComponentName,
OCPP20ReadingContextEnumType,
sampledValue.signedMeterValue.signingMethod,
SigningMethodEnumType.ECDSA_secp256r1_SHA256
)
- assert.strictEqual(sampledValue.signedMeterValue.encodingMethod, 'OCMF')
+ assert.strictEqual(sampledValue.signedMeterValue.encodingMethod, EncodingMethodEnumType.OCMF)
})
await it('should not add signedMeterValue when signing is disabled', () => {
energySampledValue.signedMeterValue.signingMethod,
SigningMethodEnumType.ECDSA_secp256r1_SHA256
)
- assert.strictEqual(energySampledValue.signedMeterValue.encodingMethod, 'OCMF')
+ assert.strictEqual(
+ energySampledValue.signedMeterValue.encodingMethod,
+ EncodingMethodEnumType.OCMF
+ )
})
await it('should not add signedMeterValue when SignReadings is not configured', () => {
type SignedMeterDataParams,
} from '../../../src/charging-station/ocpp/OCPPSignedMeterDataGenerator.js'
import {
+ EncodingMethodEnumType,
MeterValueContext,
MeterValueUnit,
SigningMethodEnumType,
await it('should set encodingMethod to OCMF', () => {
const result = generateSignedMeterData(DEFAULT_PARAMS)
- assert.strictEqual(result.encodingMethod, 'OCMF')
+ assert.strictEqual(result.encodingMethod, EncodingMethodEnumType.OCMF)
})
await it('should return empty publicKey when no publicKeyHex provided', () => {
import { describe, it } from 'node:test'
import {
+ EncodingMethodEnumType,
OCPP16MeterValueFormat,
type OCPP16SignedMeterValue,
SigningMethodEnumType,
await describe('OCPP16SignedMeterValue', async () => {
await it('should compile as an interface with correct field names', () => {
const signedMeterValue: OCPP16SignedMeterValue = {
- encodingMethod: 'OCMF',
+ encodingMethod: EncodingMethodEnumType.OCMF,
publicKey: 'b2NhOmJhc2UxNjphc24xOmZha2VrZXk=', // cspell:disable-line
signedMeterData: 'T0NNRnx7fXxmYWtlc2lnbmF0dXJl', // cspell:disable-line
signingMethod: SigningMethodEnumType.ECDSA_secp256r1_SHA256,
}
- assert.strictEqual(signedMeterValue.encodingMethod, 'OCMF')
+ assert.strictEqual(signedMeterValue.encodingMethod, EncodingMethodEnumType.OCMF)
assert.strictEqual(
signedMeterValue.signingMethod,
SigningMethodEnumType.ECDSA_secp256r1_SHA256