crypto: Add convenience hash functions
This commit is contained in:
parent
cfc362fc2a
commit
8e43dfb82a
@ -2,7 +2,7 @@ export { Bip39 } from "./bip39";
|
||||
export { EnglishMnemonic } from "./englishmnemonic";
|
||||
export { HashFunction } from "./hash";
|
||||
export { Hmac } from "./hmac";
|
||||
export { Keccak256 } from "./keccak";
|
||||
export { Keccak256, keccak256 } from "./keccak";
|
||||
export {
|
||||
Xchacha20poly1305Ietf,
|
||||
xchacha20NonceLength,
|
||||
@ -13,10 +13,10 @@ export {
|
||||
Ed25519Keypair,
|
||||
} from "./libsodium";
|
||||
export { Random } from "./random";
|
||||
export { Ripemd160 } from "./ripemd";
|
||||
export { Ripemd160, ripemd160 } from "./ripemd";
|
||||
export { Secp256k1, Secp256k1Keypair } from "./secp256k1";
|
||||
export { ExtendedSecp256k1Signature, Secp256k1Signature } from "./secp256k1signature";
|
||||
export { Sha1, Sha256, Sha512 } from "./sha";
|
||||
export { Sha1, sha1, Sha256, sha256, Sha512, sha512 } from "./sha";
|
||||
export {
|
||||
HdPath,
|
||||
pathToString,
|
||||
|
||||
@ -24,3 +24,7 @@ export class Keccak256 implements HashFunction {
|
||||
return new Uint8Array(this.impl.digest());
|
||||
}
|
||||
}
|
||||
|
||||
export function keccak256(data: Uint8Array): Uint8Array {
|
||||
return new Keccak256(data).digest();
|
||||
}
|
||||
|
||||
@ -22,3 +22,7 @@ export class Ripemd160 implements HashFunction {
|
||||
return Uint8Array.from(this.impl.digest());
|
||||
}
|
||||
}
|
||||
|
||||
export function ripemd160(data: Uint8Array): Uint8Array {
|
||||
return new Ripemd160(data).digest();
|
||||
}
|
||||
|
||||
@ -26,6 +26,10 @@ export class Sha1 implements HashFunction {
|
||||
}
|
||||
}
|
||||
|
||||
export function sha1(data: Uint8Array): Uint8Array {
|
||||
return new Sha1(data).digest();
|
||||
}
|
||||
|
||||
export class Sha256 implements HashFunction {
|
||||
public readonly blockSize = 512 / 8;
|
||||
|
||||
@ -49,6 +53,10 @@ export class Sha256 implements HashFunction {
|
||||
}
|
||||
}
|
||||
|
||||
export function sha256(data: Uint8Array): Uint8Array {
|
||||
return new Sha256(data).digest();
|
||||
}
|
||||
|
||||
export class Sha512 implements HashFunction {
|
||||
public readonly blockSize = 1024 / 8;
|
||||
|
||||
@ -71,3 +79,7 @@ export class Sha512 implements HashFunction {
|
||||
return new Uint8Array(this.impl.digest());
|
||||
}
|
||||
}
|
||||
|
||||
export function sha512(data: Uint8Array): Uint8Array {
|
||||
return new Sha512(data).digest();
|
||||
}
|
||||
|
||||
6
packages/crypto/types/index.d.ts
vendored
6
packages/crypto/types/index.d.ts
vendored
@ -2,7 +2,7 @@ export { Bip39 } from "./bip39";
|
||||
export { EnglishMnemonic } from "./englishmnemonic";
|
||||
export { HashFunction } from "./hash";
|
||||
export { Hmac } from "./hmac";
|
||||
export { Keccak256 } from "./keccak";
|
||||
export { Keccak256, keccak256 } from "./keccak";
|
||||
export {
|
||||
Xchacha20poly1305Ietf,
|
||||
xchacha20NonceLength,
|
||||
@ -13,10 +13,10 @@ export {
|
||||
Ed25519Keypair,
|
||||
} from "./libsodium";
|
||||
export { Random } from "./random";
|
||||
export { Ripemd160 } from "./ripemd";
|
||||
export { Ripemd160, ripemd160 } from "./ripemd";
|
||||
export { Secp256k1, Secp256k1Keypair } from "./secp256k1";
|
||||
export { ExtendedSecp256k1Signature, Secp256k1Signature } from "./secp256k1signature";
|
||||
export { Sha1, Sha256, Sha512 } from "./sha";
|
||||
export { Sha1, sha1, Sha256, sha256, Sha512, sha512 } from "./sha";
|
||||
export {
|
||||
HdPath,
|
||||
pathToString,
|
||||
|
||||
1
packages/crypto/types/keccak.d.ts
vendored
1
packages/crypto/types/keccak.d.ts
vendored
@ -6,3 +6,4 @@ export declare class Keccak256 implements HashFunction {
|
||||
update(data: Uint8Array): Keccak256;
|
||||
digest(): Uint8Array;
|
||||
}
|
||||
export declare function keccak256(data: Uint8Array): Uint8Array;
|
||||
|
||||
1
packages/crypto/types/ripemd.d.ts
vendored
1
packages/crypto/types/ripemd.d.ts
vendored
@ -6,3 +6,4 @@ export declare class Ripemd160 implements HashFunction {
|
||||
update(data: Uint8Array): Ripemd160;
|
||||
digest(): Uint8Array;
|
||||
}
|
||||
export declare function ripemd160(data: Uint8Array): Uint8Array;
|
||||
|
||||
3
packages/crypto/types/sha.d.ts
vendored
3
packages/crypto/types/sha.d.ts
vendored
@ -6,6 +6,7 @@ export declare class Sha1 implements HashFunction {
|
||||
update(data: Uint8Array): Sha1;
|
||||
digest(): Uint8Array;
|
||||
}
|
||||
export declare function sha1(data: Uint8Array): Uint8Array;
|
||||
export declare class Sha256 implements HashFunction {
|
||||
readonly blockSize: number;
|
||||
private readonly impl;
|
||||
@ -13,6 +14,7 @@ export declare class Sha256 implements HashFunction {
|
||||
update(data: Uint8Array): Sha256;
|
||||
digest(): Uint8Array;
|
||||
}
|
||||
export declare function sha256(data: Uint8Array): Uint8Array;
|
||||
export declare class Sha512 implements HashFunction {
|
||||
readonly blockSize: number;
|
||||
private readonly impl;
|
||||
@ -20,3 +22,4 @@ export declare class Sha512 implements HashFunction {
|
||||
update(data: Uint8Array): Sha512;
|
||||
digest(): Uint8Array;
|
||||
}
|
||||
export declare function sha512(data: Uint8Array): Uint8Array;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user