-
Notifications
You must be signed in to change notification settings - Fork 55
/
stubSignTransaction.ts
40 lines (33 loc) · 1.68 KB
/
stubSignTransaction.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import * as Crypto from '@cardano-sdk/crypto';
import { Cardano } from '@cardano-sdk/core';
import { SignTransactionContext, SignTransactionOptions } from '../types';
import { deepEquals } from '@cardano-sdk/util';
import { ownSignatureKeyPaths } from './ownSignatureKeyPaths';
import uniqWith from 'lodash/uniqWith';
const randomHexChar = () => Math.floor(Math.random() * 16).toString(16);
const randomPublicKey = () => Crypto.Ed25519PublicKeyHex(Array.from({ length: 64 }).map(randomHexChar).join(''));
export interface StubSignTransactionProps {
txBody: Cardano.TxBody;
dRepPublicKey?: Crypto.Ed25519PublicKeyHex;
context: SignTransactionContext;
signTransactionOptions?: SignTransactionOptions;
}
export const stubSignTransaction = async ({
txBody,
context: { knownAddresses, txInKeyPathMap, dRepPublicKey },
signTransactionOptions: { extraSigners, additionalKeyPaths = [] } = {}
}: StubSignTransactionProps): Promise<Cardano.Signatures> => {
const mockSignature = Crypto.Ed25519SignatureHex(
// eslint-disable-next-line max-len
'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'
);
const dRepKeyHash = dRepPublicKey ? (await Crypto.Ed25519PublicKey.fromHex(dRepPublicKey).hash()).hex() : undefined;
const signatureKeyPaths = uniqWith(
[...ownSignatureKeyPaths(txBody, knownAddresses, txInKeyPathMap, dRepKeyHash), ...additionalKeyPaths],
deepEquals
);
const totalSignature = signatureKeyPaths.length + (extraSigners?.length || 0);
const signatureMap = new Map();
for (let i = 0; i < totalSignature; ++i) signatureMap.set(randomPublicKey(), mockSignature);
return signatureMap;
};