Adjust nacl imports (#756)
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user