import { HardwareSigningKeyT, HardwareWalletT, SignHashInput } from './_types' import { Observable } from 'rxjs' import { ECPointOnCurveT, HDPathRadix, HDPathRadixT, PublicKeyT, SignatureT, } from '@crypto' import { map } from 'rxjs/operators' import { BuiltTransactionReadyToSign } from '@primitives' export const path000H = HDPathRadix.create({ address: { index: 0, isHardened: true }, }) export type HardwareWalletWithoutSK = Omit export const signingKeyWithHardWareWallet = ( hardwareWallet: HardwareWalletWithoutSK, path: HDPathRadixT, verificationPrompt: boolean = true, ): Observable => hardwareWallet .getPublicKey({ path, display: verificationPrompt, // display BIP32 path as part of derivation call. verifyAddressOnly: false, }) .pipe( map((publicKey: PublicKeyT) => ({ publicKey, getPublicKeyDisplayOnlyAddress: (): Observable => { return hardwareWallet.getPublicKey({ path, display: true, // Omits BIP32 path screen on Ledger. verifyAddressOnly: true, }) }, signHash: (hashedMessage: Buffer): Observable => hardwareWallet.signHash({ hashToSign: hashedMessage, path, }), sign: (tx: BuiltTransactionReadyToSign, nonXrdHRP?: string) => hardwareWallet .signTransaction({ tx, path, nonXrdHRP }) .map(o => o.signature), keyExchange: ( publicKeyOfOtherParty: PublicKeyT, display?: 'encrypt' | 'decrypt', ): Observable => hardwareWallet.keyExchange({ display, path, publicKeyOfOtherParty, }), })), )