Skip to content

Commit e39cf99

Browse files
Fix copyright, jsdoc and return value type. Remove regex
1 parent c061e4b commit e39cf99

File tree

2 files changed

+4
-11
lines changed

2 files changed

+4
-11
lines changed

src/core/format/KeyGenerator.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2018 NEM
2+
* Copyright 2019 NEM
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,19 +19,17 @@ import { sha3_256 } from 'js-sha3';
1919

2020
export class KeyGenerator {
2121
/**
22+
* Generate UInt64 from a string
23+
* @param {string} input Input string
2224
* @returns {UInt64} Deterministic uint64 value for the given string
2325
*/
24-
public static fromString(input: string) {
26+
public static fromString(input: string): UInt64 {
2527
if (input.length === 0) {
2628
throw Error(`Input must not be empty`);
2729
}
2830
if (input.length > 1024) {
2931
throw Error(`Input exceeds 1024 characters (has ${input.length})`);
3032
}
31-
const format = /^[a-zA-Z0-9_]+$/gm;
32-
if (input.match(format) === null) {
33-
throw Error(`Input has invalid format (accepted characters: a-z, A-Z, 0-9, _)`);
34-
}
3533
const hex = sha3_256(input)
3634
return UInt64.fromHex(hex.substr(0, 16))
3735
}

test/core/format/KeyGenerator.spec.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@ describe('key generator', () => {
2525
it('returns UInt64', () => {
2626
expect(KeyGenerator.fromString('a')).to.be.instanceOf(UInt64);
2727
})
28-
it('throws if input has invalid format', () => {
29-
expect(() => KeyGenerator.fromString('$abc')).to.throw(Error, '');
30-
expect(() => KeyGenerator.fromString('ab-c')).to.throw(Error, '');
31-
expect(() => KeyGenerator.fromString('abc.')).to.throw(Error, '');
32-
})
3328
it('generates correct keys', () => {
3429
expect(KeyGenerator.fromString('a').toHex()).to.equal('80084BF2FBA02475');
3530
})

0 commit comments

Comments
 (0)