@airmoney-degn/controller-sdk
Version:
SDK for controlling AirMoney devices, providing button screen management, key event handling, and device communication capabilities
637 lines (515 loc) • 22.1 kB
TypeScript
export declare class AirMoneyCryptoService extends BaseService {
constructor();
signEvmMessage: (params: AMCryptoServiceSignEvmMessageParams) => Promise<AMCryptoServiceEvmMessageResponse>;
signEvmTransaction: (params: AMCryptoServiceSignEvmTransactionParams) => Promise<AMCryptoServiceEvmTransactionResponse>;
signGeneralEvmTransaction: (params: AMCryptoServiceSignGeneralEvmTransactionParams) => Promise<AMCryptoServiceEvmTransactionResponse>;
signEip712TypedData: (params: AMCryptoServiceSignEip712TypedDataParams) => Promise<AMCryptoServiceEip712TypedDataResponse>;
verifyEip1271Signature: (params: AMCryptoServiceVerifyEip1271SignatureParams) => Promise<AMCryptoServiceVerifyEip1271SignatureResponse>;
signSolanaMessage: (params: AMCryptoServiceSignSolanaMessageParams) => Promise<AMCryptoServiceSolanaMessageResponse>;
signSolanaTransaction: (params: AMCryptoServiceSignSolanaTransactionParams) => Promise<AMCryptoServiceSolanaTransactionResponse>;
signEVMRawTransaction: (params: AMCryptoServiceSignEvmRawTransactionParams) => Promise<AMCryptoServiceEvmTransactionResponse>;
getDefaultEvmWallet: () => Promise<AMCryptoServiceGetDefaultEvmWalletResponse>;
getDefaultSvmWallet: () => Promise<AMCryptoServiceGetDefaultSvmWalletResponse>;
signBitcoinMessage: (params: AMCryptoServiceSignBitcoinMessageParams) => Promise<AMCryptoServiceBitcoinMessageResponse>;
verifyBitcoinSignature: (params: AMCryptoServiceVerifyBitcoinSignatureParams) => Promise<AMCryptoServiceBitcoinSignatureResponse>;
signBitcoinTransaction: (params: AMCryptoServiceSignBitcoinTransactionParams) => Promise<AMCryptoServiceBitcoinTransactionResponse>;
getDefaultBitcoinWallet: () => Promise<AMCryptoServiceGetDefaultBitcoinWalletResponse>;
getDeviceStatus: () => Promise<AMCryptoServiceDeviceStatusResponse>;
verifyPin: (params: AMCryptoServiceVerifyPinParams) => Promise<AMCryptoServiceVerifyPinResponse>;
}
export declare class AirMoneyKeyEvent {
private config;
private activeKeys;
private timers;
private callbacks;
private window;
private keyUpEventName;
private keyDownEventName;
constructor(config?: Partial<AMKeyEventConfig>);
updateConfig(config?: Partial<AMKeyEventConfig>): void;
private getSortedCombinations;
private isCombinationComplete;
private getDoubleClick;
private debugLog;
private getKeyFromEvent;
private handleCombination;
private onKeyDown;
private onKeyUp;
private notifyCallbacks;
on(callback: AMKeyEventCallback): void;
off(callback?: AMKeyEventCallback): void;
getConfig(): AMKeyEventConfig;
}
export declare class AirMoneyKeyEventManager {
private keyEvent;
private triggerConfigs;
private listenerIdCounter;
private isInitialized;
private debug;
constructor(config: AMKeyEventManagerConfig);
private initialize;
/**
* Subscribe method - registers a group of triggers with a config object.
* If config.id is missing, a unique id will be generated and assigned.
*/
subscribe: (config: AMKeyEventTriggerGroupConfig) => string;
private handlePriorityEvent;
unsubscribe: (listenerId: string) => boolean;
unsubscribeAll: () => void;
getKeyEventInstance: () => AirMoneyKeyEvent;
updateConfig: (config: Parameters<AirMoneyKeyEvent["updateConfig"]>[0]) => void;
getConfig: () => ReturnType<AirMoneyKeyEvent["getConfig"]>;
destroy: () => void;
}
export declare class AirMoneyService extends BaseService {
private appName;
private isInitialized;
private throttleConfigs;
static ERROR_CODE_MAP: ReadonlyMap<number, AMServiceUserErrorInfo>;
constructor(options?: {
[key in Methods]?: Options<key>;
});
private createThrottledMethod;
initialize: () => Promise<void>;
private ensureInitialized;
setImage: (params: AMServiceSetImageParams) => Promise<AMServiceScreenResponse>;
setAnimate: (params: AMServiceSetGifParams) => Promise<AMServiceScreenResponse>;
private createImagePathParam;
protected request<T extends AMServiceResponse<any> | AMServiceUserResponse<any>>(payload: AMServicePayload<string, readonly any[]>): Promise<T>;
}
export declare const airmoneyService: AirMoneyService;
export declare const airmoneyServiceErrorWrapper: <T, Args extends any[]>(fn: (...args: Args) => Promise<AMServiceResponse<T>>) => ((...args: Args) => Promise<AMServiceSuccessResponse<T>>);
export declare type AMCommonEvent = {
[K in keyof AMEventTypeMap]: AMEvent<K>;
}[keyof AMEventTypeMap];
export declare type AMCryptoServiceBitcoinMessageResponse = AMServiceResponse<AMCryptoServiceBitcoinMessageResult>;
export declare type AMCryptoServiceBitcoinMessageResult = {
message: string;
signature: string;
};
export declare type AMCryptoServiceBitcoinSignatureResponse = AMServiceResponse<AMCryptoServiceBitcoinSignatureResult>;
export declare type AMCryptoServiceBitcoinSignatureResult = boolean;
export declare type AMCryptoServiceBitcoinTransactionResponse = AMServiceResponse<AMCryptoServiceBitcoinTransactionResult>;
export declare type AMCryptoServiceBitcoinTransactionResult = {
signed_transaction: string;
};
export declare type AMCryptoServiceDeviceStatusResponse = AMServiceResponse<AMCryptoServiceDeviceStatusResult>;
export declare type AMCryptoServiceDeviceStatusResult = {
is_setup: boolean;
is_pin_set: boolean;
};
export declare type AMCryptoServiceEip712TypedDataResponse = AMServiceResponse<AMCryptoServiceEip712TypedDataResult>;
export declare type AMCryptoServiceEip712TypedDataResult = {
signature: HexString;
};
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 AMCryptoServiceGetDefaultBitcoinWalletResponse = AMServiceResponse<AMCryptoServiceGetDefaultBitcoinWalletResult>;
export declare type AMCryptoServiceGetDefaultBitcoinWalletResult = {
address: string;
};
export declare type AMCryptoServiceGetDefaultEvmWalletResponse = AMServiceResponse<AMCryptoServiceGetDefaultEvmWalletResult>;
export declare type AMCryptoServiceGetDefaultEvmWalletResult = {
address: HexString;
};
export declare type AMCryptoServiceGetDefaultSvmWalletResponse = AMServiceResponse<AMCryptoServiceGetDefaultSvmWalletResult>;
export declare type AMCryptoServiceGetDefaultSvmWalletResult = {
address: string;
};
export declare type AMCryptoServiceMethodMap = {
signEvmMessage: AMCryptoServiceSignEvmMessageParams;
signEvmTransaction: AMCryptoServiceSignEvmTransactionParams;
signGeneralEvmTransaction: AMCryptoServiceSignGeneralEvmTransactionParams;
signEip712TypedData: AMCryptoServiceSignEip712TypedDataParams;
verifyEip1271Signature: AMCryptoServiceVerifyEip1271SignatureParams;
signSolanaMessage: AMCryptoServiceSignSolanaMessageParams;
signSolanaTransaction: AMCryptoServiceSignSolanaTransactionParams;
getDefaultEvmWallet: void;
getDefaultSvmWallet: void;
signBitcoinMessage: AMCryptoServiceSignBitcoinMessageParams;
verifyBitcoinSignature: AMCryptoServiceVerifyBitcoinSignatureParams;
signBitcoinTransaction: AMCryptoServiceSignBitcoinTransactionParams;
getDefaultBitcoinWallet: void;
getDeviceStatus: void;
verifyPin: AMCryptoServiceVerifyPinParams;
};
export declare type AMCryptoServiceRestoreBitcoinWalletApiParams = readonly [mnemonic: string, passphrase: string];
export declare type AMCryptoServiceSignBitcoinMessageApiParams = readonly [address: string, message: string];
export declare type AMCryptoServiceSignBitcoinMessageParams = {
address: string;
message: string;
pin: string;
};
export declare type AMCryptoServiceSignBitcoinTransactionApiParams = readonly [
transaction: AMCryptoServiceSignBitcoinTransactionParams
];
export declare type AMCryptoServiceSignBitcoinTransactionParams = {
address: string;
psbt_base64: string;
sighash_type?: string;
pin: string;
};
export declare type AMCryptoServiceSignEip712TypedDataApiParams = readonly [
address: HexString,
typed_data: AMCryptoServiceSignEip712TypedDataParams['typed_data']
];
export declare type AMCryptoServiceSignEip712TypedDataParams = {
address: HexString;
typed_data: {
types: Record<string, Array<{
name: string;
type: string;
}>>;
primaryType: string;
domain: Record<string, any>;
message: Record<string, any>;
};
pin: string;
};
export declare type AMCryptoServiceSignEvmMessageApiParams = readonly [address: HexString, message: string];
export declare type AMCryptoServiceSignEvmMessageParams = {
address: HexString;
message: string;
pin: string;
};
export declare type AMCryptoServiceSignEvmRawTransactionParams = {
address: HexString;
rawTransaction: RawEVMTransaction;
chain_id: number | HexString;
pin: string;
};
export declare type AMCryptoServiceSignEvmTransactionApiParams = readonly [
address: HexString,
transaction: EVMTransaction,
chainId: HexString
];
export declare type AMCryptoServiceSignEvmTransactionParams = {
address: HexString;
transaction_data: EVMTransaction;
chain_id: HexString;
pin: string;
};
export declare type AMCryptoServiceSignGeneralEvmTransactionParams = {
address: HexString;
typed_tx: EVMTransaction;
chain_id: HexString;
pin: string;
};
export declare type AMCryptoServiceSignSolanaMessageApiParams = readonly [address: string, message: string];
export declare type AMCryptoServiceSignSolanaMessageParams = {
address: string;
message: string;
pin: string;
};
export declare type AMCryptoServiceSignSolanaTransactionApiParams = readonly [
transaction: AMCryptoServiceSignSolanaTransactionParams
];
export declare type AMCryptoServiceSignSolanaTransactionParams = {
address: string;
transaction_base64: string;
pin: 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 AMCryptoServiceVerifyBitcoinSignatureApiParams = readonly [
address: string,
message: string,
signature: string
];
export declare type AMCryptoServiceVerifyBitcoinSignatureParams = {
address: string;
message: string;
signature: string;
};
export declare type AMCryptoServiceVerifyEip1271SignatureApiParams = readonly [
rpcUrl: string,
contractAddress: HexString,
message: string,
signature: HexString
];
export declare type AMCryptoServiceVerifyEip1271SignatureParams = {
rpcUrl: string;
contractAddress: HexString;
message: string;
signature: HexString;
};
export declare type AMCryptoServiceVerifyEip1271SignatureResponse = AMServiceResponse<AMCryptoServiceVerifyEip1271SignatureResult>;
export declare type AMCryptoServiceVerifyEip1271SignatureResult = {
isValid: boolean;
};
export declare type AMCryptoServiceVerifyPinParams = {
pin: string;
};
export declare type AMCryptoServiceVerifyPinResponse = AMServiceResponse<AMCryptoServiceVerifyPinResult>;
export declare type AMCryptoServiceVerifyPinResult = Record<string, never>;
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 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;
keyUpEventName?: string;
keyDownEventName?: string;
};
export declare type AMKeyEventManagerConfig = {
instance: AirMoneyKeyEvent;
debug?: boolean;
};
export declare type AMKeyEventTrigger = {
condition: (event: AMEvent<'key-event'>) => boolean;
trigger: (event: AMEvent<'key-event'>) => void;
name?: string;
};
export declare type AMKeyEventTriggerGroupConfig = {
name?: string;
triggers: AMKeyEventTrigger[];
/**
* Higher = higher priority
*/
priority: number;
};
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 AMKKeyEventTriggerGroup = AMKeyEventTriggerGroupConfig & {
id: string;
};
export declare type AMServiceError = {
error: {
code: number;
message: string;
};
};
export declare type AMServiceErrorResponse = {
jsonrpc: '2.0';
id: number;
} & AMServiceError;
export declare type AMServiceGeneralResponse<T> = {
jsonrpc: '2.0';
id: number;
} & (AMServiceSuccess<T> | AMServiceError);
export declare type AMServiceMethodMap = {
setImage: AMServiceSetImageParams;
setAnimate: AMServiceSetGifParams;
};
export declare type AMServicePayload<Method extends string = string, Params extends readonly string[] = 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 = AMServiceUserResponse<AMServiceScreenResult>;
export declare type AMServiceScreenResult = {
message: string;
};
export declare type AMServiceSetGifParams = {
id: AMServiceScreen.Left | AMServiceScreen.Right;
imageName: string;
};
export declare type AMServiceSetImageParams = {
id: AMServiceScreen.Left | AMServiceScreen.Right;
imageName: string;
};
export declare type AMServiceSuccess<T> = {
result: T extends Record<PropertyKey, unknown> ? {
status: string;
} & T : T;
};
export declare type AMServiceSuccessResponse<T> = {
jsonrpc: '2.0';
id: number;
} & AMServiceSuccess<T>;
export declare type AMServiceUserError = AMServiceError & AMServiceUserErrorInfo;
export declare type AMServiceUserErrorInfo = {
type: AMServiceUserErrorType;
userMessage: string;
};
export declare type AMServiceUserErrorResponse = {
jsonrpc: '2.0';
id: number;
} & AMServiceUserError;
export declare enum AMServiceUserErrorType {
CoreUnhandled = "CoreUnhandled",
DisplayInvalidInput = "DisplayInvalidInput",
DisplayAssetLoad = "DisplayAssetLoad",
DisplayHardware = "DisplayHardware",
NetworkCommand = "NetworkCommand",
NetworkAuth = "NetworkAuth",
NetworkConfig = "NetworkConfig",
HapticInvalidAction = "HapticInvalidAction",
HapticHardware = "HapticHardware",
BluetoothControl = "BluetoothControl",
BluetoothData = "BluetoothData",
BrightnessFailure = "BrightnessFailure",
AudioFailure = "AudioFailure",
TelemetryRead = "TelemetryRead",
TelemetryRender = "TelemetryRender",
SessionParse = "SessionParse",
SessionStorage = "SessionStorage",
Unknown = "Unknown"
}
export declare type AMServiceUserResponse<T> = {
jsonrpc: '2.0';
id: number;
} & (AMServiceSuccess<T> | AMServiceUserError);
export declare const APP_LAUNCHER_NAME = "app-launcher";
export declare const backToHome: () => void;
declare abstract class BaseService {
protected baseURL: string;
protected serviceName: 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 extends AMServiceResponse<any> | AMServiceUserResponse<any>>(payload: AMServicePayload<string, readonly any[]>): Promise<T>;
}
export declare const createDefaultKeyEvent: (options?: Partial<AMKeyEventConfig>) => AirMoneyKeyEvent;
export declare const createDefaultKeyEventManager: (options?: Partial<AMKeyEventManagerConfig>) => AirMoneyKeyEventManager;
export declare const cryptoServiceErrorWrapper: <T, Args extends any[]>(fn: (...args: Args) => Promise<AMServiceResponse<T>>) => ((...args: Args) => Promise<AMServiceSuccessResponse<T>>);
export declare const displayAsset: (appName?: string, path?: string) => string;
declare type ErrorResponseType<T> = T extends AMServiceUserResponse<unknown> ? T & AMServiceUserErrorResponse : T extends AMServiceResponse<unknown> ? T & AMServiceErrorResponse : never;
export declare const errorWrapper: <T, Args extends any[]>(fn: (...args: Args) => Promise<AMServiceResponse<T>>) => ((...args: Args) => 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 getAppName: () => Promise<string>;
export declare const goToApp: (appName?: string) => void;
export declare type HexString = `0x${string}`;
export declare const isAMServiceErrorResponse: <T extends AMServiceResponse<unknown> | AMServiceUserResponse<unknown>>(response: T) => response is ErrorResponseType<T>;
export declare const isAMServiceSuccessResponse: <T>(response: AMServiceResponse<T>) => response is AMServiceResponse<T> & AMServiceSuccess<T>;
export declare const isFileProtocol: () => boolean;
export declare const isInDevice: () => 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 reloadWebApp: () => void;
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 { }