Skip to content

Commit 97a7b84

Browse files
committed
Renamed SignSchema enum names
1 parent 3adc60a commit 97a7b84

22 files changed

+122
-118
lines changed

src/core/crypto/Crypto.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,10 @@ export class Crypto {
219219
* @param {string} msg - A text message
220220
* @param {Uint8Array} iv - An initialization vector
221221
* @param {Uint8Array} salt - A salt
222-
* @param {SignSchema} signSchema The Sign Schema (NIS / Catapult)
222+
* @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3)
223223
* @return {string} - The encoded message
224224
*/
225-
public static _encode = (senderPriv, recipientPub, msg, iv, salt, signSchema: SignSchema = SignSchema.Catapult) => {
225+
public static _encode = (senderPriv, recipientPub, msg, iv, salt, signSchema: SignSchema = SignSchema.SHA3) => {
226226
// Errors
227227
if (!senderPriv || !recipientPub || !msg || !iv || !salt) { throw new Error('Missing argument !'); }
228228
// Processing
@@ -244,10 +244,10 @@ export class Crypto {
244244
* @param {string} senderPriv - A sender private key
245245
* @param {string} recipientPub - A recipient public key
246246
* @param {string} msg - A text message
247-
* @param {SignSchema} signSchema The Sign Schema (NIS / Catapult)
247+
* @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3)
248248
* @return {string} - The encoded message
249249
*/
250-
public static encode = (senderPriv, recipientPub, msg, signSchema: SignSchema = SignSchema.Catapult) => {
250+
public static encode = (senderPriv, recipientPub, msg, signSchema: SignSchema = SignSchema.SHA3) => {
251251
// Errors
252252
if (!senderPriv || !recipientPub || !msg) { throw new Error('Missing argument !'); }
253253
// Processing
@@ -264,10 +264,10 @@ export class Crypto {
264264
* @param {string} recipientPrivate - A recipient private key
265265
* @param {string} senderPublic - A sender public key
266266
* @param {Uint8Array} _payload - An encrypted message payload in bytes
267-
* @param {SignSchema} signSchema The Sign Schema (NIS / Catapult)
267+
* @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3)
268268
* @return {string} - The decoded payload as hex
269269
*/
270-
public static _decode = (recipientPrivate, senderPublic, payload, iv, salt, signSchema: SignSchema = SignSchema.Catapult) => {
270+
public static _decode = (recipientPrivate, senderPublic, payload, iv, salt, signSchema: SignSchema = SignSchema.SHA3) => {
271271
// Error
272272
if (!recipientPrivate || !senderPublic || !payload) { throw new Error('Missing argument !'); }
273273
// Processing
@@ -291,10 +291,10 @@ export class Crypto {
291291
* @param {string} recipientPrivate - A recipient private key
292292
* @param {string} senderPublic - A sender public key
293293
* @param {string} _payload - An encrypted message payload
294-
* @param {SignSchema} signSchema The Sign Schema (NIS / Catapult)
294+
* @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3)
295295
* @return {string} - The decoded payload as hex
296296
*/
297-
public static decode = (recipientPrivate, senderPublic, _payload, signSchema: SignSchema = SignSchema.Catapult) => {
297+
public static decode = (recipientPrivate, senderPublic, _payload, signSchema: SignSchema = SignSchema.SHA3) => {
298298
// Error
299299
if (!recipientPrivate || !senderPublic || !_payload) { throw new Error('Missing argument !'); }
300300
// Processing

src/core/crypto/KeyPair.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ export class KeyPair {
2121
/**
2222
* Creates a key pair from a private key string.
2323
* @param {string} privateKeyString A hex encoded private key string.
24-
* @param {SignSchema} signSchema The Sign Schema (NIS / Catapult)
24+
* @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3)
2525
* @returns {module:crypto/keyPair~KeyPair} The key pair.
2626
*/
27-
public static createKeyPairFromPrivateKeyString = (privateKeyString, signSchema = SignSchema.Catapult) => {
27+
public static createKeyPairFromPrivateKeyString = (privateKeyString, signSchema = SignSchema.SHA3) => {
2828
const privateKey = convert.hexToUint8(privateKeyString);
2929

30-
// NIS use reversed private key.
31-
const secretKey = signSchema === SignSchema.Catapult ? privateKey : convert.hexToUint8Reverse(privateKeyString);
30+
// KECCAK_REVERSED_KEY uses reversed private key.
31+
const secretKey = signSchema === SignSchema.SHA3 ? privateKey : convert.hexToUint8Reverse(privateKeyString);
3232
if (Utility.Key_Size !== privateKey.length) {
3333
throw Error(`private key has unexpected size: ${privateKey.length}`);
3434
}
@@ -43,13 +43,13 @@ export class KeyPair {
4343
* Signs a data buffer with a key pair.
4444
* @param {module:crypto/keyPair~KeyPair} keyPair The key pair to use for signing.
4545
* @param {Uint8Array} data The data to sign.
46-
* @param {SignSchema} signSchema The Sign Schema (NIS / Catapult)
46+
* @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3)
4747
* @returns {Uint8Array} The signature.
4848
*/
49-
public static sign = (keyPair, data, signSchema = SignSchema.Catapult) => {
49+
public static sign = (keyPair, data, signSchema = SignSchema.SHA3) => {
5050
let secretKey = keyPair.privateKey;
51-
// NIS use reversed private key.
52-
if (signSchema === SignSchema.NIS) {
51+
// KECCAK_REVERSED_KEY uses reversed private key.
52+
if (signSchema === SignSchema.KECCAK_REVERSED_KEY) {
5353
secretKey = convert.hexToUint8Reverse(convert.uint8ToHex(secretKey));
5454
}
5555
return Utility.catapult_crypto.sign(data, keyPair.publicKey, secretKey,
@@ -61,10 +61,10 @@ export class KeyPair {
6161
* @param {module:crypto/keyPair~PublicKey} publicKey The public key to use for verification.
6262
* @param {Uint8Array} data The data to verify.
6363
* @param {Uint8Array} signature The signature to verify.
64-
* @param {SignSchema} signSchema The Sign Schema (NIS / Catapult)
64+
* @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3)
6565
* @returns {boolean} true if the signature is verifiable, false otherwise.
6666
*/
67-
public static verify = (publicKey, data, signature, signSchema = SignSchema.Catapult) => {
67+
public static verify = (publicKey, data, signature, signSchema = SignSchema.SHA3) => {
6868
return Utility.catapult_crypto.verify(publicKey, data, signature, Utility.catapult_hash.createHasher(64, signSchema));
6969
}
7070

@@ -74,19 +74,19 @@ export class KeyPair {
7474
* @param {module:crypto/keyPair~KeyPair} keyPair The key pair for which to create the shared key.
7575
* @param {Uint8Array} publicKey The public key for which to create the shared key.
7676
* @param {Uint8Array} salt A salt that should be applied to the shared key.
77-
* @param {SignSchema} signSchema The Sign Schema (NIS / Catapult)
77+
* @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3)
7878
* @returns {Uint8Array} The shared key.
7979
*/
80-
public static deriveSharedKey = (keyPair, publicKey, salt, signSchema = SignSchema.Catapult) => {
80+
public static deriveSharedKey = (keyPair, publicKey, salt, signSchema = SignSchema.SHA3) => {
8181
if (Utility.Key_Size !== salt.length) {
8282
throw Error(`salt has unexpected size: ${salt.length}`);
8383
}
8484
if (Utility.Key_Size !== publicKey.length) {
8585
throw Error(`public key has unexpected size: ${salt.length}`);
8686
}
8787
let secretKey = keyPair.privateKey;
88-
// NIS use reversed private key.
89-
if (signSchema === SignSchema.NIS) {
88+
// KECCAK_REVERSED_KEY uses reversed private key.
89+
if (signSchema === SignSchema.KECCAK_REVERSED_KEY) {
9090
secretKey = convert.hexToUint8Reverse(convert.uint8ToHex(secretKey));
9191
}
9292
return Utility.catapult_crypto.deriveSharedKey(salt, secretKey, publicKey, Utility.catapult_hash.func, signSchema);

src/core/crypto/SHA3Hasher.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ export class SHA3Hasher {
2424
* @param {Uint8Array} dest The computed hash destination.
2525
* @param {Uint8Array} data The data to hash.
2626
* @param {numeric} length The hash length in bytes.
27-
* @param {SignSchema} signSchema The Sign Schema (NIS / Catapult)
27+
* @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3)
2828
*/
29-
public static func = (dest, data, length, signSchema = SignSchema.Catapult) => {
29+
public static func = (dest, data, length, signSchema = SignSchema.SHA3) => {
3030
const hasher = SHA3Hasher.getHasher(length, signSchema);
3131
const hash = hasher.arrayBuffer(data);
3232
array.copy(dest, array.uint8View(hash));
@@ -35,10 +35,10 @@ export class SHA3Hasher {
3535
/**
3636
* Creates a hasher object.
3737
* @param {numeric} length The hash length in bytes.
38-
* @param {SignSchema} signSchema The Sign Schema (NIS / Catapult)
38+
* @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3)
3939
* @returns {object} The hasher.
4040
*/
41-
public static createHasher = (length = 64, signSchema = SignSchema.Catapult) => {
41+
public static createHasher = (length = 64, signSchema = SignSchema.SHA3) => {
4242
let hash;
4343
return {
4444
reset: () => {
@@ -62,13 +62,13 @@ export class SHA3Hasher {
6262
/**
6363
* Get a hasher instance.
6464
* @param {numeric} length The hash length in bytes.
65-
* @param {SignSchema} signSchema The Sign Schema (NIS / Catapult)
65+
* @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3)
6666
* @returns {object} The hasher.
6767
*/
68-
public static getHasher = (length = 64, signSchema = SignSchema.Catapult) => {
68+
public static getHasher = (length = 64, signSchema = SignSchema.SHA3) => {
6969
return {
70-
32: signSchema === SignSchema.Catapult ? sha3_256 : keccak256,
71-
64: signSchema === SignSchema.Catapult ? sha3_512 : keccak512 ,
70+
32: signSchema === SignSchema.SHA3 ? sha3_256 : keccak256,
71+
64: signSchema === SignSchema.SHA3 ? sha3_512 : keccak512 ,
7272
} [length];
7373
}
7474
}

src/core/crypto/SignSchema.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414
* limitations under the License.
1515
*/
1616

17+
/**
18+
* [KECCAK_REVERSED_KEY]: Keccak hash algorithm with key reversed.
19+
* [SHA3]: Sha3 has algorithm without key resersed
20+
*/
1721
export enum SignSchema {
18-
NIS = 1,
19-
Catapult = 2,
22+
KECCAK_REVERSED_KEY = 1,
23+
SHA3 = 2,
2024
}

src/core/format/RawAddress.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,14 @@ export class RawAddress {
7575
* Converts a public key to a decoded address for a specific network.
7676
* @param {Uint8Array} publicKey The public key.
7777
* @param {number} networkIdentifier The network identifier.
78-
* @param {SignSchema} signSchema The Sign Schema (NIS / Catapult)
78+
* @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3)
7979
* @returns {Uint8Array} The decoded address corresponding to the inputs.
8080
*/
8181
public static publicKeyToAddress = (publicKey: Uint8Array,
8282
networkIdentifier: number,
83-
signSchema: SignSchema = SignSchema.Catapult): Uint8Array => {
83+
signSchema: SignSchema = SignSchema.SHA3): Uint8Array => {
8484
// step 1: sha3 hash of the public key
85-
const publicKeyHash = signSchema === SignSchema.Catapult ? sha3_256.arrayBuffer(publicKey) : keccak256.arrayBuffer(publicKey);
85+
const publicKeyHash = signSchema === SignSchema.SHA3 ? sha3_256.arrayBuffer(publicKey) : keccak256.arrayBuffer(publicKey);
8686

8787
// step 2: ripemd160 hash of (1)
8888
const ripemdHash = new RIPEMD160().update(new Buffer(publicKeyHash)).digest();
@@ -93,7 +93,7 @@ export class RawAddress {
9393
RawArray.copy(decodedAddress, ripemdHash, RawAddress.constants.sizes.ripemd160, 1);
9494

9595
// step 4: concatenate (3) and the checksum of (3)
96-
const hash = signSchema === SignSchema.Catapult ?
96+
const hash = signSchema === SignSchema.SHA3 ?
9797
sha3_256.arrayBuffer(decodedAddress.subarray(0, RawAddress.constants.sizes.ripemd160 + 1)) :
9898
keccak256.arrayBuffer(decodedAddress.subarray(0, RawAddress.constants.sizes.ripemd160 + 1));
9999
RawArray.copy(decodedAddress, RawArray.uint8View(hash),
@@ -105,11 +105,11 @@ export class RawAddress {
105105
/**
106106
* Determines the validity of a decoded address.
107107
* @param {Uint8Array} decoded The decoded address.
108-
* @param {SignSchema} signSchema The Sign Schema (NIS / Catapult)
108+
* @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3)
109109
* @returns {boolean} true if the decoded address is valid, false otherwise.
110110
*/
111-
public static isValidAddress = (decoded: Uint8Array, signSchema: SignSchema = SignSchema.Catapult): boolean => {
112-
const hash = signSchema === SignSchema.Catapult ? sha3_256.create() : keccak256.create();
111+
public static isValidAddress = (decoded: Uint8Array, signSchema: SignSchema = SignSchema.SHA3): boolean => {
112+
const hash = signSchema === SignSchema.SHA3 ? sha3_256.create() : keccak256.create();
113113
const checksumBegin = RawAddress.constants.sizes.addressDecoded - RawAddress.constants.sizes.checksum;
114114
hash.update(decoded.subarray(0, checksumBegin));
115115
const checksum = new Uint8Array(RawAddress.constants.sizes.checksum);

src/infrastructure/builders/AggregateTransaction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export class AggregateTransaction extends VerifiableTransaction {
3636
super(bytes, AggregateTransactionSchema);
3737
}
3838

39-
signTransactionWithCosigners(initializer, cosigners, generationHash, signSchema: SignSchema = SignSchema.Catapult) {
39+
signTransactionWithCosigners(initializer, cosigners, generationHash, signSchema: SignSchema = SignSchema.SHA3) {
4040
const signedTransaction = this.signTransaction(initializer, generationHash, signSchema);
4141
cosigners.forEach((cosigner) => {
4242
const signatureTransaction = new CosignatureTransaction(signedTransaction.hash);

src/infrastructure/builders/VerifiableTransaction.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ export class VerifiableTransaction {
6060
/**
6161
* @param {KeyPair } keyPair KeyPair instance
6262
* @param {string} generationHash Network generation hash hex
63-
* @param {SignSchema} signSchema The Sign Schema (NIS / Catapult)
63+
* @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3)
6464
* @returns {module:model/TransactionPayload} - Signed Transaction Payload
6565
*/
66-
signTransaction(keyPair, generationHash, signSchema: SignSchema = SignSchema.Catapult) {
66+
signTransaction(keyPair, generationHash, signSchema: SignSchema = SignSchema.SHA3) {
6767
const generationHashBytes = Array.from(convert.hexToUint8(generationHash));
6868
const byteBuffer = this.serialize();
6969
const signingBytes = generationHashBytes.concat(byteBuffer.slice(4 + 64 + 32));
@@ -95,10 +95,10 @@ export class VerifiableTransaction {
9595

9696
/**
9797
* @param {KeyPair} keyPair KeyPair instance
98-
* @param {SignSchema} signSchema The Sign Schema (NIS / Catapult)
98+
* @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3)
9999
* @returns {module:model/TransactionPayload} Returns TransactionPayload instance
100100
*/
101-
signCosignatoriesTransaction(keyPair, signSchema: SignSchema = SignSchema.Catapult) {
101+
signCosignatoriesTransaction(keyPair, signSchema: SignSchema = SignSchema.SHA3) {
102102
const signature = KeyPair.sign(keyPair, new Uint8Array(this.bytes), signSchema);
103103
return {
104104
parentHash: convert.uint8ToHex(this.bytes),

0 commit comments

Comments
 (0)