Pass account & address offsets to Ledger signing (#3712)
This commit is contained in:
parent
fa72e24971
commit
cbb38f3c9a
@ -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) {
|
||||
|
||||
@ -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 };
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user