@polkadot/extension-base 0.53.1 → 0.55.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,63 @@
1
+ import type { InjectedProvider, ProviderList, ProviderMeta } from '@polkadot/extension-inject/types';
2
+ import type { ProviderInterfaceEmitCb, ProviderInterfaceEmitted } from '@polkadot/rpc-provider/types';
3
+ import type { AnyFunction } from '@polkadot/types/types';
4
+ import type { SendRequest } from './types.js';
5
+ type CallbackHandler = (error?: null | Error, value?: unknown) => void;
6
+ interface SubscriptionHandler {
7
+ callback: CallbackHandler;
8
+ type: string;
9
+ }
10
+ /**
11
+ * @name PostMessageProvider
12
+ *
13
+ * @description Extension provider to be used by dapps
14
+ */
15
+ export default class PostMessageProvider implements InjectedProvider {
16
+ #private;
17
+ /**
18
+ * @param {function} sendRequest The function to be called to send requests to the node
19
+ * @param {function} subscriptionNotificationHandler Channel for receiving subscription messages
20
+ */
21
+ constructor(_sendRequest: SendRequest);
22
+ get isClonable(): boolean;
23
+ /**
24
+ * @description Returns a clone of the object
25
+ */
26
+ clone(): PostMessageProvider;
27
+ /**
28
+ * @description Manually disconnect from the connection, clearing autoconnect logic
29
+ */
30
+ connect(): Promise<void>;
31
+ /**
32
+ * @description Manually disconnect from the connection, clearing autoconnect logic
33
+ */
34
+ disconnect(): Promise<void>;
35
+ /**
36
+ * @summary `true` when this provider supports subscriptions
37
+ */
38
+ get hasSubscriptions(): boolean;
39
+ /**
40
+ * @summary Whether the node is connected or not.
41
+ * @return {boolean} true if connected
42
+ */
43
+ get isConnected(): boolean;
44
+ listProviders(): Promise<ProviderList>;
45
+ /**
46
+ * @summary Listens on events after having subscribed using the [[subscribe]] function.
47
+ * @param {ProviderInterfaceEmitted} type Event
48
+ * @param {ProviderInterfaceEmitCb} sub Callback
49
+ * @return unsubscribe function
50
+ */
51
+ on(type: ProviderInterfaceEmitted, sub: ProviderInterfaceEmitCb): () => void;
52
+ send(method: string, params: unknown[], _?: boolean, subscription?: SubscriptionHandler): Promise<any>;
53
+ /**
54
+ * @summary Spawn a provider on the extension background.
55
+ */
56
+ startProvider(key: string): Promise<ProviderMeta>;
57
+ subscribe(type: string, method: string, params: unknown[], callback: AnyFunction): Promise<number>;
58
+ /**
59
+ * @summary Allows unsubscribing to subscriptions made with [[subscribe]].
60
+ */
61
+ unsubscribe(type: string, method: string, id: number): Promise<boolean>;
62
+ }
63
+ export {};
@@ -0,0 +1,8 @@
1
+ import type { Signer as SignerInterface, SignerResult } from '@polkadot/api/types';
2
+ import type { SignerPayloadJSON, SignerPayloadRaw } from '@polkadot/types/types';
3
+ import type { SendRequest } from './types.js';
4
+ export default class Signer implements SignerInterface {
5
+ constructor(_sendRequest: SendRequest);
6
+ signPayload(payload: SignerPayloadJSON): Promise<SignerResult>;
7
+ signRaw(payload: SignerPayloadRaw): Promise<SignerResult>;
8
+ }
@@ -0,0 +1,16 @@
1
+ import type { MessageTypes, MessageTypesWithNoSubscriptions, MessageTypesWithNullRequest, MessageTypesWithSubscriptions, RequestTypes, ResponseTypes, SubscriptionMessageTypes, TransportResponseMessage } from '../background/types.js';
2
+ import Injected from './Injected.js';
3
+ export interface Handler {
4
+ resolve: (data?: any) => void;
5
+ reject: (error: Error) => void;
6
+ subscriber?: (data: any) => void;
7
+ }
8
+ export type Handlers = Record<string, Handler>;
9
+ export declare function sendMessage<TMessageType extends MessageTypesWithNullRequest>(message: TMessageType): Promise<ResponseTypes[TMessageType]>;
10
+ export declare function sendMessage<TMessageType extends MessageTypesWithNoSubscriptions>(message: TMessageType, request: RequestTypes[TMessageType]): Promise<ResponseTypes[TMessageType]>;
11
+ export declare function sendMessage<TMessageType extends MessageTypesWithSubscriptions>(message: TMessageType, request: RequestTypes[TMessageType], subscriber: (data: SubscriptionMessageTypes[TMessageType]) => void): Promise<ResponseTypes[TMessageType]>;
12
+ export declare function enable(origin: string): Promise<Injected>;
13
+ export declare function redirectIfPhishing(): Promise<boolean>;
14
+ export declare function handleResponse<TMessageType extends MessageTypes>(data: TransportResponseMessage<TMessageType> & {
15
+ subscription?: string;
16
+ }): void;
@@ -0,0 +1,6 @@
1
+ import type { MessageTypesWithNoSubscriptions, MessageTypesWithNullRequest, MessageTypesWithSubscriptions, RequestTypes, ResponseTypes, SubscriptionMessageTypes } from '../background/types.js';
2
+ export interface SendRequest {
3
+ <TMessageType extends MessageTypesWithNullRequest>(message: TMessageType): Promise<ResponseTypes[TMessageType]>;
4
+ <TMessageType extends MessageTypesWithNoSubscriptions>(message: TMessageType, request: RequestTypes[TMessageType]): Promise<ResponseTypes[TMessageType]>;
5
+ <TMessageType extends MessageTypesWithSubscriptions>(message: TMessageType, request: RequestTypes[TMessageType], subscriber: (data: SubscriptionMessageTypes[TMessageType]) => void): Promise<ResponseTypes[TMessageType]>;
6
+ }
@@ -0,0 +1,6 @@
1
+ import type { KeyringJson, KeyringStore } from '@polkadot/ui-keyring/types';
2
+ import BaseStore from './Base.js';
3
+ export default class AccountsStore extends BaseStore<KeyringJson> implements KeyringStore {
4
+ constructor();
5
+ set(key: string, value: KeyringJson, update?: () => void): Promise<void>;
6
+ }
@@ -0,0 +1,9 @@
1
+ export default abstract class BaseStore<T> {
2
+ #private;
3
+ constructor(prefix: string | null);
4
+ all(update: (key: string, value: T) => void): Promise<void>;
5
+ allMap(update: (value: Record<string, T>) => Promise<void>): Promise<void>;
6
+ get(key: string, update: (value: T) => void): Promise<void>;
7
+ remove(key: string, update?: () => void): Promise<void>;
8
+ set(key: string, value: T, update?: () => void): Promise<void>;
9
+ }
@@ -0,0 +1,5 @@
1
+ import type { MetadataDef } from '@polkadot/extension-inject/types';
2
+ import BaseStore from './Base.js';
3
+ export default class MetadataStore extends BaseStore<MetadataDef> {
4
+ constructor();
5
+ }
@@ -0,0 +1,2 @@
1
+ export { default as AccountsStore } from './Accounts.js';
2
+ export { default as MetadataStore } from './Metadata.js';
package/cjs/types.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ export interface Message extends MessageEvent {
2
+ data: {
3
+ error?: string;
4
+ id: string;
5
+ origin: string;
6
+ response?: string;
7
+ subscription?: string;
8
+ };
9
+ }
@@ -0,0 +1,2 @@
1
+ import type { KeypairType } from '@polkadot/util-crypto/types';
2
+ export declare function canDerive(type?: KeypairType): boolean;
@@ -0,0 +1 @@
1
+ export declare function getId(): string;
@@ -0,0 +1 @@
1
+ export { canDerive } from './canDerive.js';
@@ -0,0 +1,14 @@
1
+ /// <reference types="chrome" />
2
+ import type { Message } from '@polkadot/extension-base/types';
3
+ export declare function setupPort(portName: string, onMessageHandler: (data: Message['data']) => void, onDisconnectHandler: () => void): chrome.runtime.Port;
4
+ export declare function wakeUpServiceWorker(): Promise<{
5
+ status: string;
6
+ }>;
7
+ export declare const wakeUpServiceWorkerWrapper: {
8
+ wakeUpServiceWorker: typeof wakeUpServiceWorker;
9
+ };
10
+ export declare function ensurePortConnection(portRef: chrome.runtime.Port | undefined, portConfig: {
11
+ portName: string;
12
+ onPortMessageHandler: (data: Message['data']) => void;
13
+ onPortDisconnectHandler: () => void;
14
+ }): Promise<chrome.runtime.Port>;