ghost-portal/packages/react-signer/src/signers/AccountSigner.ts
Tarik Gul 384049fb6b
2025 (#11172)
* 2025

* update ci scripts to add access to scripts
2025-01-03 03:59:53 +02:00

34 lines
1.0 KiB
TypeScript

// Copyright 2017-2025 @polkadot/react-signer authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Signer, SignerResult } from '@polkadot/api/types';
import type { KeyringPair } from '@polkadot/keyring/types';
import type { Registry, SignerPayloadJSON } from '@polkadot/types/types';
import { objectSpread } from '@polkadot/util';
import { lockAccount } from '../util.js';
let id = 0;
export class AccountSigner implements Signer {
readonly #keyringPair: KeyringPair;
readonly #registry: Registry;
constructor (registry: Registry, keyringPair: KeyringPair) {
this.#keyringPair = keyringPair;
this.#registry = registry;
}
public async signPayload (payload: SignerPayloadJSON): Promise<SignerResult> {
return new Promise((resolve): void => {
const signed = this.#registry.createType('ExtrinsicPayload', payload, { version: payload.version }).sign(this.#keyringPair);
lockAccount(this.#keyringPair);
resolve(
objectSpread({ id: ++id }, signed)
);
});
}
}