@airmoney-degn/controller-sdk
Version:
SDK for controlling AirMoney devices, providing button screen management, key event handling, and device communication capabilities
699 lines (550 loc) • 24.1 kB
TypeScript
export declare class AirMoneyCryptoService extends BaseService {
constructor();
generateEvmWallet: () => Promise<AMCryptoServiceEvmWalletResponse>;
listEvmWallets: () => Promise<AMCryptoServiceEvmWalletsResponse>;
signEvmMessage: (params: AMCryptoServiceSignEvmMessageParams) => Promise<AMCryptoServiceEvmMessageResponse>;
signEvmTransaction: (params: AMCryptoServiceSignEvmTransactionParams) => Promise<AMCryptoServiceEvmTransactionResponse>;
signGeneralEvmTransaction: (params: AMCryptoServiceSignEvmTransactionParams) => Promise<AMCryptoServiceEvmTransactionResponse>;
generateSolanaWallet: () => Promise<AMCryptoServiceSolanaWalletResponse>;
listSolanaWallets: () => Promise<AMCryptoServiceSolanaWalletsResponse>;
signSolanaMessage: (params: AMCryptoServiceSignSolanaMessageParams) => Promise<AMCryptoServiceSolanaMessageResponse>;
signSolanaTransaction: (params: AMCryptoServiceSignSolanaTransactionParams) => Promise<AMCryptoServiceSolanaTransactionResponse>;
restoreSvmWallet: (params: AMCryptoServiceRestoreSvmWalletParams) => Promise<AMCryptoServiceRestoreSvmWalletResponse>;
signEVMRawTransaction: (params: AMCryptoServiceSignEvmRawTransactionParams) => Promise<AMCryptoServiceEvmTransactionResponse>;
}
export declare class AirMoneyKeyEvent {
private config;
private activeKeys;
private timers;
private callbacks;
constructor(config?: Partial<AMKeyEventConfig>);
updateConfig(config?: Partial<AMKeyEventConfig>): void;
private getCombination;
private getDoubleClick;
private debugLog;
private onKeyDown;
private onKeyUp;
onSimulatorMessage: (event: MessageEvent<AMCommonEvent>) => void;
private notifyCallbacks;
on(callback: AMKeyEventCallback): void;
off(callback?: AMKeyEventCallback): void;
getConfig(): AMKeyEventConfig;
}
export declare class AirMoneyService extends BaseService {
private appName;
private assetsPath;
private isInitialized;
private throttleConfigs;
constructor(options?: {
[key in Methods]?: Options<key>;
});
private createThrottledMethod;
initialize: () => Promise<void>;
private ensureInitialized;
scanWifi: () => Promise<AMServiceWifiScanResponse>;
connectWifi: (params: AMServiceConnectWifiParams) => Promise<AMServiceWifiConnectResponse>;
managePairing: (enabled: boolean) => Promise<AMServicePairingResponse>;
getPairingStatus: () => Promise<AMServicePairingStatusResponse>;
getBatteryStatus: () => Promise<AMServiceBatteryStatusResponse>;
getTemperatureStatus: () => Promise<AMServiceTemperatureStatusResponse>;
getBrightness: () => Promise<AMServiceBrightnessResponse>;
setBrightness: (value: number) => Promise<AMServiceBrightnessResponse>;
getVolume: () => Promise<AMServiceVolumeResponse>;
setVolume: (value: number) => Promise<AMServiceVolumeResponse>;
getWifiStatus: () => Promise<AMServiceWifiStatusResponse>;
setImage: (params: AMServiceSetImageParams) => Promise<AMServiceScreenResponse>;
setAnimate: (params: AMServiceSetGifParams) => Promise<AMServiceScreenResponse>;
/**
* @deprecated MPC functionality is deprecated and will be removed in a future version
*/
setMPC: (key: string, value: string) => Promise<string>;
/**
* @deprecated MPC functionality is deprecated and will be removed in a future version
*/
getMPC: (key: string) => Promise<string>;
getHapticEffects: () => Promise<AMServiceHapticEffectsResponse>;
getHapticConfig: () => Promise<AMServiceHapticConfigResponse>;
setHapticEffect: (params: AMServiceSetHapticEffectParams) => Promise<AMServiceSetHapticEffectResponse>;
private createImagePathParam;
}
export declare const airmoneyService: AirMoneyService;
export declare const airmoneyServiceErrorWrapper: <T>(fn: AMServiceAsyncFn<T>) => ((...args: Parameters<AMServiceAsyncFn<T>>) => Promise<AMServiceSuccessResponse<T>>);
export declare class AirMoneyUpdateService {
private baseURL;
private createEndpoint;
private get;
appVersions: () => Promise<AMUpdateServiceAppVersionsResponse>;
appCheck: (appName: string) => Promise<AMUpdateServiceAppCheckResponse>;
appUpdate: (appName: string) => Promise<AMUpdateServiceUpdateResponse>;
serviceVersion: () => Promise<AMUpdateServiceVersionResponse>;
serviceCheck: () => Promise<AMUpdateServiceCheckResponse>;
serviceUpdate: () => Promise<AMUpdateServiceUpdateResponse>;
firmwareVersion: () => Promise<AMUpdateServiceFirmwareVersionResponse>;
internetCheck: () => Promise<AMUpdateServiceInternetCheckResponse>;
appList: () => Promise<AMUpdateServiceAppListResponse>;
appRefresh: (appName: string) => Promise<AMUpdateServiceAppRefreshResponse>;
appRemove: (appName: string) => Promise<AMUpdateServiceAppRemoveResponse>;
}
export declare const AM_HAPTIC_ACTION_MAP: {
readonly balance_effect: "balance";
readonly depin_effect: "depin";
readonly left_effect: "left";
readonly right_effect: "right";
readonly rotary_click_effect: "rotary_click";
readonly rotary_turn_effect: "rotary_turn";
readonly shift_effect: "shift";
};
export declare const AM_HAPTIC_ACTION_NAME_MAP: {
[key in AMHaptiConfig]: string;
};
export declare type AMCommonEvent = {
[K in keyof AMEventTypeMap]: AMEvent<K>;
}[keyof AMEventTypeMap];
export declare type AMCryptoServiceEvmMessageResponse = AMServiceResponse<AMCryptoServiceEvmMessageResult>;
export declare type AMCryptoServiceEvmMessageResult = {
message: string;
signature: string;
};
export declare type AMCryptoServiceEvmTransactionResponse = AMServiceResponse<AMCryptoServiceEvmTransactionResult>;
export declare type AMCryptoServiceEvmTransactionResult = {
signed_transaction: HexString;
};
export declare type AMCryptoServiceEvmWalletResponse = AMServiceResponse<AMCryptoServiceEvmWalletResult>;
export declare type AMCryptoServiceEvmWalletResult = {
address: HexString;
};
export declare type AMCryptoServiceEvmWalletsResponse = AMServiceResponse<AMCryptoServiceEvmWalletsResult>;
export declare type AMCryptoServiceEvmWalletsResult = {
wallets: HexString[];
};
export declare type AMCryptoServiceMethodMap = {
generateEvmWallet: void;
listEvmWallets: void;
signEvmMessage: AMCryptoServiceSignEvmMessageParams;
signEvmTransaction: AMCryptoServiceSignEvmTransactionParams;
signGeneralEvmTransaction: AMCryptoServiceSignEvmTransactionParams;
generateSolanaWallet: void;
listSolanaWallets: void;
signSolanaMessage: AMCryptoServiceSignSolanaMessageParams;
signSolanaTransaction: AMCryptoServiceSignSolanaTransactionParams;
restoreSvmWallet: AMCryptoServiceRestoreSvmWalletParams;
};
export declare type AMCryptoServiceRestoreSvmWalletParams = {
mnemonic: string;
passphrase?: string;
};
export declare type AMCryptoServiceRestoreSvmWalletResponse = AMServiceResponse<AMCryptoServiceRestoreSvmWalletResult>;
export declare type AMCryptoServiceRestoreSvmWalletResult = {
status: string;
wallets: string[];
};
export declare type AMCryptoServiceSignEvmMessageApiParams = readonly [address: HexString, message: string];
export declare type AMCryptoServiceSignEvmMessageParams = {
address: HexString;
message: string;
};
export declare type AMCryptoServiceSignEvmRawTransactionParams = {
address: HexString;
rawTransaction: RawEVMTransaction;
chainId: number | HexString;
};
export declare type AMCryptoServiceSignEvmTransactionApiParams = readonly [
address: HexString,
transaction: EVMTransaction,
chainId: HexString
];
export declare type AMCryptoServiceSignEvmTransactionParams = {
address: HexString;
transaction: EVMTransaction;
chainId: HexString;
};
export declare type AMCryptoServiceSignSolanaMessageApiParams = readonly [address: string, message: string];
export declare type AMCryptoServiceSignSolanaMessageParams = {
address: string;
message: string;
};
export declare type AMCryptoServiceSignSolanaTransactionApiParams = readonly [
transaction: AMCryptoServiceSignSolanaTransactionParams
];
export declare type AMCryptoServiceSignSolanaTransactionParams = {
address: string;
transaction_base64: string;
};
export declare type AMCryptoServiceSolanaMessageResponse = AMServiceResponse<AMCryptoServiceSolanaMessageResult>;
export declare type AMCryptoServiceSolanaMessageResult = {
message: string;
signature: string;
};
export declare type AMCryptoServiceSolanaTransactionResponse = AMServiceResponse<AMCryptoServiceSolanaTransactionResult>;
export declare type AMCryptoServiceSolanaTransactionResult = {
signed_transaction: string;
};
export declare type AMCryptoServiceSolanaWalletResponse = AMServiceResponse<AMCryptoServiceSolanaWalletResult>;
export declare type AMCryptoServiceSolanaWalletResult = {
address: string;
};
export declare type AMCryptoServiceSolanaWalletsResponse = AMServiceResponse<AMCryptoServiceSolanaWalletsResult>;
export declare type AMCryptoServiceSolanaWalletsResult = {
wallets: string[];
};
export declare type AMEvent<K extends keyof AMEventTypeMap> = {
[L in keyof AMEventTypeMap[K]]: {
source: 'air-money';
type: K;
subType: L;
data: AMEventTypeMap[K][L];
};
}[keyof AMEventTypeMap[K]];
export declare type AMEventTypeMap = {
service: AMServiceMethodMap;
'key-event': AMKeyTypeMap;
};
export declare type AMHapticAction = 'rotary_turn' | 'rotary_click' | 'left' | 'right' | 'shift' | 'balance' | 'depin';
export declare type AMHaptiConfig = Exclude<keyof AMServiceHapticConfig, 'address'>;
export declare enum AMKey {
LeftButton = "ArrowLeft",
RightButton = "ArrowRight",
CounterClockwiseRotary = "]",
ClockwiseRotary = "[",
RotaryButton = "Enter",
SideButton = "ArrowUp",
MuteSwitch = "ArrowDown"
}
export declare type AMKeyCombinationConfig = {
[name: string]: AMKey[];
};
export declare type AMKeyDoubleClickConfig = {
[name: string]: AMKey;
};
export declare type AMKeyEventCallback = (event: AMEvent<'key-event'>) => void;
export declare type AMKeyEventConfig = {
/**
* The time limit in ms (default is 300ms) for interpreting multiple inputs as a single gesture."
*/
threshold: number;
combinations?: AMKeyCombinationConfig;
doubleClicks?: AMKeyDoubleClickConfig;
debug?: boolean;
};
export declare type AMKeyState = 'over' | 'available' | 'pressed' | 'clicked' | 'end' | undefined;
export declare type AMKeyTypeMap = {
press: {
key: AMKey;
};
doubleclick: {
key: AMKey;
name: string;
};
longpressdown: {
key: AMKey;
};
longpressup: {
key: AMKey;
};
combinationdown: {
keys: AMKey[];
name: string;
};
combinationup: {
keys: AMKey[];
name: string;
};
};
export declare type AMServiceAsyncFn<T> = (...args: any[]) => Promise<AMServiceResponse<T>>;
export declare type AMServiceBatteryStatusResponse = AMServiceResponse<AMServiceBatteryStatusResult>;
export declare type AMServiceBatteryStatusResult = {
capacity: number;
status: string;
voltage: number;
};
export declare type AMServiceBrightnessResponse = AMServiceResponse<AMServiceBrightnessResult>;
export declare type AMServiceBrightnessResult = number;
export declare type AMServiceConnectWifiApiParams = readonly [ssid: string, password: string];
export declare type AMServiceConnectWifiParams = {
ssid: string;
password: string;
};
export declare type AMServiceError = {
error: {
code: number;
message: string;
};
};
export declare type AMServiceErrorResponse = {
jsonrpc: '2.0';
id: number;
} & AMServiceError;
export declare type AMServiceHapticConfig = {
address: string;
balance_effect: number;
depin_effect: number;
left_effect: number;
right_effect: number;
rotary_click_effect: number;
rotary_turn_effect: number;
shift_effect: number;
};
export declare type AMServiceHapticConfigResponse = AMServiceResponse<AMServiceHapticConfigResult>;
export declare type AMServiceHapticConfigResult = AMServiceHapticConfig;
export declare type AMServiceHapticEffect = {
duration: number;
effect_type: number;
id: number;
magnitude: number;
name: string;
};
export declare type AMServiceHapticEffectsResponse = AMServiceResponse<AMServiceHapticEffectsResult>;
export declare type AMServiceHapticEffectsResult = AMServiceHapticEffect[];
export declare type AMServiceManagePairingApiParams = readonly [enabled: boolean];
export declare type AMServiceManagePairingParams = boolean;
export declare type AMServiceMethodMap = {
setImage: AMServiceSetImageParams;
setAnimate: AMServiceSetGifParams;
scanWifi: void;
connectWifi: AMServiceConnectWifiParams;
managePairing: AMServiceManagePairingParams;
getPairingStatus: void;
batteryStatus: void;
temperatureStatus: void;
getBrightness: void;
setBrightness: AMServiceSetBrightnessParams;
getVolume: void;
setVolume: AMServiceSetVolumeParams;
getVersion: void;
getWifiStatus: void;
getHapticEffects: void;
getHapticConfig: void;
setHapticEffect: AMServiceSetHapticEffectParams;
};
export declare type AMServicePairingResponse = AMServiceResponse<AMServicePairingResult>;
export declare type AMServicePairingResult = boolean;
export declare type AMServicePairingStatusResponse = AMServiceResponse<AMServicePairingStatusResult>;
export declare type AMServicePairingStatusResult = boolean;
export declare type AMServicePayload<Method extends string, Params extends readonly string[]> = {
jsonrpc: '2.0';
method: Method;
params: Params;
id: string;
};
export declare type AMServiceResponse<T> = {
jsonrpc: '2.0';
id: number;
} & (AMServiceSuccess<T> | AMServiceError);
export declare enum AMServiceScreen {
Right = "right",
Left = "left"
}
export declare type AMServiceScreenApiParams = readonly [imageName: string, position: AMServiceScreen];
export declare type AMServiceScreenResponse = AMServiceResponse<AMServiceScreenResult>;
export declare type AMServiceScreenResult = {
message: string;
};
export declare type AMServiceSetBrightnessApiParams = readonly [brightness: number];
export declare type AMServiceSetBrightnessParams = number;
export declare type AMServiceSetGifParams = {
id: AMServiceScreen.Left | AMServiceScreen.Right;
imageName: string;
};
export declare type AMServiceSetHapticEffectParams = {
action: AMHapticAction;
effectId: number;
};
export declare type AMServiceSetHapticEffectResponse = AMServiceResponse<AMServiceSetHapticEffectResult>;
export declare type AMServiceSetHapticEffectResult = boolean;
export declare type AMServiceSetImageParams = {
id: AMServiceScreen.Left | AMServiceScreen.Right;
imageName: string;
};
export declare type AMServiceSetVolumeApiParams = readonly [volume: number];
export declare type AMServiceSetVolumeParams = number;
export declare type AMServiceSuccess<T> = {
status: string;
result: T;
};
export declare type AMServiceSuccessResponse<T> = {
jsonrpc: '2.0';
id: number;
} & AMServiceSuccess<T>;
export declare type AMServiceTemperatureStatusResponse = AMServiceResponse<AMServiceTemperatureStatusResult>;
export declare type AMServiceTemperatureStatusResult = {
zone_name: string;
sensor_type: string;
temperature: number;
}[];
export declare type AMServiceVolumeResponse = AMServiceResponse<AMServiceVolumeResult>;
export declare type AMServiceVolumeResult = number;
export declare type AMServiceWifiConnectResponse = AMServiceResponse<AMServiceWifiConnectResult>;
export declare type AMServiceWifiConnectResult = boolean;
export declare type AMServiceWifiResult = string[];
export declare type AMServiceWifiScanResponse = AMServiceResponse<AMServiceWifiScanResult>;
export declare type AMServiceWifiScanResult = string[];
export declare type AMServiceWifiStatusResponse = AMServiceResponse<AMServiceWifiStatusResult>;
export declare type AMServiceWifiStatusResult = {
dns_servers: string[];
gateway: string | null;
interface: string;
ip_address: string | null;
netmask: string | null;
ssid: string;
};
export declare type AMUpdateServiceAppCheck = {
id: string;
/**
* null - Brand new app
*/
current_version: string | null;
/**
* null - Brand new app
*/
current_build: string | null;
update_version: string;
update_build: string;
whats_new: string;
needs_update: boolean;
};
export declare type AMUpdateServiceAppCheckResponse = AMUpdateServiceResponse<AMUpdateServiceAppCheck>;
export declare type AMUpdateServiceAppListResponse = AMUpdateServiceResponse<string[]>;
export declare type AMUpdateServiceAppRefreshResponse = {
status: boolean;
message: string;
error: null | string;
};
export declare type AMUpdateServiceAppRemoveResponse = AMUpdateServiceResponse<never>;
export declare type AMUpdateServiceAppVersion = {
name: string;
displayName: string;
identifier: string;
author: string;
maintainer: string;
url: string;
version: string;
whatsNew: string;
buildNumber: string;
commitHash: string;
buildDate: string;
themeColor: string;
id: string | null;
};
export declare type AMUpdateServiceAppVersionsResponse = AMUpdateServiceResponse<AMUpdateServiceAppVersion[]>;
export declare type AMUpdateServiceAsyncFn<T> = (...args: any[]) => Promise<AMUpdateServiceResponse<T>>;
export declare type AMUpdateServiceCheck = {
name: string;
current_build: string;
new_build: string;
needs_update: boolean;
};
export declare type AMUpdateServiceCheckResponse = AMUpdateServiceResponse<AMUpdateServiceCheck[]>;
export declare type AMUpdateServiceErrorResponse = {
status: false;
error: string;
};
export declare type AMUpdateServiceFirmwareVersion = {
build: string;
commit: string;
};
export declare type AMUpdateServiceFirmwareVersionResponse = AMUpdateServiceResponse<AMUpdateServiceFirmwareVersion>;
export declare type AMUpdateServiceInternetCheck = {
ping: boolean;
dns: boolean;
default_route: boolean;
internet: boolean;
};
export declare type AMUpdateServiceInternetCheckResponse = AMUpdateServiceResponse<AMUpdateServiceInternetCheck>;
export declare type AMUpdateServiceResponse<T> = AMUpdateServiceSuccessResponse<T> | AMUpdateServiceErrorResponse;
export declare type AMUpdateServiceSuccessResponse<T> = {
status: true;
data: T;
};
export declare type AMUpdateServiceUpdateResponse = AMUpdateServiceResponse<never>;
export declare type AMUpdateServiceVersion = {
name: string;
meta: AMUpdateServiceVersionMeta;
};
export declare type AMUpdateServiceVersionMeta = {
build: string;
commit: string;
};
export declare type AMUpdateServiceVersionResponse = AMUpdateServiceResponse<AMUpdateServiceVersion[]>;
export declare const APP_LAUNCHER_NAME = "app-launcher";
export declare const backToHome: () => void;
declare abstract class BaseService {
protected baseURL: string;
constructor(baseURL: string);
protected createEndpoint: (url: string) => string;
protected createPayload: <Method extends string, Params extends readonly any[]>(method: Method, params: Params) => AMServicePayload<Method, Params>;
protected request: <T>(payload: AMServicePayload<string, readonly any[]>) => Promise<T>;
}
export declare const cryptoServiceErrorWrapper: <T>(fn: AMServiceAsyncFn<T>) => ((...args: Parameters<AMServiceAsyncFn<T>>) => Promise<AMServiceSuccessResponse<T>>);
export declare const displayAsset: (appName?: string, path?: string) => string;
export declare const errorWrapper: <T>(fn: AMServiceAsyncFn<T>) => ((...args: Parameters<AMServiceAsyncFn<T>>) => Promise<AMServiceSuccessResponse<T>>);
export declare type EVMTransaction = {
to?: HexString;
value?: HexString;
gasLimit?: HexString;
gasPrice?: HexString;
maxFeePerGas?: HexString;
maxPriorityFeePerGas?: HexString;
nonce?: HexString;
chainId?: HexString;
data?: HexString;
type?: HexString;
gas?: HexString;
accessList?: Array<{
address: HexString | null;
storageKeys: HexString[];
}>;
};
export declare const getAppLink: (appName?: string) => string;
export declare const getAppLogo: (appName?: string) => string;
export declare const goToApp: (appName?: string) => void;
export declare type HexString = `0x${string}`;
export declare const isAMServiceErrorResponse: <T>(response: AMServiceResponse<T>) => response is AMServiceResponse<T> & AMServiceError;
export declare const isAMServiceSuccessResponse: <T>(response: AMServiceResponse<T>) => response is AMServiceResponse<T> & AMServiceSuccess<T>;
export declare const isAMUpdateServiceErrorResponse: <T>(response: AMUpdateServiceResponse<T>) => response is AMUpdateServiceResponse<T> & AMUpdateServiceErrorResponse;
export declare const isAMUpdateServiceSuccessResponse: <T>(response: AMUpdateServiceResponse<T>) => response is AMUpdateServiceResponse<T> & AMUpdateServiceSuccessResponse<T>;
export declare const isFileProtocol: () => boolean;
export declare const isParamsValid: <T>(params: readonly (T | undefined)[]) => params is T[];
export declare const isValidNumber: (value?: string) => value is string;
export declare interface Metadata {
name: string;
displayName: string;
identifier: string;
author: string;
maintainer: string;
url: string;
version: string;
whatsNew: string;
buildNumber: string;
commitHash: string;
buildDate: string;
themeColor: string;
}
declare type Methods = keyof AirMoneyService;
export declare const normalizeEVMTransaction: (obj: RawEVMTransaction) => EVMTransaction;
declare type Options<Method extends Methods> = Method extends ThrottlableMethods ? {
throttleEnabled: boolean;
throttleTime?: number;
} : never;
export declare type RawEVMTransaction = {
to?: HexString | string | null;
value?: HexString | string | number | bigint | null;
gasLimit?: HexString | string | number | bigint | null;
gasPrice?: HexString | string | number | bigint | null;
maxFeePerGas?: HexString | string | number | bigint | null;
maxPriorityFeePerGas?: HexString | string | number | bigint | null;
nonce?: HexString | string | number | bigint | null;
chainId?: HexString | string | number | bigint | null;
data?: HexString | string | null;
type?: HexString | string | number | bigint | null;
gas?: HexString | string | number | bigint | null;
accessList?: readonly {
address: HexString | string | null;
storageKeys: readonly HexString[];
}[];
};
export declare const serializeParams: <T extends readonly (any | undefined)[]>(params: T) => { [K in keyof T]: Exclude<T[K], undefined>; } | undefined;
declare type ThrottlableMethods = Extract<Methods, 'setImage' | 'setAnimate'>;
export declare const toBoolean: (value: string) => boolean;
export declare const toHexString: (obj: bigint | number | string) => HexString;
export declare const updateServiceErrorWrapper: <T>(fn: AMUpdateServiceAsyncFn<T>) => ((...args: Parameters<AMUpdateServiceAsyncFn<T>>) => Promise<AMUpdateServiceSuccessResponse<T>>);
export { }