Skip to content

Commit 11de7f2

Browse files
authored
Merge pull request #6534 from BitGo/coin-4944
fix(sdk-coin-vet): implement getHashFunction for vet sdk
2 parents 8d5eb43 + 10e0db8 commit 11de7f2

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

modules/sdk-coin-vet/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
]
4141
},
4242
"dependencies": {
43+
"@bitgo/blake2b": "^3.2.4",
4344
"@bitgo/abstract-eth": "^24.8.1",
4445
"@bitgo/sdk-core": "^35.8.0",
4546
"@bitgo/secp256k1": "^1.4.0",

modules/sdk-coin-vet/src/vet.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as _ from 'lodash';
22
import BigNumber from 'bignumber.js';
3+
import blake2b from '@bitgo/blake2b';
34
import {
45
AuditDecryptedKeyParams,
56
BaseCoin,
@@ -19,7 +20,7 @@ import {
1920
import { BaseCoin as StaticsBaseCoin } from '@bitgo/statics';
2021
import utils from './lib/utils';
2122
import { bip32 } from '@bitgo/secp256k1';
22-
import { randomBytes } from 'crypto';
23+
import { randomBytes, Hash } from 'crypto';
2324
import { KeyPair as EthKeyPair } from '@bitgo/abstract-eth';
2425
import { TransactionBuilderFactory } from './lib';
2526
import { ExplainTransactionOptions, VetParseTransactionOptions } from './lib/types';
@@ -216,4 +217,24 @@ export class Vet extends BaseCoin {
216217
/** https://bitgoinc.atlassian.net/browse/COIN-4213 */
217218
throw new Error('Method not implemented.');
218219
}
220+
221+
/**
222+
* Function to get coin specific hash function used to generate transaction digests.
223+
* @returns {@see Hash} hash function if implemented, otherwise throws exception
224+
*/
225+
getHashFunction(): Hash {
226+
const blake = blake2b(32);
227+
228+
// We return an object that mimics the Hash interface
229+
return {
230+
update(data: Buffer | Uint8Array) {
231+
blake.update(data);
232+
return this;
233+
},
234+
digest() {
235+
const uint8Result = blake.digest();
236+
return Buffer.from(uint8Result);
237+
},
238+
} as unknown as Hash;
239+
}
219240
}

0 commit comments

Comments
 (0)