[PB-6503] Add download with bucketKey#413
Conversation
| computeHmac?: (key: BinaryData, shardHashes: string[]) => Promise<HmacPayload>; | ||
| }; | ||
|
|
||
| export type CryptoV3 = { |
There was a problem hiding this comment.
Because V3 doesn't need validateMnemonic and generateFileKey anymore. So either I will have to define those functions for compatibility on the front, or I'll need to mark them as optional (with ?) and change the existing API.
There was a problem hiding this comment.
Should I merge both cryptos?
There was a problem hiding this comment.
What it would be good to avoid is to add adhoc interfaces or _VX namings as those tend to be outdated soon and do not mean anything to distinguish them from other versions. Try to extend what exists in the way TypeScript allows you, as long as it has sense. You mention that validateMnemonic and generateFileKey are no longer needed, but the base is the same, thus, you could do:
type CryptoBase = {
algorithm: Algorithm;
randomBytes: (bytesLength: number) => BinaryData;
computeHmac?: (key: BinaryData, shardHashes: string[]) => Promise<HmacPayload>;
};
export type Crypto = CryptoBase & {
validateMnemonic: (mnemonic: string) => boolean;
generateFileKey: (mnemonic: string, bucketId: string, index: BinaryData | string) => Promise<BinaryData>;
};
export type CryptoWithBucketKey = CryptoBase & {
generateFileKeyFromBucketKey: (bucketKey: Buffer, index: BinaryData) => Promise<BinaryData>;
};
For a new share version to work, we need a method for downloading files with the bucket key alone (without mnemonic). This PR adds this method