Pass account & address offsets to Ledger signing (#3712)

This commit is contained in:
Jaco Greeff 2020-09-18 11:09:03 +02:00 committed by GitHub
parent fa72e24971
commit cbb38f3c9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 3 deletions

View File

@ -135,10 +135,10 @@ async function wrapTx (api: ApiPromise, currentItem: QueueTx, { isMultiCall, mul
async function extractParams (address: string, options: Partial<SignerOptions>, setQrState: (state: QrState) => void): Promise<['qr' | 'signing', KeyringPair | string, Partial<SignerOptions>]> {
const pair = keyring.getPair(address);
const { meta: { isExternal, isHardware, isInjected, source } } = pair;
const { meta: { accountOffset, addressOffset, isExternal, isHardware, isInjected, source } } = pair;
if (isHardware) {
return ['signing', address, { ...options, signer: new LedgerSigner() }];
return ['signing', address, { ...options, signer: new LedgerSigner(accountOffset as number || 0, addressOffset as number || 0) }];
} else if (isExternal) {
return ['qr', address, { ...options, signer: new QrSigner(setQrState) }];
} else if (isInjected) {

View File

@ -9,9 +9,17 @@ import { getLedger, registry } from '@polkadot/react-api';
let id = 0;
export default class LedgerSigner implements Signer {
#accountOffset: number;
#addressOffset: number;
constructor (accountOffset: number, addressOffset: number) {
this.#accountOffset = accountOffset;
this.#addressOffset = addressOffset;
}
public async signPayload (payload: SignerPayloadJSON): Promise<SignerResult> {
const raw = registry.createType('ExtrinsicPayload', payload, { version: payload.version });
const { signature } = await getLedger().sign(raw.toU8a(true));
const { signature } = await getLedger().sign(raw.toU8a(true), this.#accountOffset, this.#addressOffset);
return { id: ++id, signature };
}