ghost-keychain/packages/extension/src/background/RequestBytesSign.ts
2019-12-06 15:49:37 +01:00

24 lines
885 B
TypeScript

// Copyright 2019 @polkadot/extension authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { KeyringPair } from '@polkadot/keyring/types';
import { RequestSign } from './types';
import { SignerPayloadJSON, SignerPayloadRaw } from '@polkadot/types/types';
import { u8aToHex, hexToU8a } from '@polkadot/util';
import { TypeRegistry } from '@polkadot/types';
export default class RequestBytesSign implements RequestSign {
inner: SignerPayloadJSON | SignerPayloadRaw;
constructor (inner: SignerPayloadRaw) {
this.inner = inner;
}
sign (_registry: TypeRegistry, pair: KeyringPair): { signature: string } {
const inner = this.inner as SignerPayloadRaw;
const signedBytes = pair.sign(hexToU8a(inner.data));
return { signature: u8aToHex(signedBytes) };
}
}