ghost-portal/packages/react-signer/src/signers/LedgerSigner.ts
Jaco Greeff 19d49f09be
Move to Ledger usage with hook (#4195)
* Move ledgerChains to apps-config

* Swap Ledger capabilities to hook

* Fix type usage

* getLedger returns promise

* Revert promise result

* cleanup

* use has ledger support (#4413)

* use hasLedgerSupport

* Bump common

Co-authored-by: Jaco Greeff <jacogr@gmail.com>

Co-authored-by: Thibaut Sardan <33178835+Tbaut@users.noreply.github.com>
2021-01-14 20:58:02 +01:00

30 lines
1.1 KiB
TypeScript

// Copyright 2017-2021 @polkadot/react-signer authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Signer, SignerResult } from '@polkadot/api/types';
import type { Registry, SignerPayloadJSON } from '@polkadot/types/types';
import type { Ledger } from '@polkadot/ui-keyring';
let id = 0;
export default class LedgerSigner implements Signer {
readonly #accountOffset: number;
readonly #addressOffset: number;
readonly #getLedger: () => Ledger;
readonly #registry: Registry;
constructor (registry: Registry, getLedger: () => Ledger, accountOffset: number, addressOffset: number) {
this.#accountOffset = accountOffset;
this.#addressOffset = addressOffset;
this.#getLedger = getLedger;
this.#registry = registry;
}
public async signPayload (payload: SignerPayloadJSON): Promise<SignerResult> {
const raw = this.#registry.createType('ExtrinsicPayload', payload, { version: payload.version });
const { signature } = await this.#getLedger().sign(raw.toU8a(true), this.#accountOffset, this.#addressOffset);
return { id: ++id, signature };
}
}