Skip to content

Commit f1b42d1

Browse files
authored
Merge pull request #1630 from input-output-hk/refactor/bip32account-bip32ed25519-di
feat: bip32account bip32ed25519 dependency injection LW-12941
2 parents 06944bc + b56110c commit f1b42d1

File tree

62 files changed

+311
-293
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+311
-293
lines changed

packages/cardano-services/src/StakePool/HttpStakePoolMetadata/HttpStakePoolMetadataService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export const createHttpStakePoolMetadataService = (
6969
const { data } = await axiosClient.get<Uint8Array>(url, { responseType: 'arraybuffer' });
7070

7171
// Produce metadata hash
72-
const metadataHash = Crypto.blake2b(Crypto.blake2b.BYTES).update(data).digest('hex');
72+
const metadataHash = Crypto.blake2b.hash(HexBlob.fromBytes(data), 32);
7373

7474
// Verify base hashes
7575
if (metadataHash !== hash) {

packages/cardano-services/test/StakePool/HttpStakePoolMetadataService/HttpMetadataService.test.ts

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Cardano } from '@cardano-sdk/core';
55
import { DataMocks } from '../../data-mocks';
66
import { ExtMetadataFormat } from '../../../src/StakePool/types';
77
import { Hash32ByteBase16 } from '@cardano-sdk/crypto';
8+
import { HexBlob } from '@cardano-sdk/util';
89
import { IncomingMessage } from 'http';
910
import {
1011
StakePoolMetadataServiceError,
@@ -90,15 +91,13 @@ describe('StakePoolMetadataService', () => {
9091

9192
// Since the extended metadata URL will change each run and its part of the metadata, we must
9293
// recalculate metadata the hash.
93-
const metadataHash = Crypto.blake2b(Crypto.blake2b.BYTES)
94-
.update(Buffer.from(JSON.stringify(metadata), 'ascii'))
95-
.digest('hex');
96-
97-
const resultMetadata = await metadataService.getStakePoolMetadata(
98-
metadataHash as Hash32ByteBase16,
99-
`${serverUrl}/metadata`
94+
const metadataHash = Crypto.blake2b.hash<Hash32ByteBase16>(
95+
HexBlob.fromBytes(Buffer.from(JSON.stringify(metadata), 'ascii')),
96+
32
10097
);
10198

99+
const resultMetadata = await metadataService.getStakePoolMetadata(metadataHash, `${serverUrl}/metadata`);
100+
102101
expect(resultMetadata).toEqual(metadata);
103102

104103
const resultExtendedMetadata = await metadataService.getValidateStakePoolExtendedMetadata(
@@ -249,14 +248,9 @@ describe('StakePoolMetadataService', () => {
249248
extVkey: INVALID_KEY
250249
};
251250

252-
const metadataHash = Crypto.blake2b(Crypto.blake2b.BYTES)
253-
.update(Buffer.from(JSON.stringify(metadata), 'ascii'))
254-
.digest('hex');
251+
const metadataHash = Crypto.blake2b.hash(HexBlob.fromBytes(Buffer.from(JSON.stringify(metadata), 'ascii')), 32);
255252

256-
const metadataResult = await metadataService.getStakePoolMetadata(
257-
metadataHash as Hash32ByteBase16,
258-
`${serverUrl}/metadata`
259-
);
253+
const metadataResult = await metadataService.getStakePoolMetadata(metadataHash, `${serverUrl}/metadata`);
260254

261255
const result2 = await metadataService.getValidateStakePoolExtendedMetadata(
262256
metadataResult as Cardano.StakePoolMetadata

packages/core/src/Cardano/types/Asset.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,7 @@ export const AssetFingerprint = (value: string): AssetFingerprint => typedBech32
6464
AssetFingerprint.fromParts = (policyId: PolicyId, assetName: AssetName): AssetFingerprint => {
6565
const policyBuf = Buffer.from(policyId, 'hex');
6666
const assetNameBuf = Buffer.from(assetName, 'hex');
67-
const hexDigest = HexBlob(
68-
Crypto.blake2b(20)
69-
.update(new Uint8Array([...policyBuf, ...assetNameBuf]))
70-
.digest('hex')
71-
);
67+
const hexDigest = Crypto.blake2b.hash(HexBlob.fromBytes(new Uint8Array([...policyBuf, ...assetNameBuf])), 20);
7268

7369
return AssetFingerprint(HexBlob.toTypedBech32<string>('asset', hexDigest));
7470
};

packages/core/src/Cardano/types/AuxiliaryData.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import * as Crypto from '@cardano-sdk/crypto';
22
import * as Serialization from '../../Serialization/AuxiliaryData';
33
import { Hash32ByteBase16 } from '@cardano-sdk/crypto';
44
import { Script } from './Script';
5-
import { hexToBytes } from '../../util/misc';
65

76
// eslint-disable-next-line no-use-before-define
87
export type MetadatumMap = Map<Metadatum, Metadatum>;
@@ -17,10 +16,4 @@ export interface AuxiliaryData {
1716
}
1817

1918
export const computeAuxiliaryDataHash = (data: AuxiliaryData | undefined): Hash32ByteBase16 | undefined =>
20-
data
21-
? Hash32ByteBase16(
22-
Crypto.blake2b(Crypto.blake2b.BYTES)
23-
.update(hexToBytes(Serialization.AuxiliaryData.fromCore(data).toCbor()))
24-
.digest('hex')
25-
)
26-
: undefined;
19+
data ? Crypto.blake2b.hash<Hash32ByteBase16>(Serialization.AuxiliaryData.fromCore(data).toCbor(), 32) : undefined;

packages/core/src/Cardano/types/StakePool/primitives.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const PoolId = (value: string): PoolId => typedBech32(value, 'pool', 45);
1818
* @param {string} value blake2b_224 digest of an operator verification key hash
1919
* @throws InvalidStringError
2020
*/
21-
PoolId.fromKeyHash = (value: Crypto.Ed25519KeyHashHex): PoolId => HexBlob.toTypedBech32('pool', HexBlob(value));
21+
PoolId.fromKeyHash = (value: Crypto.Ed25519KeyHashHex): PoolId => HexBlob.toTypedBech32('pool', value);
2222

2323
/** /** pool operator verification key hash as hex string */
2424
export type PoolIdHex = OpaqueString<'PoolIdHex'>;

packages/core/src/Cardano/types/Transaction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { RewardAccount } from '../Address';
1313
import { Script } from './Script';
1414

1515
/** transaction hash as hex string */
16-
export type TransactionId = OpaqueString<'TransactionId'>;
16+
export type TransactionId = OpaqueString<'TransactionId'> & Crypto.Hash32ByteBase16;
1717

1818
/**
1919
* @param {string} value transaction hash as hex string

packages/core/src/Cardano/util/computeImplicitCoin.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,7 @@ const computeConwayDeposits = (
102102
case Cardano.CertificateType.UnregisterDelegateRepresentative:
103103
if (
104104
!dRepKeyHash ||
105-
(cert.dRepCredential.type === Address.CredentialType.KeyHash &&
106-
cert.dRepCredential.hash === Crypto.Hash28ByteBase16.fromEd25519KeyHashHex(dRepKeyHash))
105+
(cert.dRepCredential.type === Address.CredentialType.KeyHash && cert.dRepCredential.hash === dRepKeyHash)
107106
) {
108107
cert.__typename === Cardano.CertificateType.RegisterDelegateRepresentative
109108
? (deposit += cert.deposit)

packages/core/src/Serialization/PlutusData/PlutusData.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,7 @@ export class PlutusData {
235235
* @returns the plutus data hash.
236236
*/
237237
hash(): Crypto.Hash32ByteBase16 {
238-
const hash = Crypto.blake2b(HASH_LENGTH_IN_BYTES).update(Buffer.from(this.toCbor(), 'hex')).digest();
239-
240-
return Crypto.Hash32ByteBase16(HexBlob.fromBytes(hash));
238+
return Crypto.blake2b.hash(this.toCbor(), HASH_LENGTH_IN_BYTES);
241239
}
242240

243241
/**

packages/core/src/Serialization/Scripts/NativeScript/NativeScript.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,9 @@ export class NativeScript {
182182
hash(): Crypto.Hash28ByteBase16 {
183183
// To compute a script hash, note that you must prepend a tag to the bytes of
184184
// the script before hashing. The tags in the Babbage era for native scripts is "\x00"
185-
const bytes = `00${this.toCbor()}`;
185+
const bytes = `00${this.toCbor()}` as HexBlob;
186186

187-
const hash = Crypto.blake2b(HASH_LENGTH_IN_BYTES).update(Buffer.from(bytes, 'hex')).digest();
188-
189-
return Crypto.Hash28ByteBase16(HexBlob.fromBytes(hash));
187+
return Crypto.blake2b.hash(bytes, HASH_LENGTH_IN_BYTES);
190188
}
191189

192190
/**

packages/core/src/Serialization/Scripts/PlutusScript/PlutusV1Script.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,9 @@ export class PlutusV1Script {
8989
hash(): Crypto.Hash28ByteBase16 {
9090
// To compute a script hash, note that you must prepend a tag to the bytes of
9191
// the script before hashing. The tags in the Babbage era for PlutusV1 is "\x01"
92-
const bytes = `01${this.rawBytes()}`;
92+
const bytes = `01${this.rawBytes()}` as HexBlob;
9393

94-
const hash = Crypto.blake2b(HASH_LENGTH_IN_BYTES).update(Buffer.from(bytes, 'hex')).digest();
95-
96-
return Crypto.Hash28ByteBase16(HexBlob.fromBytes(hash));
94+
return Crypto.blake2b.hash(bytes, HASH_LENGTH_IN_BYTES);
9795
}
9896

9997
/**

packages/core/src/Serialization/Scripts/PlutusScript/PlutusV2Script.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,9 @@ export class PlutusV2Script {
9797
hash(): Crypto.Hash28ByteBase16 {
9898
// To compute a script hash, note that you must prepend a tag to the bytes of
9999
// the script before hashing. The tags in the Babbage era for PlutusV2 is "\x02"
100-
const bytes = `02${this.rawBytes()}`;
100+
const bytes = `02${this.rawBytes()}` as HexBlob;
101101

102-
const hash = Crypto.blake2b(HASH_LENGTH_IN_BYTES).update(Buffer.from(bytes, 'hex')).digest();
103-
104-
return Crypto.Hash28ByteBase16(HexBlob.fromBytes(hash));
102+
return Crypto.blake2b.hash(bytes, HASH_LENGTH_IN_BYTES);
105103
}
106104

107105
/**

packages/core/src/Serialization/Scripts/PlutusScript/PlutusV3Script.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,9 @@ export class PlutusV3Script {
9797
hash(): Crypto.Hash28ByteBase16 {
9898
// To compute a script hash, note that you must prepend a tag to the bytes of
9999
// the script before hashing. The tags in the Conway era for PlutusV3 is "\x03"
100-
const bytes = `03${this.rawBytes()}`;
100+
const bytes = `03${this.rawBytes()}` as HexBlob;
101101

102-
const hash = Crypto.blake2b(HASH_LENGTH_IN_BYTES).update(Buffer.from(bytes, 'hex')).digest();
103-
104-
return Crypto.Hash28ByteBase16(HexBlob.fromBytes(hash));
102+
return Crypto.blake2b.hash(bytes, HASH_LENGTH_IN_BYTES);
105103
}
106104

107105
/**

packages/core/src/Serialization/Transaction.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import type * as Cardano from '../Cardano';
99
const ALONZO_ERA_TX_FRAME_SIZE = 4;
1010

1111
/** Transaction serialized as CBOR, encoded as hex string */
12-
export type TxCBOR = OpaqueString<'TxCbor'>;
12+
export type TxCBOR = OpaqueString<'TxCbor'> & HexBlob;
1313
/** Transaction body serialized as CBOR, encoded as hex string */
14-
export type TxBodyCBOR = OpaqueString<'TxBodyCbor' & HexBlob['__opaqueString']>;
14+
export type TxBodyCBOR = OpaqueString<'TxBodyCbor'> & HexBlob;
1515

1616
/**
1717
* A transaction is a record of value transfer between two or more addresses on the network. It represents a request

packages/core/src/Serialization/TransactionBody/TransactionBody.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -933,8 +933,7 @@ export class TransactionBody {
933933
* @returns The hash of the transaction body.
934934
*/
935935
hash() {
936-
const hash = Crypto.blake2b(Crypto.blake2b.BYTES).update(hexToBytes(this.toCbor())).digest();
937-
return TransactionId.fromHexBlob(HexBlob.fromBytes(hash));
936+
return Crypto.blake2b.hash<TransactionId>(this.toCbor(), 32);
938937
}
939938

940939
/**

packages/core/src/Serialization/TransactionWitnessSet/Redeemer/Redeemer.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,6 @@ export class Redeemer {
253253
* @returns the redeemer hash.
254254
*/
255255
hash(): Crypto.Hash32ByteBase16 {
256-
const hash = Crypto.blake2b(HASH_LENGTH_IN_BYTES).update(Buffer.from(this.toCbor(), 'hex')).digest();
257-
258-
return Crypto.Hash32ByteBase16(HexBlob.fromBytes(hash));
256+
return Crypto.blake2b.hash(this.toCbor(), HASH_LENGTH_IN_BYTES);
259257
}
260258
}

packages/core/test/Cardano/util/computeImplicitCoin.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,15 @@ describe('Cardano.util.computeImplicitCoin', () => {
139139
__typename: Cardano.CertificateType.RegisterDelegateRepresentative,
140140
anchor: null,
141141
dRepCredential: {
142-
hash: Crypto.Hash28ByteBase16.fromEd25519KeyHashHex(dRepKeyHash),
142+
hash: dRepKeyHash,
143143
type: Cardano.CredentialType.KeyHash
144144
} as Cardano.Credential,
145145
deposit: drepDeposit
146146
},
147147
{
148148
__typename: Cardano.CertificateType.UnregisterDelegateRepresentative,
149149
dRepCredential: {
150-
hash: Crypto.Hash28ByteBase16.fromEd25519KeyHashHex(dRepKeyHash),
150+
hash: dRepKeyHash,
151151
type: Cardano.CredentialType.KeyHash
152152
} as Cardano.Credential,
153153
deposit: drepDeposit

packages/crypto/src/Bip32/Bip32PublicKey.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import * as Bip32KeyDerivation from './Bip32KeyDerivation';
2-
import { BIP32_PUBLIC_KEY_HASH_LENGTH, Bip32PublicKeyHashHex, Bip32PublicKeyHex } from '../hexTypes';
3-
import { ED25519_PUBLIC_KEY_LENGTH, Ed25519PublicKey } from '../Ed25519e';
2+
import {
3+
BIP32_PUBLIC_KEY_HASH_LENGTH,
4+
Bip32PublicKeyHashHex,
5+
Bip32PublicKeyHex,
6+
ED25519_PUBLIC_KEY_LENGTH
7+
} from '../hexTypes';
8+
import { Ed25519PublicKey } from '../Ed25519e';
49
import { InvalidArgumentError } from '@cardano-sdk/util';
510
import sodium from 'libsodium-wrappers-sumo';
611

packages/crypto/src/Ed25519e/Ed25519PublicKey.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import { ED25519_PUBLIC_KEY_HASH_LENGTH, Ed25519KeyHash } from './Ed25519KeyHash';
2-
import { Ed25519PublicKeyHex } from '../hexTypes';
2+
import { ED25519_PUBLIC_KEY_LENGTH, Ed25519PublicKeyHex } from '../hexTypes';
33
import { Ed25519Signature } from './Ed25519Signature';
44
import { HexBlob, InvalidArgumentError } from '@cardano-sdk/util';
55
import sodium from 'libsodium-wrappers-sumo';
66

7-
export const ED25519_PUBLIC_KEY_LENGTH = 32;
8-
97
/**
108
* Ed25519 raw public key. This key can be used for cryptographically verifying messages
119
* previously signed with the matching Ed25519 raw private key.

packages/crypto/src/blake2b-hash.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { HexBlob, hexStringToBuffer } from '@cardano-sdk/util';
2+
import hash from 'blake2b';
3+
import type { Hash28ByteBase16, Hash32ByteBase16 } from './hexTypes';
4+
5+
export interface Blake2b {
6+
/**
7+
* blake2b-256
8+
*
9+
* @param message payload to hash
10+
* @param outputLengthBytes digest size, e.g. 28 for blake2b-224 or 32 for blake2b-256
11+
*/
12+
hash<T extends Hash32ByteBase16>(message: HexBlob, outputLengthBytes: 32): T;
13+
/**
14+
* blake2b-224
15+
*
16+
* @param message payload to hash
17+
* @param outputLengthBytes digest size, e.g. 28 for blake2b-224 or 32 for blake2b-256
18+
*/
19+
hash<T extends Hash28ByteBase16>(message: HexBlob, outputLengthBytes: 28): T;
20+
/**
21+
* @param message payload to hash
22+
* @param outputLengthBytes digest size, e.g. 28 for blake2b-224 or 32 for blake2b-256
23+
*/
24+
hash<T extends HexBlob>(message: HexBlob, outputLengthBytes: number): T;
25+
}
26+
27+
export const blake2b: Blake2b = {
28+
hash<T extends HexBlob>(message: HexBlob, outputLengthBytes: number) {
29+
return hash(outputLengthBytes).update(hexStringToBuffer(message)).digest('hex') as T;
30+
}
31+
};

packages/crypto/src/hexTypes.ts

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,57 @@
11
import { HexBlob, OpaqueString, castHexBlob, typedHex } from '@cardano-sdk/util';
22

33
export const BIP32_PUBLIC_KEY_HASH_LENGTH = 28;
4+
export const ED25519_PUBLIC_KEY_LENGTH = 32;
5+
6+
/** 28 byte hash as hex string */
7+
export type Hash28ByteBase16 = OpaqueString<'Hash28ByteBase16'> & HexBlob;
8+
/**
9+
* @param {string} value 28 byte hash as hex string
10+
* @throws InvalidStringError
11+
*/
12+
export const Hash28ByteBase16 = (value: string): Hash28ByteBase16 => typedHex<Hash28ByteBase16>(value, 56);
13+
14+
/** 32 byte hash as hex string */
15+
export type Hash32ByteBase16 = OpaqueString<'Hash32ByteBase16'> & HexBlob;
16+
/**
17+
* @param {string} value 32 byte hash as hex string
18+
* @throws InvalidStringError
19+
*/
20+
export const Hash32ByteBase16 = (value: string): Hash32ByteBase16 => typedHex<Hash32ByteBase16>(value, 64);
21+
Hash32ByteBase16.fromHexBlob = <T>(value: HexBlob) => castHexBlob<T>(value, 64);
422

523
/** Ed25519 signature as hex string */
6-
export type Ed25519SignatureHex = OpaqueString<'Ed25519SignatureHex'>;
24+
export type Ed25519SignatureHex = OpaqueString<'Ed25519SignatureHex'> & HexBlob;
725
export const Ed25519SignatureHex = (value: string): Ed25519SignatureHex => typedHex(value, 128);
826

927
/** BIP32 public key as hex string */
10-
export type Bip32PublicKeyHex = OpaqueString<'Bip32PublicKeyHex'>;
28+
export type Bip32PublicKeyHex = OpaqueString<'Bip32PublicKeyHex'> & HexBlob;
1129
export const Bip32PublicKeyHex = (key: string): Bip32PublicKeyHex => typedHex(key, 128);
1230

1331
/** BIP32 private key as hex string */
14-
export type Bip32PrivateKeyHex = OpaqueString<'Bip32PrivateKeyHex'>;
32+
export type Bip32PrivateKeyHex = OpaqueString<'Bip32PrivateKeyHex'> & HexBlob;
1533
export const Bip32PrivateKeyHex = (key: string): Bip32PrivateKeyHex => typedHex(key, 192);
1634

1735
/** Ed25519 public key as hex string */
18-
export type Ed25519PublicKeyHex = OpaqueString<'Ed25519PublicKeyHex'>;
19-
export const Ed25519PublicKeyHex = (value: string): Ed25519PublicKeyHex => typedHex(value, 64);
36+
export type Ed25519PublicKeyHex = OpaqueString<'Ed25519PublicKeyHex'> & HexBlob;
37+
export const Ed25519PublicKeyHex = (value: string): Ed25519PublicKeyHex =>
38+
typedHex(value, ED25519_PUBLIC_KEY_LENGTH * HexBlob.CHARS_PER_BYTE);
39+
Ed25519PublicKeyHex.fromBip32PublicKey = (bip32PublicKey: Bip32PublicKeyHex): Ed25519PublicKeyHex =>
40+
bip32PublicKey.slice(0, ED25519_PUBLIC_KEY_LENGTH * HexBlob.CHARS_PER_BYTE) as Ed25519PublicKeyHex;
2041

2142
/** Ed25519 private extended key as hex string */
22-
export type Ed25519PrivateExtendedKeyHex = OpaqueString<'Ed25519PrivateKeyHex'>;
43+
export type Ed25519PrivateExtendedKeyHex = OpaqueString<'Ed25519PrivateKeyHex'> & HexBlob;
2344
export const Ed25519PrivateExtendedKeyHex = (value: string): Ed25519PrivateExtendedKeyHex => typedHex(value, 128);
2445

2546
/** Ed25519 private normal key as hex string */
26-
export type Ed25519PrivateNormalKeyHex = OpaqueString<'Ed25519PrivateKeyHex'>;
47+
export type Ed25519PrivateNormalKeyHex = OpaqueString<'Ed25519PrivateKeyHex'> & HexBlob;
2748
export const Ed25519PrivateNormalKeyHex = (value: string): Ed25519PrivateNormalKeyHex => typedHex(value, 64);
2849

2950
/** 28 byte ED25519 key hash as hex string */
30-
export type Ed25519KeyHashHex = OpaqueString<'Ed25519KeyHashHex'>;
51+
export type Ed25519KeyHashHex = OpaqueString<'Ed25519KeyHashHex'> & Hash28ByteBase16 & HexBlob;
3152
export const Ed25519KeyHashHex = (value: string): Ed25519KeyHashHex => typedHex(value, 56);
3253

3354
/** 28 byte BIP32 public key hash as hex string */
34-
export type Bip32PublicKeyHashHex = OpaqueString<'Bip32PublicKeyHashHex'>;
55+
export type Bip32PublicKeyHashHex = OpaqueString<'Bip32PublicKeyHashHex'> & HexBlob;
3556
export const Bip32PublicKeyHashHex = (value: string): Bip32PublicKeyHashHex =>
36-
typedHex(value, BIP32_PUBLIC_KEY_HASH_LENGTH * 2);
37-
38-
/** 32 byte hash as hex string */
39-
export type Hash32ByteBase16 = OpaqueString<'Hash32ByteBase16'>;
40-
41-
/**
42-
* @param {string} value 32 byte hash as hex string
43-
* @throws InvalidStringError
44-
*/
45-
export const Hash32ByteBase16 = (value: string): Hash32ByteBase16 => typedHex<Hash32ByteBase16>(value, 64);
46-
Hash32ByteBase16.fromHexBlob = <T>(value: HexBlob) => castHexBlob<T>(value, 64);
47-
48-
/** 28 byte hash as hex string */
49-
export type Hash28ByteBase16 = OpaqueString<'Hash28ByteBase16'>;
50-
51-
/**
52-
* @param {string} value 28 byte hash as hex string
53-
* @throws InvalidStringError
54-
*/
55-
export const Hash28ByteBase16 = (value: string): Hash28ByteBase16 => typedHex<Hash28ByteBase16>(value, 56);
56-
/** Ed25519KeyHashHex is a 28 byte hash. This is a utility function that downcasts without validation. */
57-
Hash28ByteBase16.fromEd25519KeyHashHex = (value: Ed25519KeyHashHex) => value as unknown as Hash28ByteBase16;
57+
typedHex(value, BIP32_PUBLIC_KEY_HASH_LENGTH * HexBlob.CHARS_PER_BYTE);

packages/crypto/src/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import blake2b from 'blake2b';
21
import sodium from 'libsodium-wrappers-sumo';
3-
export { blake2b };
42

3+
export * from './blake2b-hash';
54
export * from './Bip32';
65
export * from './Bip32Ed25519';
76
export * from './Ed25519e';

0 commit comments

Comments
 (0)