Adjust nacl imports (#756)

This commit is contained in:
Jaco Greeff
2020-11-08 19:42:13 +01:00
committed by GitHub
parent 12d8b07ff1
commit 055c4f82f5
11 changed files with 22 additions and 22 deletions
@@ -3,7 +3,7 @@
import { Keypair } from '../../types';
import nacl from 'tweetnacl';
import { box } from 'tweetnacl';
/**
* @name naclBoxKeypairFromSecret
@@ -20,5 +20,5 @@ import nacl from 'tweetnacl';
* ```
*/
export function naclBoxKeypairFromSecret (secret: Uint8Array): Keypair {
return nacl.box.keyPair.fromSecretKey(secret.slice(0, 32));
return box.keyPair.fromSecretKey(secret.slice(0, 32));
}
+2 -2
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2020 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import nacl from 'tweetnacl';
import { secretbox } from 'tweetnacl';
/**
* @name naclDecrypt
@@ -18,5 +18,5 @@ import nacl from 'tweetnacl';
* ```
*/
export function naclDecrypt (encrypted: Uint8Array, nonce: Uint8Array, secret: Uint8Array): Uint8Array | null {
return nacl.secretbox.open(encrypted, nonce, secret) || null;
return secretbox.open(encrypted, nonce, secret) || null;
}
+2 -2
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2020 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import nacl from 'tweetnacl';
import { secretbox } from 'tweetnacl';
import { randomAsU8a } from '../random/asU8a';
@@ -26,7 +26,7 @@ interface Encrypted {
*/
export function naclEncrypt (message: Uint8Array, secret: Uint8Array, nonce: Uint8Array = randomAsU8a(24)): Encrypted {
return {
encrypted: nacl.secretbox(message, nonce, secret),
encrypted: secretbox(message, nonce, secret),
nonce
};
}
@@ -3,7 +3,7 @@
import { Keypair } from '../../types';
import nacl from 'tweetnacl';
import { sign } from 'tweetnacl';
/**
* @name naclKeypairFromRandom
@@ -20,5 +20,5 @@ import nacl from 'tweetnacl';
* ```
*/
export function naclKeypairFromRandom (): Keypair {
return nacl.sign.keyPair();
return sign.keyPair();
}
@@ -3,7 +3,7 @@
import { Keypair } from '../../types';
import nacl from 'tweetnacl';
import { sign } from 'tweetnacl';
/**
* @name naclKeypairFromSecret
@@ -20,5 +20,5 @@ import nacl from 'tweetnacl';
* ```
*/
export function naclKeypairFromSecret (secret: Uint8Array): Keypair {
return nacl.sign.keyPair.fromSecretKey(secret);
return sign.keyPair.fromSecretKey(secret);
}
@@ -3,7 +3,7 @@
import { Keypair } from '../../types';
import nacl from 'tweetnacl';
import { sign } from 'tweetnacl';
import { isReady, ed25519KeypairFromSeed } from '@polkadot/wasm-crypto';
/**
@@ -30,5 +30,5 @@ export function naclKeypairFromSeed (seed: Uint8Array): Keypair {
};
}
return nacl.sign.keyPair.fromSeed(seed);
return sign.keyPair.fromSeed(seed);
}
+2 -2
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2020 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import nacl from 'tweetnacl';
import { box } from 'tweetnacl';
/**
* @name naclOpen
@@ -18,5 +18,5 @@ import nacl from 'tweetnacl';
* ```
*/
export function naclOpen (sealed: Uint8Array, nonce: Uint8Array, senderBoxPublic: Uint8Array, receiverBoxSecret: Uint8Array): Uint8Array | null {
return nacl.box.open(sealed, nonce, senderBoxPublic, receiverBoxSecret) || null;
return box.open(sealed, nonce, senderBoxPublic, receiverBoxSecret) || null;
}
+2 -2
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2020 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import nacl from 'tweetnacl';
import { box } from 'tweetnacl';
import { randomAsU8a } from '../random/asU8a';
@@ -27,6 +27,6 @@ interface Sealed {
export function naclSeal (message: Uint8Array, senderBoxSecret: Uint8Array, receiverBoxPublic: Uint8Array, nonce: Uint8Array = randomAsU8a(24)): Sealed {
return {
nonce,
sealed: nacl.box(message, nonce, receiverBoxPublic, senderBoxSecret)
sealed: box(message, nonce, receiverBoxPublic, senderBoxSecret)
};
}
+2 -2
View File
@@ -3,7 +3,7 @@
import { Keypair } from '../types';
import nacl from 'tweetnacl';
import { sign } from 'tweetnacl';
import { assert, u8aToU8a } from '@polkadot/util';
import { isReady, ed25519Sign } from '@polkadot/wasm-crypto';
@@ -28,5 +28,5 @@ export function naclSign (message: Uint8Array | string, { publicKey, secretKey }
return isReady()
? ed25519Sign(publicKey as Uint8Array, secretKey.subarray(0, 32), messageU8a)
: nacl.sign.detached(messageU8a, secretKey);
: sign.detached(messageU8a, secretKey);
}
+2 -2
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2020 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import nacl from 'tweetnacl';
import { sign } from 'tweetnacl';
import { assert, u8aToU8a } from '@polkadot/util';
import { isReady, ed25519Verify } from '@polkadot/wasm-crypto';
@@ -29,5 +29,5 @@ export function naclVerify (message: Uint8Array | string, signature: Uint8Array
return isReady()
? ed25519Verify(signatureU8a, messageU8a, publicKeyU8a)
: nacl.sign.detached.verify(messageU8a, signatureU8a, publicKeyU8a);
: sign.detached.verify(messageU8a, signatureU8a, publicKeyU8a);
}
+2 -2
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2020 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import nacl from 'tweetnacl';
import { hash } from 'tweetnacl';
import { isReady, sha512 } from '@polkadot/wasm-crypto';
/**
@@ -21,5 +21,5 @@ import { isReady, sha512 } from '@polkadot/wasm-crypto';
export function sha512AsU8a (data: Uint8Array): Uint8Array {
return isReady()
? sha512(data)
: nacl.hash(data);
: hash(data);
}