-
Notifications
You must be signed in to change notification settings - Fork 420
/
Copy pathSigner.ts
45 lines (37 loc) · 1.41 KB
/
Signer.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright 2019-2025 @polkadot/extension-base authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Signer as SignerInterface, SignerResult } from '@polkadot/api/types';
import type { SignerPayloadJSON, SignerPayloadRaw } from '@polkadot/types/types';
import type { SendRequest } from './types.js';
// External to class, this.# is not private enough (yet)
let sendRequest: SendRequest;
let nextId = 0;
export default class Signer implements SignerInterface {
constructor (_sendRequest: SendRequest) {
sendRequest = _sendRequest;
}
public async signPayload (payload: SignerPayloadJSON): Promise<SignerResult> {
const id = ++nextId;
const result = await sendRequest('pub(extrinsic.sign)', payload);
// we add an internal id (number) - should have a mapping from the
// extension id (string) -> internal id (number) if we wish to provide
// updated via the update functionality (noop at this point)
return {
...result,
id
};
}
public async signRaw (payload: SignerPayloadRaw): Promise<SignerResult> {
const id = ++nextId;
const result = await sendRequest('pub(bytes.sign)', payload);
return {
...result,
id
};
}
// NOTE We don't listen to updates at all, if we do we can interpret the
// result as provided by the API here
// public update (id: number, status: Hash | SubmittableResult): void {
// // ignore
// }
}