@onekeyfe/hd-core 0.0.3 → 0.0.6
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.
- package/dist/api/helpers/pathUtils.d.ts +0 -1
- package/dist/api/helpers/pathUtils.d.ts.map +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/events/core.d.ts +2 -1
- package/dist/events/core.d.ts.map +1 -1
- package/dist/events/device.d.ts +15 -0
- package/dist/events/device.d.ts.map +1 -1
- package/dist/events/ui-request.d.ts +15 -1
- package/dist/events/ui-request.d.ts.map +1 -1
- package/dist/index.d.ts +71 -30
- package/dist/index.js +155 -112
- package/dist/types/api/btcSignTransaction.d.ts +2 -2
- package/dist/types/api/btcSignTransaction.d.ts.map +1 -1
- package/dist/types/api/export.d.ts +1 -0
- package/dist/types/api/export.d.ts.map +1 -1
- package/dist/utils/index.d.ts +2 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/api/btc/BTCGetPublicKey.ts +2 -2
- package/src/api/helpers/pathUtils.ts +1 -1
- package/src/core/index.ts +42 -2
- package/src/events/core.ts +8 -1
- package/src/events/device.ts +27 -0
- package/src/events/ui-request.ts +22 -1
- package/src/types/api/btcSignTransaction.ts +1 -2
- package/src/types/api/export.ts +8 -0
- package/src/utils/index.ts +2 -1
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { ChangeOutputScriptType, InputScriptType } from '@onekeyfe/hd-transport/src/types/messages';
|
|
2
|
-
export declare const HD_HARDENED = 2147483648;
|
|
3
2
|
export declare const toHardened: (n: number) => number;
|
|
4
3
|
export declare const fromHardened: (n: number) => number;
|
|
5
4
|
export declare const getHDPath: (path: string) => Array<number>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pathUtils.d.ts","sourceRoot":"","sources":["../../../src/api/helpers/pathUtils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,eAAe,EAAE,MAAM,2CAA2C,CAAC;
|
|
1
|
+
{"version":3,"file":"pathUtils.d.ts","sourceRoot":"","sources":["../../../src/api/helpers/pathUtils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,eAAe,EAAE,MAAM,2CAA2C,CAAC;AAIpG,eAAO,MAAM,UAAU,MAAO,MAAM,KAAG,MAAiC,CAAC;AACzE,eAAO,MAAM,YAAY,MAAO,MAAM,KAAG,MAAkC,CAAC;AAQ5E,eAAO,MAAM,SAAS,SAAU,MAAM,KAAG,MAAM,MAAM,CAuBpD,CAAC;AAEF,eAAO,MAAM,cAAc,SAAU,MAAM,MAAM,CAAC,KAAG,OACF,CAAC;AAEpD,eAAO,MAAM,YAAY,SAAU,MAAM,MAAM,CAAC,KAAG,OACA,CAAC;AAEpD,eAAO,MAAM,YAAY,SAAU,MAAM,MAAM,CAAC,KAAG,OACA,CAAC;AAEpD,eAAO,MAAM,aAAa,SAAU,MAAM,MAAM,CAAC,KAAG,eAcnD,CAAC;AAEF,eAAO,MAAM,mBAAmB,mCAAsB,sBAmBrD,CAAC;AAEF,eAAO,MAAM,cAAc,SAAU,MAAM,MAAM,CAAC,KAAG,MAWpD,CAAC;AAEF,eAAO,MAAM,YAAY,SACjB,MAAM,GAAG,MAAM,MAAM,CAAC,sCAG3B,MAAM,MAAM,CAoBd,CAAC"}
|
package/dist/core/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":";AAAA,OAAO,YAAY,MAAM,QAAQ,CAAC;AASlC,OAAO,EACL,WAAW,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":";AAAA,OAAO,YAAY,MAAM,QAAQ,CAAC;AASlC,OAAO,EACL,WAAW,EAYZ,MAAM,WAAW,CAAC;AAEnB,OAAO,KAAK,EAAE,eAAe,EAAe,MAAM,UAAU,CAAC;AAE7D,OAAO,eAAe,MAAM,2BAA2B,CAAC;AAWxD,eAAO,MAAM,OAAO,YAAmB,WAAW,iBAgIjD,CAAC;AAoHF,MAAM,CAAC,OAAO,OAAO,IAAK,SAAQ,YAAY;IACtC,aAAa,CAAC,OAAO,EAAE,WAAW;IA2BxC,OAAO;CAGR;AAED,eAAO,MAAM,QAAQ,YAGpB,CAAC;AAEF,eAAO,MAAM,aAAa,uBAGzB,CAAC;AAMF,eAAO,MAAM,IAAI,aAAoB,eAAe,aAAa,GAAG,8BAgBnE,CAAC"}
|
package/dist/events/core.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Unsuccessful } from '../types/params';
|
|
2
2
|
import { IFrameCallMessage } from './call';
|
|
3
|
+
import { DeviceEventMessage } from './device';
|
|
3
4
|
import { IFrameEventMessage } from './iframe';
|
|
4
5
|
import { UiEventMessage } from './ui-request';
|
|
5
6
|
import { UiResponseMessage } from './ui-response';
|
|
@@ -7,7 +8,7 @@ export declare const CORE_EVENT = "CORE_EVENT";
|
|
|
7
8
|
export declare type CoreMessage = {
|
|
8
9
|
id?: string;
|
|
9
10
|
success?: true | false;
|
|
10
|
-
} & (IFrameEventMessage | IFrameCallMessage | UiResponseMessage | UiEventMessage);
|
|
11
|
+
} & (IFrameEventMessage | IFrameCallMessage | UiResponseMessage | UiEventMessage | DeviceEventMessage);
|
|
11
12
|
export declare type PostMessageEvent = MessageEvent<any>;
|
|
12
13
|
export declare const parseMessage: (messageData: any) => CoreMessage;
|
|
13
14
|
export declare const createErrorMessage: (error: Error & {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../src/events/core.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAC;AAC3C,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAElD,eAAO,MAAM,UAAU,eAAe,CAAC;AAEvC,oBAAY,WAAW,GAAG;IACxB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,IAAI,GAAG,KAAK,CAAC;CACxB,GAAG,
|
|
1
|
+
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../src/events/core.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAC;AAC3C,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAElD,eAAO,MAAM,UAAU,eAAe,CAAC;AAEvC,oBAAY,WAAW,GAAG;IACxB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,IAAI,GAAG,KAAK,CAAC;CACxB,GAAG,CACA,kBAAkB,GAClB,iBAAiB,GACjB,iBAAiB,GACjB,cAAc,GACd,kBAAkB,CACrB,CAAC;AAEF,oBAAY,gBAAgB,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC;AAEjD,eAAO,MAAM,YAAY,gBAAiB,GAAG,KAAG,WAiB/C,CAAC;AAEF,eAAO,MAAM,kBAAkB,UAAW,KAAK,GAAG;IAAE,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,KAAG,YAMpE,CAAC"}
|
package/dist/events/device.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import type { PROTO } from '../constants';
|
|
2
|
+
import type { KnownDevice as Device } from '../types/device';
|
|
3
|
+
import { MessageFactoryFn } from './utils';
|
|
4
|
+
export declare const DEVICE_EVENT = "DEVICE_EVENT";
|
|
2
5
|
export declare const DEVICE: {
|
|
3
6
|
readonly CONNECT: "device-connect";
|
|
4
7
|
readonly CONNECT_UNACQUIRED: "device-connect_unacquired";
|
|
@@ -20,4 +23,16 @@ export declare const DEVICE: {
|
|
|
20
23
|
export interface DeviceButtonRequestPayload extends Omit<PROTO.ButtonRequest, 'code'> {
|
|
21
24
|
code?: PROTO.ButtonRequest['code'] | 'ButtonRequest_FirmwareUpdate';
|
|
22
25
|
}
|
|
26
|
+
export interface DeviceButtonRequest {
|
|
27
|
+
type: typeof DEVICE.BUTTON;
|
|
28
|
+
payload: DeviceButtonRequestPayload & {
|
|
29
|
+
device: Device | null;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export declare type DeviceEvent = DeviceButtonRequest;
|
|
33
|
+
export declare type DeviceEventMessage = DeviceEvent & {
|
|
34
|
+
event: typeof DEVICE_EVENT;
|
|
35
|
+
};
|
|
36
|
+
export declare type DeviceEventListenerFn = (type: typeof DEVICE_EVENT, cb: (event: DeviceEventMessage) => void) => void;
|
|
37
|
+
export declare const createDeviceMessage: MessageFactoryFn<typeof DEVICE_EVENT, DeviceEvent>;
|
|
23
38
|
//# sourceMappingURL=device.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"device.d.ts","sourceRoot":"","sources":["../../src/events/device.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"device.d.ts","sourceRoot":"","sources":["../../src/events/device.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,KAAK,EAAE,WAAW,IAAI,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAE3C,eAAO,MAAM,YAAY,iBAAiB,CAAC;AAC3C,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;CAqBT,CAAC;AAEX,MAAM,WAAW,0BAA2B,SAAQ,IAAI,CAAC,KAAK,CAAC,aAAa,EAAE,MAAM,CAAC;IACnF,IAAI,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC,MAAM,CAAC,GAAG,8BAA8B,CAAC;CACrE;AAED,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,OAAO,MAAM,CAAC,MAAM,CAAC;IAC3B,OAAO,EAAE,0BAA0B,GAAG;QAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAAC;CACjE;AAED,oBAAY,WAAW,GAAG,mBAAmB,CAAC;AAE9C,oBAAY,kBAAkB,GAAG,WAAW,GAAG;IAAE,KAAK,EAAE,OAAO,YAAY,CAAA;CAAE,CAAC;AAE9E,oBAAY,qBAAqB,GAAG,CAClC,IAAI,EAAE,OAAO,YAAY,EACzB,EAAE,EAAE,CAAC,KAAK,EAAE,kBAAkB,KAAK,IAAI,KACpC,IAAI,CAAC;AAEV,eAAO,MAAM,mBAAmB,EAAE,gBAAgB,CAAC,OAAO,YAAY,EAAE,WAAW,CAQxE,CAAC"}
|
|
@@ -1,10 +1,20 @@
|
|
|
1
1
|
import type { PROTO } from '../constants';
|
|
2
2
|
import type { Device } from '../types';
|
|
3
|
+
import type { DeviceButtonRequest } from './device';
|
|
3
4
|
import type { MessageFactoryFn } from './utils';
|
|
4
5
|
export declare const UI_EVENT = "UI_EVENT";
|
|
5
6
|
export declare const UI_REQUEST: {
|
|
6
7
|
readonly REQUEST_PIN: "ui-request_pin";
|
|
8
|
+
readonly INVALID_PIN: "ui-invalid_pin";
|
|
9
|
+
readonly REQUEST_BUTTON: "ui-button";
|
|
10
|
+
readonly CLOSE_UI_WINDOW: "ui-close_window";
|
|
11
|
+
readonly BLUETOOTH_PERMISSION: "ui-bluetooth_permission";
|
|
12
|
+
readonly LOCATION_PERMISSION: "ui-location_permission";
|
|
7
13
|
};
|
|
14
|
+
export interface UiRequestWithoutPayload {
|
|
15
|
+
type: typeof UI_REQUEST.CLOSE_UI_WINDOW | typeof UI_REQUEST.BLUETOOTH_PERMISSION | typeof UI_REQUEST.LOCATION_PERMISSION;
|
|
16
|
+
payload?: typeof undefined;
|
|
17
|
+
}
|
|
8
18
|
export declare type UiRequestDeviceAction = {
|
|
9
19
|
type: typeof UI_REQUEST.REQUEST_PIN;
|
|
10
20
|
payload: {
|
|
@@ -12,7 +22,11 @@ export declare type UiRequestDeviceAction = {
|
|
|
12
22
|
type?: PROTO.PinMatrixRequestType;
|
|
13
23
|
};
|
|
14
24
|
};
|
|
15
|
-
export
|
|
25
|
+
export interface UiRequestButton {
|
|
26
|
+
type: typeof UI_REQUEST.REQUEST_BUTTON;
|
|
27
|
+
payload: DeviceButtonRequest['payload'];
|
|
28
|
+
}
|
|
29
|
+
export declare type UiEvent = UiRequestWithoutPayload | UiRequestDeviceAction | UiRequestButton;
|
|
16
30
|
export declare type UiEventMessage = UiEvent & {
|
|
17
31
|
event: typeof UI_EVENT;
|
|
18
32
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ui-request.d.ts","sourceRoot":"","sources":["../../src/events/ui-request.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAEhD,eAAO,MAAM,QAAQ,aAAa,CAAC;AAEnC,eAAO,MAAM,UAAU
|
|
1
|
+
{"version":3,"file":"ui-request.d.ts","sourceRoot":"","sources":["../../src/events/ui-request.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AACpD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAEhD,eAAO,MAAM,QAAQ,aAAa,CAAC;AAEnC,eAAO,MAAM,UAAU;;;;;;;CASb,CAAC;AAEX,MAAM,WAAW,uBAAuB;IACtC,IAAI,EACA,OAAO,UAAU,CAAC,eAAe,GACjC,OAAO,UAAU,CAAC,oBAAoB,GACtC,OAAO,UAAU,CAAC,mBAAmB,CAAC;IAC1C,OAAO,CAAC,EAAE,OAAO,SAAS,CAAC;CAC5B;AAED,oBAAY,qBAAqB,GAAG;IAClC,IAAI,EAAE,OAAO,UAAU,CAAC,WAAW,CAAC;IACpC,OAAO,EAAE;QACP,MAAM,EAAE,MAAM,CAAC;QACf,IAAI,CAAC,EAAE,KAAK,CAAC,oBAAoB,CAAC;KACnC,CAAC;CACH,CAAC;AAEF,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,OAAO,UAAU,CAAC,cAAc,CAAC;IACvC,OAAO,EAAE,mBAAmB,CAAC,SAAS,CAAC,CAAC;CACzC;AAED,oBAAY,OAAO,GAAG,uBAAuB,GAAG,qBAAqB,GAAG,eAAe,CAAC;AAExF,oBAAY,cAAc,GAAG,OAAO,GAAG;IAAE,KAAK,EAAE,OAAO,QAAQ,CAAA;CAAE,CAAC;AAElE,eAAO,MAAM,eAAe,EAAE,gBAAgB,CAAC,OAAO,QAAQ,EAAE,OAAO,CAK5D,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import EventEmitter, { EventEmitter as EventEmitter$1 } from 'events';
|
|
2
2
|
import { Messages, Transport, OneKeyDeviceInfo } from '@onekeyfe/hd-transport';
|
|
3
3
|
export { Messages as PROTO } from '@onekeyfe/hd-transport';
|
|
4
|
-
import { EthereumPublicKey, EthereumMessageSignature, Success as Success$1, Address, MultisigRedeemScriptType, InputScriptType, PublicKey, MessageSignature,
|
|
4
|
+
import { EthereumPublicKey, EthereumMessageSignature, Success as Success$1, Address, MultisigRedeemScriptType, InputScriptType, PublicKey, MessageSignature, PrevInput, TxOutputBinType, TxInput, TxOutputType, TxInputType, RecoveryDeviceType, SafetyCheckLevel, StarcoinAddress as StarcoinAddress$1, StarcoinPublicKey as StarcoinPublicKey$1, StarcoinMessageSignature, StarcoinSignedTx } from '@onekeyfe/hd-transport/src/types/messages';
|
|
5
5
|
|
|
6
6
|
interface CommonParams {
|
|
7
7
|
keepSession?: boolean;
|
|
@@ -361,6 +361,20 @@ declare type BTCSignMessageParams = {
|
|
|
361
361
|
};
|
|
362
362
|
declare function btcSignMessage(connectId: string, params: CommonParams & BTCSignMessageParams): Response<MessageSignature>;
|
|
363
363
|
|
|
364
|
+
declare type SignedTransaction = {
|
|
365
|
+
signatures: string[];
|
|
366
|
+
serializedTx: string;
|
|
367
|
+
txid?: string;
|
|
368
|
+
};
|
|
369
|
+
declare type TransactionOptions = {
|
|
370
|
+
version?: number;
|
|
371
|
+
lock_time?: number;
|
|
372
|
+
expiry?: number;
|
|
373
|
+
overwintered?: boolean;
|
|
374
|
+
version_group_id?: number;
|
|
375
|
+
timestamp?: number;
|
|
376
|
+
branch_id?: number;
|
|
377
|
+
};
|
|
364
378
|
declare type RefTransaction = {
|
|
365
379
|
hash: string;
|
|
366
380
|
version: number;
|
|
@@ -417,7 +431,7 @@ declare type BTCSignTransactionParams = {
|
|
|
417
431
|
branchId?: number;
|
|
418
432
|
timestamp?: number;
|
|
419
433
|
};
|
|
420
|
-
declare function btcSignTransaction(connectId: string, params: CommonParams & BTCSignTransactionParams): Response<
|
|
434
|
+
declare function btcSignTransaction(connectId: string, params: CommonParams & BTCSignTransactionParams): Response<SignedTransaction>;
|
|
421
435
|
|
|
422
436
|
declare type BTCVerifyMessageParams = {
|
|
423
437
|
address: string;
|
|
@@ -588,10 +602,54 @@ declare type MessageFactoryFn<Group, Event> = UnionToIntersection<Event extends
|
|
|
588
602
|
payload: undefined;
|
|
589
603
|
} : never>;
|
|
590
604
|
|
|
605
|
+
declare const DEVICE_EVENT = "DEVICE_EVENT";
|
|
606
|
+
declare const DEVICE: {
|
|
607
|
+
readonly CONNECT: "device-connect";
|
|
608
|
+
readonly CONNECT_UNACQUIRED: "device-connect_unacquired";
|
|
609
|
+
readonly DISCONNECT: "device-disconnect";
|
|
610
|
+
readonly CHANGED: "device-changed";
|
|
611
|
+
readonly ACQUIRE: "device-acquire";
|
|
612
|
+
readonly RELEASE: "device-release";
|
|
613
|
+
readonly ACQUIRED: "device-acquired";
|
|
614
|
+
readonly RELEASED: "device-released";
|
|
615
|
+
readonly USED_ELSEWHERE: "device-used_elsewhere";
|
|
616
|
+
readonly UNREADABLE: "unreadable-device";
|
|
617
|
+
readonly LOADING: "device-loading";
|
|
618
|
+
readonly BUTTON: "button";
|
|
619
|
+
readonly PIN: "pin";
|
|
620
|
+
readonly PASSPHRASE: "passphrase";
|
|
621
|
+
readonly PASSPHRASE_ON_DEVICE: "passphrase_on_device";
|
|
622
|
+
readonly WORD: "word";
|
|
623
|
+
};
|
|
624
|
+
interface DeviceButtonRequestPayload extends Omit<Messages.ButtonRequest, 'code'> {
|
|
625
|
+
code?: Messages.ButtonRequest['code'] | 'ButtonRequest_FirmwareUpdate';
|
|
626
|
+
}
|
|
627
|
+
interface DeviceButtonRequest {
|
|
628
|
+
type: typeof DEVICE.BUTTON;
|
|
629
|
+
payload: DeviceButtonRequestPayload & {
|
|
630
|
+
device: KnownDevice | null;
|
|
631
|
+
};
|
|
632
|
+
}
|
|
633
|
+
declare type DeviceEvent = DeviceButtonRequest;
|
|
634
|
+
declare type DeviceEventMessage = DeviceEvent & {
|
|
635
|
+
event: typeof DEVICE_EVENT;
|
|
636
|
+
};
|
|
637
|
+
declare type DeviceEventListenerFn = (type: typeof DEVICE_EVENT, cb: (event: DeviceEventMessage) => void) => void;
|
|
638
|
+
declare const createDeviceMessage: MessageFactoryFn<typeof DEVICE_EVENT, DeviceEvent>;
|
|
639
|
+
|
|
591
640
|
declare const UI_EVENT = "UI_EVENT";
|
|
592
641
|
declare const UI_REQUEST: {
|
|
593
642
|
readonly REQUEST_PIN: "ui-request_pin";
|
|
594
|
-
|
|
643
|
+
readonly INVALID_PIN: "ui-invalid_pin";
|
|
644
|
+
readonly REQUEST_BUTTON: "ui-button";
|
|
645
|
+
readonly CLOSE_UI_WINDOW: "ui-close_window";
|
|
646
|
+
readonly BLUETOOTH_PERMISSION: "ui-bluetooth_permission";
|
|
647
|
+
readonly LOCATION_PERMISSION: "ui-location_permission";
|
|
648
|
+
};
|
|
649
|
+
interface UiRequestWithoutPayload {
|
|
650
|
+
type: typeof UI_REQUEST.CLOSE_UI_WINDOW | typeof UI_REQUEST.BLUETOOTH_PERMISSION | typeof UI_REQUEST.LOCATION_PERMISSION;
|
|
651
|
+
payload?: typeof undefined;
|
|
652
|
+
}
|
|
595
653
|
declare type UiRequestDeviceAction = {
|
|
596
654
|
type: typeof UI_REQUEST.REQUEST_PIN;
|
|
597
655
|
payload: {
|
|
@@ -599,7 +657,11 @@ declare type UiRequestDeviceAction = {
|
|
|
599
657
|
type?: Messages.PinMatrixRequestType;
|
|
600
658
|
};
|
|
601
659
|
};
|
|
602
|
-
|
|
660
|
+
interface UiRequestButton {
|
|
661
|
+
type: typeof UI_REQUEST.REQUEST_BUTTON;
|
|
662
|
+
payload: DeviceButtonRequest['payload'];
|
|
663
|
+
}
|
|
664
|
+
declare type UiEvent = UiRequestWithoutPayload | UiRequestDeviceAction | UiRequestButton;
|
|
603
665
|
declare type UiEventMessage = UiEvent & {
|
|
604
666
|
event: typeof UI_EVENT;
|
|
605
667
|
};
|
|
@@ -681,35 +743,13 @@ declare const CORE_EVENT = "CORE_EVENT";
|
|
|
681
743
|
declare type CoreMessage = {
|
|
682
744
|
id?: string;
|
|
683
745
|
success?: true | false;
|
|
684
|
-
} & (IFrameEventMessage | IFrameCallMessage | UiResponseMessage | UiEventMessage);
|
|
746
|
+
} & (IFrameEventMessage | IFrameCallMessage | UiResponseMessage | UiEventMessage | DeviceEventMessage);
|
|
685
747
|
declare type PostMessageEvent = MessageEvent<any>;
|
|
686
748
|
declare const parseMessage: (messageData: any) => CoreMessage;
|
|
687
749
|
declare const createErrorMessage: (error: Error & {
|
|
688
750
|
code?: string;
|
|
689
751
|
}) => Unsuccessful;
|
|
690
752
|
|
|
691
|
-
declare const DEVICE: {
|
|
692
|
-
readonly CONNECT: "device-connect";
|
|
693
|
-
readonly CONNECT_UNACQUIRED: "device-connect_unacquired";
|
|
694
|
-
readonly DISCONNECT: "device-disconnect";
|
|
695
|
-
readonly CHANGED: "device-changed";
|
|
696
|
-
readonly ACQUIRE: "device-acquire";
|
|
697
|
-
readonly RELEASE: "device-release";
|
|
698
|
-
readonly ACQUIRED: "device-acquired";
|
|
699
|
-
readonly RELEASED: "device-released";
|
|
700
|
-
readonly USED_ELSEWHERE: "device-used_elsewhere";
|
|
701
|
-
readonly UNREADABLE: "unreadable-device";
|
|
702
|
-
readonly LOADING: "device-loading";
|
|
703
|
-
readonly BUTTON: "button";
|
|
704
|
-
readonly PIN: "pin";
|
|
705
|
-
readonly PASSPHRASE: "passphrase";
|
|
706
|
-
readonly PASSPHRASE_ON_DEVICE: "passphrase_on_device";
|
|
707
|
-
readonly WORD: "word";
|
|
708
|
-
};
|
|
709
|
-
interface DeviceButtonRequestPayload extends Omit<Messages.ButtonRequest, 'code'> {
|
|
710
|
-
code?: Messages.ButtonRequest['code'] | 'ButtonRequest_FirmwareUpdate';
|
|
711
|
-
}
|
|
712
|
-
|
|
713
753
|
declare type DeviceDescriptorDiff = {
|
|
714
754
|
didUpdate: boolean;
|
|
715
755
|
connected: OneKeyDeviceInfo[];
|
|
@@ -852,8 +892,9 @@ declare const getDeviceType: (features?: {
|
|
|
852
892
|
} | undefined) => IDeviceType;
|
|
853
893
|
declare const getDeviceUUID: (features: Features) => string;
|
|
854
894
|
declare const getDeviceLabel: (features: Features) => string;
|
|
855
|
-
|
|
856
|
-
declare const
|
|
895
|
+
|
|
896
|
+
declare const getHDPath: (path: string) => Array<number>;
|
|
897
|
+
declare const getScriptType: (path: Array<number>) => InputScriptType;
|
|
857
898
|
|
|
858
899
|
declare type RunOptions = {
|
|
859
900
|
keepSession?: boolean;
|
|
@@ -958,4 +999,4 @@ declare class DataManager {
|
|
|
958
999
|
|
|
959
1000
|
declare const HardwareSdk: ({ init, call, dispose, eventEmitter, uiResponse, cancel, }: InjectApi) => CoreApi;
|
|
960
1001
|
|
|
961
|
-
export { AssetsMap, BTCAddress, BTCGetAddressParams, BTCGetPublicKeyParams, BTCPublicKey, BTCSignMessageParams, BTCVerifyMessageParams, CORE_EVENT, CallMethod, CallMethodAnyResponse, CallMethodKeys, CallMethodPayload, CallMethodResponse, CallMethodUnion, CommonParams, ConnectSettings, Core, CoreApi, CoreMessage, DEFAULT_PRIORITY, DEVICE, DataManager, Deferred, Device$1 as Device, DeviceButtonRequestPayload, DeviceChangePinParams, DeviceFlagsParams, DeviceMode, DeviceRecoveryParams, DeviceResetParams, DeviceSettingsParams, DeviceStatus, DeviceTypeMap, errors as ERRORS, EVMAccessList, EVMAddress, EVMGetAddressParams, EVMGetPublicKeyParams, EVMPublicKey, EVMSignMessageEIP712Params, EVMSignMessageParams, EVMSignTransactionParams, EVMSignTypedDataParams, EVMSignedTx, EVMTransaction, EVMTransactionEIP1559, EVMVerifyMessageParams, EthereumSignTypedDataMessage, EthereumSignTypedDataTypeProperty, EthereumSignTypedDataTypes, Features, FirmwareRange, FirmwareRelease, IBLEFirmwareReleaseInfo, IDeviceBLEFirmwareStatus, IDeviceFirmwareStatus, IDeviceType, IFRAME, IFirmwareReleaseInfo, IFrameBridge, IFrameCallMessage, IFrameEvent, IFrameEventMessage, IFrameInit, ILocale, ITransportStatus, IVersionArray, KnownDevice, MethodResponseMessage, PostMessageEvent, RESPONSE_EVENT, ReleaseInfo, RemoteConfigResponse, Response, SearchDevice, StarcoinAddress, StarcoinGetAddressParams, StarcoinGetPublicKeyParams, StarcoinPublicKey, StarcoinSignMessageParams, StarcoinSignTransactionParams, StarcoinVerifyMessageParams, Success, TransportReleaseStatus, UI_EVENT, UI_REQUEST, UI_RESPONSE, UiEvent, UiEventMessage, UiPromise, UiPromiseResponse, UiRequestDeviceAction, UiResponseEvent, UiResponseMessage, UiResponsePin, UnavailableCapabilities, UnavailableCapability, Unsuccessful, VersionArray, corsValidator, create, createErrorMessage, createIFrameMessage, createResponseMessage, createUiMessage, createUiResponse, HardwareSdk as default, enableLog,
|
|
1002
|
+
export { AccountAddress, AccountAddresses, AssetsMap, BTCAddress, BTCGetAddressParams, BTCGetPublicKeyParams, BTCPublicKey, BTCSignMessageParams, BTCSignTransactionParams, BTCVerifyMessageParams, CORE_EVENT, CallMethod, CallMethodAnyResponse, CallMethodKeys, CallMethodPayload, CallMethodResponse, CallMethodUnion, CommonParams, ConnectSettings, Core, CoreApi, CoreMessage, DEFAULT_PRIORITY, DEVICE, DEVICE_EVENT, DataManager, Deferred, Device$1 as Device, DeviceButtonRequest, DeviceButtonRequestPayload, DeviceChangePinParams, DeviceEvent, DeviceEventListenerFn, DeviceEventMessage, DeviceFlagsParams, DeviceMode, DeviceRecoveryParams, DeviceResetParams, DeviceSettingsParams, DeviceStatus, DeviceTypeMap, errors as ERRORS, EVMAccessList, EVMAddress, EVMGetAddressParams, EVMGetPublicKeyParams, EVMPublicKey, EVMSignMessageEIP712Params, EVMSignMessageParams, EVMSignTransactionParams, EVMSignTypedDataParams, EVMSignedTx, EVMTransaction, EVMTransactionEIP1559, EVMVerifyMessageParams, EthereumSignTypedDataMessage, EthereumSignTypedDataTypeProperty, EthereumSignTypedDataTypes, Features, FirmwareRange, FirmwareRelease, IBLEFirmwareReleaseInfo, IDeviceBLEFirmwareStatus, IDeviceFirmwareStatus, IDeviceType, IFRAME, IFirmwareReleaseInfo, IFrameBridge, IFrameCallMessage, IFrameEvent, IFrameEventMessage, IFrameInit, ILocale, ITransportStatus, IVersionArray, KnownDevice, MethodResponseMessage, PostMessageEvent, RESPONSE_EVENT, RefTransaction, ReleaseInfo, RemoteConfigResponse, Response, SearchDevice, SignedTransaction, StarcoinAddress, StarcoinGetAddressParams, StarcoinGetPublicKeyParams, StarcoinPublicKey, StarcoinSignMessageParams, StarcoinSignTransactionParams, StarcoinVerifyMessageParams, Success, TransactionOptions, TransportReleaseStatus, UI_EVENT, UI_REQUEST, UI_RESPONSE, UiEvent, UiEventMessage, UiPromise, UiPromiseResponse, UiRequestButton, UiRequestDeviceAction, UiRequestWithoutPayload, UiResponseEvent, UiResponseMessage, UiResponsePin, UnavailableCapabilities, UnavailableCapability, Unsuccessful, VersionArray, corsValidator, create, createDeviceMessage, createErrorMessage, createIFrameMessage, createResponseMessage, createUiMessage, createUiResponse, HardwareSdk as default, enableLog, getDeviceLabel, getDeviceType, getDeviceUUID, getEnv, getHDPath, getScriptType, getTimeStamp, httpRequest, init as initCore, initLog, isValidVersionArray, isValidVersionString, normalizeVersionArray, parseConnectSettings, parseMessage, versionCompare, versionSplit };
|
package/dist/index.js
CHANGED
|
@@ -845,6 +845,109 @@ const getDeviceBLEFirmwareVersion = (features) => {
|
|
|
845
845
|
return features.ble_ver.split('.');
|
|
846
846
|
};
|
|
847
847
|
|
|
848
|
+
const HD_HARDENED = 0x80000000;
|
|
849
|
+
const toHardened = (n) => (n | HD_HARDENED) >>> 0;
|
|
850
|
+
const fromHardened = (n) => (n & ~HD_HARDENED) >>> 0;
|
|
851
|
+
const PATH_NOT_VALID = TypedError('Method_InvalidParameter', 'Not a valid path');
|
|
852
|
+
const PATH_NEGATIVE_VALUES = TypedError('Method_InvalidParameter', 'Path cannot contain negative values');
|
|
853
|
+
const getHDPath = (path) => {
|
|
854
|
+
const parts = path.toLowerCase().split('/');
|
|
855
|
+
if (parts[0] !== 'm')
|
|
856
|
+
throw PATH_NOT_VALID;
|
|
857
|
+
return parts
|
|
858
|
+
.filter((p) => p !== 'm' && p !== '')
|
|
859
|
+
.map((p) => {
|
|
860
|
+
let hardened = false;
|
|
861
|
+
if (p.substr(p.length - 1) === "'") {
|
|
862
|
+
hardened = true;
|
|
863
|
+
p = p.substr(0, p.length - 1);
|
|
864
|
+
}
|
|
865
|
+
let n = parseInt(p);
|
|
866
|
+
if (Number.isNaN(n)) {
|
|
867
|
+
throw PATH_NOT_VALID;
|
|
868
|
+
}
|
|
869
|
+
else if (n < 0) {
|
|
870
|
+
throw PATH_NEGATIVE_VALUES;
|
|
871
|
+
}
|
|
872
|
+
if (hardened) {
|
|
873
|
+
n = toHardened(n);
|
|
874
|
+
}
|
|
875
|
+
return n;
|
|
876
|
+
});
|
|
877
|
+
};
|
|
878
|
+
const isMultisigPath = (path) => Array.isArray(path) && path[0] === toHardened(48);
|
|
879
|
+
const isSegwitPath = (path) => Array.isArray(path) && path[0] === toHardened(49);
|
|
880
|
+
const getScriptType = (path) => {
|
|
881
|
+
if (!Array.isArray(path) || path.length < 1)
|
|
882
|
+
return 'SPENDADDRESS';
|
|
883
|
+
const p1 = fromHardened(path[0]);
|
|
884
|
+
switch (p1) {
|
|
885
|
+
case 48:
|
|
886
|
+
return 'SPENDMULTISIG';
|
|
887
|
+
case 49:
|
|
888
|
+
return 'SPENDP2SHWITNESS';
|
|
889
|
+
case 84:
|
|
890
|
+
return 'SPENDWITNESS';
|
|
891
|
+
default:
|
|
892
|
+
return 'SPENDADDRESS';
|
|
893
|
+
}
|
|
894
|
+
};
|
|
895
|
+
const getOutputScriptType = (path) => {
|
|
896
|
+
if (!Array.isArray(path) || path.length < 1)
|
|
897
|
+
return 'PAYTOADDRESS';
|
|
898
|
+
if (path[0] === 49) {
|
|
899
|
+
return 'PAYTOP2SHWITNESS';
|
|
900
|
+
}
|
|
901
|
+
const p = fromHardened(path[0]);
|
|
902
|
+
switch (p) {
|
|
903
|
+
case 48:
|
|
904
|
+
return 'PAYTOMULTISIG';
|
|
905
|
+
case 49:
|
|
906
|
+
return 'PAYTOP2SHWITNESS';
|
|
907
|
+
case 84:
|
|
908
|
+
return 'PAYTOWITNESS';
|
|
909
|
+
default:
|
|
910
|
+
return 'PAYTOADDRESS';
|
|
911
|
+
}
|
|
912
|
+
};
|
|
913
|
+
const serializedPath = (path) => {
|
|
914
|
+
const pathStr = path
|
|
915
|
+
.map((p) => {
|
|
916
|
+
if (p & HD_HARDENED) {
|
|
917
|
+
return `${p & ~HD_HARDENED}'`;
|
|
918
|
+
}
|
|
919
|
+
return p;
|
|
920
|
+
})
|
|
921
|
+
.join('/');
|
|
922
|
+
return `m/${pathStr}`;
|
|
923
|
+
};
|
|
924
|
+
const validatePath = (path, length = 0, base = false) => {
|
|
925
|
+
let valid;
|
|
926
|
+
if (typeof path === 'string') {
|
|
927
|
+
valid = getHDPath(path);
|
|
928
|
+
}
|
|
929
|
+
else if (Array.isArray(path)) {
|
|
930
|
+
valid = path.map((p) => {
|
|
931
|
+
const n = parseInt(p);
|
|
932
|
+
if (Number.isNaN(n)) {
|
|
933
|
+
throw PATH_NOT_VALID;
|
|
934
|
+
}
|
|
935
|
+
else if (n < 0) {
|
|
936
|
+
throw PATH_NEGATIVE_VALUES;
|
|
937
|
+
}
|
|
938
|
+
return n;
|
|
939
|
+
});
|
|
940
|
+
}
|
|
941
|
+
else {
|
|
942
|
+
valid = undefined;
|
|
943
|
+
}
|
|
944
|
+
if (!valid)
|
|
945
|
+
throw PATH_NOT_VALID;
|
|
946
|
+
if (length > 0 && valid.length < length)
|
|
947
|
+
throw PATH_NOT_VALID;
|
|
948
|
+
return base ? valid.splice(0, 3) : valid;
|
|
949
|
+
};
|
|
950
|
+
|
|
848
951
|
var nested = {
|
|
849
952
|
BinanceGetAddress: {
|
|
850
953
|
fields: {
|
|
@@ -9805,6 +9908,11 @@ const createErrorMessage = (error) => ({
|
|
|
9805
9908
|
const UI_EVENT = 'UI_EVENT';
|
|
9806
9909
|
const UI_REQUEST$1 = {
|
|
9807
9910
|
REQUEST_PIN: 'ui-request_pin',
|
|
9911
|
+
INVALID_PIN: 'ui-invalid_pin',
|
|
9912
|
+
REQUEST_BUTTON: 'ui-button',
|
|
9913
|
+
CLOSE_UI_WINDOW: 'ui-close_window',
|
|
9914
|
+
BLUETOOTH_PERMISSION: 'ui-bluetooth_permission',
|
|
9915
|
+
LOCATION_PERMISSION: 'ui-location_permission',
|
|
9808
9916
|
};
|
|
9809
9917
|
const createUiMessage = (type, payload) => ({
|
|
9810
9918
|
event: UI_EVENT,
|
|
@@ -9841,6 +9949,7 @@ const createUiResponse = (type, payload) => ({
|
|
|
9841
9949
|
payload,
|
|
9842
9950
|
});
|
|
9843
9951
|
|
|
9952
|
+
const DEVICE_EVENT = 'DEVICE_EVENT';
|
|
9844
9953
|
const DEVICE = {
|
|
9845
9954
|
CONNECT: 'device-connect',
|
|
9846
9955
|
CONNECT_UNACQUIRED: 'device-connect_unacquired',
|
|
@@ -9859,6 +9968,11 @@ const DEVICE = {
|
|
|
9859
9968
|
PASSPHRASE_ON_DEVICE: 'passphrase_on_device',
|
|
9860
9969
|
WORD: 'word',
|
|
9861
9970
|
};
|
|
9971
|
+
const createDeviceMessage = (type, payload) => ({
|
|
9972
|
+
event: DEVICE_EVENT,
|
|
9973
|
+
type,
|
|
9974
|
+
payload,
|
|
9975
|
+
});
|
|
9862
9976
|
|
|
9863
9977
|
const assertType = (res, resType) => {
|
|
9864
9978
|
const splitResTypes = Array.isArray(resType) ? resType : resType.split('|');
|
|
@@ -10483,109 +10597,6 @@ class GetFeatures extends BaseMethod {
|
|
|
10483
10597
|
}
|
|
10484
10598
|
}
|
|
10485
10599
|
|
|
10486
|
-
const HD_HARDENED = 0x80000000;
|
|
10487
|
-
const toHardened = (n) => (n | HD_HARDENED) >>> 0;
|
|
10488
|
-
const fromHardened = (n) => (n & ~HD_HARDENED) >>> 0;
|
|
10489
|
-
const PATH_NOT_VALID = TypedError('Method_InvalidParameter', 'Not a valid path');
|
|
10490
|
-
const PATH_NEGATIVE_VALUES = TypedError('Method_InvalidParameter', 'Path cannot contain negative values');
|
|
10491
|
-
const getHDPath = (path) => {
|
|
10492
|
-
const parts = path.toLowerCase().split('/');
|
|
10493
|
-
if (parts[0] !== 'm')
|
|
10494
|
-
throw PATH_NOT_VALID;
|
|
10495
|
-
return parts
|
|
10496
|
-
.filter((p) => p !== 'm' && p !== '')
|
|
10497
|
-
.map((p) => {
|
|
10498
|
-
let hardened = false;
|
|
10499
|
-
if (p.substr(p.length - 1) === "'") {
|
|
10500
|
-
hardened = true;
|
|
10501
|
-
p = p.substr(0, p.length - 1);
|
|
10502
|
-
}
|
|
10503
|
-
let n = parseInt(p);
|
|
10504
|
-
if (Number.isNaN(n)) {
|
|
10505
|
-
throw PATH_NOT_VALID;
|
|
10506
|
-
}
|
|
10507
|
-
else if (n < 0) {
|
|
10508
|
-
throw PATH_NEGATIVE_VALUES;
|
|
10509
|
-
}
|
|
10510
|
-
if (hardened) {
|
|
10511
|
-
n = toHardened(n);
|
|
10512
|
-
}
|
|
10513
|
-
return n;
|
|
10514
|
-
});
|
|
10515
|
-
};
|
|
10516
|
-
const isMultisigPath = (path) => Array.isArray(path) && path[0] === toHardened(48);
|
|
10517
|
-
const isSegwitPath = (path) => Array.isArray(path) && path[0] === toHardened(49);
|
|
10518
|
-
const getScriptType = (path) => {
|
|
10519
|
-
if (!Array.isArray(path) || path.length < 1)
|
|
10520
|
-
return 'SPENDADDRESS';
|
|
10521
|
-
const p1 = fromHardened(path[0]);
|
|
10522
|
-
switch (p1) {
|
|
10523
|
-
case 48:
|
|
10524
|
-
return 'SPENDMULTISIG';
|
|
10525
|
-
case 49:
|
|
10526
|
-
return 'SPENDP2SHWITNESS';
|
|
10527
|
-
case 84:
|
|
10528
|
-
return 'SPENDWITNESS';
|
|
10529
|
-
default:
|
|
10530
|
-
return 'SPENDADDRESS';
|
|
10531
|
-
}
|
|
10532
|
-
};
|
|
10533
|
-
const getOutputScriptType = (path) => {
|
|
10534
|
-
if (!Array.isArray(path) || path.length < 1)
|
|
10535
|
-
return 'PAYTOADDRESS';
|
|
10536
|
-
if (path[0] === 49) {
|
|
10537
|
-
return 'PAYTOP2SHWITNESS';
|
|
10538
|
-
}
|
|
10539
|
-
const p = fromHardened(path[0]);
|
|
10540
|
-
switch (p) {
|
|
10541
|
-
case 48:
|
|
10542
|
-
return 'PAYTOMULTISIG';
|
|
10543
|
-
case 49:
|
|
10544
|
-
return 'PAYTOP2SHWITNESS';
|
|
10545
|
-
case 84:
|
|
10546
|
-
return 'PAYTOWITNESS';
|
|
10547
|
-
default:
|
|
10548
|
-
return 'PAYTOADDRESS';
|
|
10549
|
-
}
|
|
10550
|
-
};
|
|
10551
|
-
const serializedPath = (path) => {
|
|
10552
|
-
const pathStr = path
|
|
10553
|
-
.map((p) => {
|
|
10554
|
-
if (p & HD_HARDENED) {
|
|
10555
|
-
return `${p & ~HD_HARDENED}'`;
|
|
10556
|
-
}
|
|
10557
|
-
return p;
|
|
10558
|
-
})
|
|
10559
|
-
.join('/');
|
|
10560
|
-
return `m/${pathStr}`;
|
|
10561
|
-
};
|
|
10562
|
-
const validatePath = (path, length = 0, base = false) => {
|
|
10563
|
-
let valid;
|
|
10564
|
-
if (typeof path === 'string') {
|
|
10565
|
-
valid = getHDPath(path);
|
|
10566
|
-
}
|
|
10567
|
-
else if (Array.isArray(path)) {
|
|
10568
|
-
valid = path.map((p) => {
|
|
10569
|
-
const n = parseInt(p);
|
|
10570
|
-
if (Number.isNaN(n)) {
|
|
10571
|
-
throw PATH_NOT_VALID;
|
|
10572
|
-
}
|
|
10573
|
-
else if (n < 0) {
|
|
10574
|
-
throw PATH_NEGATIVE_VALUES;
|
|
10575
|
-
}
|
|
10576
|
-
return n;
|
|
10577
|
-
});
|
|
10578
|
-
}
|
|
10579
|
-
else {
|
|
10580
|
-
valid = undefined;
|
|
10581
|
-
}
|
|
10582
|
-
if (!valid)
|
|
10583
|
-
throw PATH_NOT_VALID;
|
|
10584
|
-
if (length > 0 && valid.length < length)
|
|
10585
|
-
throw PATH_NOT_VALID;
|
|
10586
|
-
return base ? valid.splice(0, 3) : valid;
|
|
10587
|
-
};
|
|
10588
|
-
|
|
10589
10600
|
const hasHexPrefix = (str) => str.slice(0, 2).toLowerCase() === '0x';
|
|
10590
10601
|
const stripHexPrefix = (str) => (hasHexPrefix(str) ? str.slice(2) : str);
|
|
10591
10602
|
const addHexPrefix = (str) => (hasHexPrefix(str) ? str : `0x${str}`);
|
|
@@ -10978,8 +10989,8 @@ class BTCGetPublicKey extends BaseMethod {
|
|
|
10978
10989
|
}
|
|
10979
10990
|
init() {
|
|
10980
10991
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
|
|
10981
|
-
|
|
10982
|
-
const payload = hasBundle ? this.payload : { bundle: [this.payload] };
|
|
10992
|
+
this.hasBundle = Object.prototype.hasOwnProperty.call(this.payload, 'bundle');
|
|
10993
|
+
const payload = this.hasBundle ? this.payload : { bundle: [this.payload] };
|
|
10983
10994
|
validateParams(payload, [{ name: 'bundle', type: 'array' }]);
|
|
10984
10995
|
this.params = [];
|
|
10985
10996
|
payload.bundle.forEach((batch) => {
|
|
@@ -12316,7 +12327,7 @@ let _connector;
|
|
|
12316
12327
|
let _uiPromises = [];
|
|
12317
12328
|
let _callPromise;
|
|
12318
12329
|
const callAPI = (message) => __awaiter(void 0, void 0, void 0, function* () {
|
|
12319
|
-
var _a;
|
|
12330
|
+
var _a, _b;
|
|
12320
12331
|
if (!message.id || !message.payload || message.type !== IFRAME.CALL) {
|
|
12321
12332
|
return Promise.reject(TypedError('Method_InvalidParameter', 'onCall: message.id or message.payload is missing'));
|
|
12322
12333
|
}
|
|
@@ -12336,7 +12347,10 @@ const callAPI = (message) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
12336
12347
|
return createResponseMessage(method.responseID, true, response);
|
|
12337
12348
|
}
|
|
12338
12349
|
catch (error) {
|
|
12339
|
-
return createResponseMessage(method.responseID, false,
|
|
12350
|
+
return createResponseMessage(method.responseID, false, {
|
|
12351
|
+
code: error.code,
|
|
12352
|
+
error: (_a = error.message) !== null && _a !== void 0 ? _a : error,
|
|
12353
|
+
});
|
|
12340
12354
|
}
|
|
12341
12355
|
}
|
|
12342
12356
|
try {
|
|
@@ -12359,8 +12373,11 @@ const callAPI = (message) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
12359
12373
|
return Promise.reject(error);
|
|
12360
12374
|
}
|
|
12361
12375
|
Log.debug('Call API - setDevice: ', device);
|
|
12362
|
-
(
|
|
12376
|
+
(_b = method.setDevice) === null || _b === void 0 ? void 0 : _b.call(method, device);
|
|
12363
12377
|
device.on(DEVICE.PIN, onDevicePinHandler);
|
|
12378
|
+
device.on(DEVICE.BUTTON, (d, code) => {
|
|
12379
|
+
onDeviceButtonHandler(d, code);
|
|
12380
|
+
});
|
|
12364
12381
|
try {
|
|
12365
12382
|
const inner = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
12366
12383
|
const unexpectedMode = device.hasUnexpectedMode(method.allowDeviceMode, method.requireDeviceMode);
|
|
@@ -12385,7 +12402,13 @@ const callAPI = (message) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
12385
12402
|
Log.debug('Call API - Device Run: ', device);
|
|
12386
12403
|
const deviceRun = () => device.run(inner);
|
|
12387
12404
|
_callPromise = create(deviceRun);
|
|
12388
|
-
|
|
12405
|
+
try {
|
|
12406
|
+
return yield _callPromise.promise;
|
|
12407
|
+
}
|
|
12408
|
+
catch (e) {
|
|
12409
|
+
console.log('Device Run Error: ', e);
|
|
12410
|
+
return createResponseMessage(method.responseID, false, e.message);
|
|
12411
|
+
}
|
|
12389
12412
|
}
|
|
12390
12413
|
catch (error) {
|
|
12391
12414
|
messageResponse = createResponseMessage(method.responseID, false, error);
|
|
@@ -12398,6 +12421,8 @@ const callAPI = (message) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
12398
12421
|
method.dispose();
|
|
12399
12422
|
}
|
|
12400
12423
|
}
|
|
12424
|
+
closePopup();
|
|
12425
|
+
cleanup();
|
|
12401
12426
|
}
|
|
12402
12427
|
});
|
|
12403
12428
|
function initDeviceList(method) {
|
|
@@ -12447,6 +12472,13 @@ function initDeviceForBle(method) {
|
|
|
12447
12472
|
device.deviceConnector = _connector;
|
|
12448
12473
|
return device;
|
|
12449
12474
|
}
|
|
12475
|
+
const cleanup = () => {
|
|
12476
|
+
_uiPromises = [];
|
|
12477
|
+
Log.debug('Cleanup...');
|
|
12478
|
+
};
|
|
12479
|
+
const closePopup = () => {
|
|
12480
|
+
postMessage(createUiMessage(UI_REQUEST$1.CLOSE_UI_WINDOW));
|
|
12481
|
+
};
|
|
12450
12482
|
const onDevicePinHandler = (...[device, type, callback]) => __awaiter(void 0, void 0, void 0, function* () {
|
|
12451
12483
|
console.log('onDevicePinHandler');
|
|
12452
12484
|
const uiPromise = createUiPromise(UI_RESPONSE.RECEIVE_PIN, device);
|
|
@@ -12457,6 +12489,10 @@ const onDevicePinHandler = (...[device, type, callback]) => __awaiter(void 0, vo
|
|
|
12457
12489
|
const uiResp = yield uiPromise.promise;
|
|
12458
12490
|
callback(null, uiResp.payload);
|
|
12459
12491
|
});
|
|
12492
|
+
const onDeviceButtonHandler = (...[device, request]) => {
|
|
12493
|
+
postMessage(createDeviceMessage(DEVICE.BUTTON, Object.assign(Object.assign({}, request), { device: device.toMessageObject() })));
|
|
12494
|
+
postMessage(createUiMessage(UI_REQUEST$1.REQUEST_BUTTON, { device: device.toMessageObject() }));
|
|
12495
|
+
};
|
|
12460
12496
|
const postMessage = (message) => {
|
|
12461
12497
|
_core.emit(CORE_EVENT, message);
|
|
12462
12498
|
};
|
|
@@ -12481,6 +12517,11 @@ class Core extends events.exports {
|
|
|
12481
12517
|
}
|
|
12482
12518
|
break;
|
|
12483
12519
|
}
|
|
12520
|
+
case UI_REQUEST$1.BLUETOOTH_PERMISSION:
|
|
12521
|
+
case UI_REQUEST$1.LOCATION_PERMISSION: {
|
|
12522
|
+
postMessage(message);
|
|
12523
|
+
break;
|
|
12524
|
+
}
|
|
12484
12525
|
case IFRAME.CALL: {
|
|
12485
12526
|
const response = yield callAPI(message);
|
|
12486
12527
|
return response;
|
|
@@ -12509,7 +12550,7 @@ const init = (settings, Transport) => __awaiter(void 0, void 0, void 0, function
|
|
|
12509
12550
|
yield DataManager.load(settings);
|
|
12510
12551
|
initTransport(Transport);
|
|
12511
12552
|
}
|
|
12512
|
-
catch (
|
|
12553
|
+
catch (_c) {
|
|
12513
12554
|
Log.error('DataManager.load error');
|
|
12514
12555
|
}
|
|
12515
12556
|
enableLog(DataManager.getSettings('debug'));
|
|
@@ -12539,6 +12580,7 @@ exports.CORE_EVENT = CORE_EVENT;
|
|
|
12539
12580
|
exports.Core = Core;
|
|
12540
12581
|
exports.DEFAULT_PRIORITY = DEFAULT_PRIORITY;
|
|
12541
12582
|
exports.DEVICE = DEVICE;
|
|
12583
|
+
exports.DEVICE_EVENT = DEVICE_EVENT;
|
|
12542
12584
|
exports.DataManager = DataManager;
|
|
12543
12585
|
exports.ERRORS = errors;
|
|
12544
12586
|
exports.IFRAME = IFRAME;
|
|
@@ -12548,6 +12590,7 @@ exports.UI_REQUEST = UI_REQUEST$1;
|
|
|
12548
12590
|
exports.UI_RESPONSE = UI_RESPONSE;
|
|
12549
12591
|
exports.corsValidator = corsValidator;
|
|
12550
12592
|
exports.create = create;
|
|
12593
|
+
exports.createDeviceMessage = createDeviceMessage;
|
|
12551
12594
|
exports.createErrorMessage = createErrorMessage;
|
|
12552
12595
|
exports.createIFrameMessage = createIFrameMessage;
|
|
12553
12596
|
exports.createResponseMessage = createResponseMessage;
|
|
@@ -12555,12 +12598,12 @@ exports.createUiMessage = createUiMessage;
|
|
|
12555
12598
|
exports.createUiResponse = createUiResponse;
|
|
12556
12599
|
exports["default"] = HardwareSdk;
|
|
12557
12600
|
exports.enableLog = enableLog;
|
|
12558
|
-
exports.getDeviceBLEFirmwareVersion = getDeviceBLEFirmwareVersion;
|
|
12559
|
-
exports.getDeviceFirmwareVersion = getDeviceFirmwareVersion;
|
|
12560
12601
|
exports.getDeviceLabel = getDeviceLabel;
|
|
12561
12602
|
exports.getDeviceType = getDeviceType;
|
|
12562
12603
|
exports.getDeviceUUID = getDeviceUUID;
|
|
12563
12604
|
exports.getEnv = getEnv;
|
|
12605
|
+
exports.getHDPath = getHDPath;
|
|
12606
|
+
exports.getScriptType = getScriptType;
|
|
12564
12607
|
exports.getTimeStamp = getTimeStamp;
|
|
12565
12608
|
exports.httpRequest = httpRequest;
|
|
12566
12609
|
exports.initCore = init;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TxInput as OrigTxInput, PrevInput,
|
|
1
|
+
import { TxInput as OrigTxInput, PrevInput, TxOutputBinType, TxOutputType, TxInputType } from '@onekeyfe/hd-transport/src/types/messages';
|
|
2
2
|
import type { CommonParams, Response } from '../params';
|
|
3
3
|
export declare type SignedTransaction = {
|
|
4
4
|
signatures: string[];
|
|
@@ -70,5 +70,5 @@ export declare type BTCSignTransactionParams = {
|
|
|
70
70
|
branchId?: number;
|
|
71
71
|
timestamp?: number;
|
|
72
72
|
};
|
|
73
|
-
export declare function btcSignTransaction(connectId: string, params: CommonParams & BTCSignTransactionParams): Response<
|
|
73
|
+
export declare function btcSignTransaction(connectId: string, params: CommonParams & BTCSignTransactionParams): Response<SignedTransaction>;
|
|
74
74
|
//# sourceMappingURL=btcSignTransaction.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"btcSignTransaction.d.ts","sourceRoot":"","sources":["../../../src/types/api/btcSignTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,IAAI,WAAW,EACtB,SAAS,EACT,
|
|
1
|
+
{"version":3,"file":"btcSignTransaction.d.ts","sourceRoot":"","sources":["../../../src/types/api/btcSignTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,IAAI,WAAW,EACtB,SAAS,EACT,eAAe,EACf,YAAY,EACZ,WAAW,EACZ,MAAM,2CAA2C,CAAC;AACnD,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAExD,oBAAY,iBAAiB,GAAG;IAC9B,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,oBAAY,kBAAkB,GAAG;IAC/B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,oBAAY,cAAc,GACtB;IACE,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,SAAS,EAAE,CAAC;IACpB,WAAW,EAAE,eAAe,EAAE,CAAC;IAC/B,OAAO,CAAC,EAAE,OAAO,SAAS,CAAC;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,GACD;IACE,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,WAAW,EAAE,CAAC;IACtB,WAAW,CAAC,EAAE,OAAO,SAAS,CAAC;IAC/B,OAAO,EAAE,YAAY,EAAE,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEN,oBAAY,cAAc,GAAG;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,oBAAY,gBAAgB,GAAG;IAC7B,MAAM,EAAE,cAAc,EAAE,CAAC;IACzB,IAAI,EAAE,cAAc,EAAE,CAAC;IACvB,MAAM,EAAE,cAAc,EAAE,CAAC;CAC1B,CAAC;AAEF,oBAAY,wBAAwB,GAAG;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,WAAW,EAAE,CAAC;IACtB,OAAO,EAAE,YAAY,EAAE,CAAC;IACxB,MAAM,EAAE,cAAc,EAAE,CAAC;IACzB,OAAO,CAAC,EAAE;QAER,SAAS,EAAE,gBAAgB,CAAC;KAC7B,CAAC;IACF,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,YAAY,CAAC,EAAE,OAAO,CAAC;IAEvB,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,kBAAkB,CACxC,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,YAAY,GAAG,wBAAwB,GAC9C,QAAQ,CAAC,iBAAiB,CAAC,CAAC"}
|
|
@@ -2,6 +2,7 @@ export type { BTCAddress, BTCGetAddressParams } from './btcGetAddress';
|
|
|
2
2
|
export type { BTCPublicKey, BTCGetPublicKeyParams } from './btcGetPublicKey';
|
|
3
3
|
export type { BTCSignMessageParams } from './btcSignMessage';
|
|
4
4
|
export type { BTCVerifyMessageParams } from './btcVerifyMessage';
|
|
5
|
+
export type { RefTransaction, AccountAddress, AccountAddresses, BTCSignTransactionParams, SignedTransaction, TransactionOptions, } from './btcSignTransaction';
|
|
5
6
|
export type { DeviceChangePinParams } from './deviceChangePin';
|
|
6
7
|
export type { DeviceFlagsParams } from './deviceFlags';
|
|
7
8
|
export type { DeviceRecoveryParams } from './deviceRecovery';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"export.d.ts","sourceRoot":"","sources":["../../../src/types/api/export.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACvE,YAAY,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC7E,YAAY,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAC7D,YAAY,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"export.d.ts","sourceRoot":"","sources":["../../../src/types/api/export.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACvE,YAAY,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC7E,YAAY,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAC7D,YAAY,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AACjE,YAAY,EACV,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,wBAAwB,EACxB,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,sBAAsB,CAAC;AAE9B,YAAY,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC/D,YAAY,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACvD,YAAY,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAC7D,YAAY,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACvD,YAAY,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAE7D,YAAY,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACvE,YAAY,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC7E,YAAY,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAC7D,YAAY,EAAE,0BAA0B,EAAE,MAAM,wBAAwB,CAAC;AACzE,YAAY,EACV,cAAc,EACd,qBAAqB,EACrB,WAAW,EACX,wBAAwB,EACxB,aAAa,GACd,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EACV,0BAA0B,EAC1B,iCAAiC,EACjC,4BAA4B,EAC5B,sBAAsB,GACvB,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAEjE,YAAY,EAAE,eAAe,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AACtF,YAAY,EAAE,iBAAiB,EAAE,0BAA0B,EAAE,MAAM,wBAAwB,CAAC;AAC5F,YAAY,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AACvE,YAAY,EAAE,6BAA6B,EAAE,MAAM,2BAA2B,CAAC;AAC/E,YAAY,EAAE,2BAA2B,EAAE,MAAM,yBAAyB,CAAC"}
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { initLog, enableLog } from './logger';
|
|
|
2
2
|
export * from './assets';
|
|
3
3
|
export * from './versionUtils';
|
|
4
4
|
export * from './deferred';
|
|
5
|
-
export
|
|
5
|
+
export { getDeviceType, getDeviceUUID, getDeviceLabel } from './deviceFeaturesUtils';
|
|
6
|
+
export { getHDPath, getScriptType } from '../api/helpers/pathUtils';
|
|
6
7
|
export { initLog, enableLog };
|
|
7
8
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAE9C,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAE9C,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACrF,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAEpE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"description": "> TODO: description",
|
|
5
5
|
"author": "OneKey",
|
|
6
6
|
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"url": "https://github.com/OneKeyHQ/hardware-js-sdk/issues"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@onekeyfe/hd-transport": "^0.0.
|
|
28
|
+
"@onekeyfe/hd-transport": "^0.0.6",
|
|
29
29
|
"axios": "^0.27.2",
|
|
30
30
|
"bignumber.js": "^9.0.2",
|
|
31
31
|
"parse-uri": "^1.0.7",
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"@types/parse-uri": "^1.0.0",
|
|
36
36
|
"@types/semver": "^7.3.9"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "b37ddf4e02812f40a01ec38ffef2ff6cdcad4bbc"
|
|
39
39
|
}
|
|
@@ -13,8 +13,8 @@ export default class BTCGetPublicKey extends BaseMethod<GetPublicKey[]> {
|
|
|
13
13
|
init() {
|
|
14
14
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
const payload = hasBundle ? this.payload : { bundle: [this.payload] };
|
|
16
|
+
this.hasBundle = Object.prototype.hasOwnProperty.call(this.payload, 'bundle');
|
|
17
|
+
const payload = this.hasBundle ? this.payload : { bundle: [this.payload] };
|
|
18
18
|
|
|
19
19
|
validateParams(payload, [{ name: 'bundle', type: 'array' }]);
|
|
20
20
|
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { ChangeOutputScriptType, InputScriptType } from '@onekeyfe/hd-transport/src/types/messages';
|
|
4
4
|
import { ERRORS } from '../../constants';
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
const HD_HARDENED = 0x80000000;
|
|
7
7
|
export const toHardened = (n: number): number => (n | HD_HARDENED) >>> 0;
|
|
8
8
|
export const fromHardened = (n: number): number => (n & ~HD_HARDENED) >>> 0;
|
|
9
9
|
|
package/src/core/index.ts
CHANGED
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
UiPromise,
|
|
20
20
|
UiPromiseResponse,
|
|
21
21
|
createUiMessage,
|
|
22
|
+
createDeviceMessage,
|
|
22
23
|
} from '../events';
|
|
23
24
|
import type { BaseMethod } from '../api/BaseMethod';
|
|
24
25
|
import type { ConnectSettings, KnownDevice } from '../types';
|
|
@@ -60,7 +61,10 @@ export const callAPI = async (message: CoreMessage) => {
|
|
|
60
61
|
const response = await method.run();
|
|
61
62
|
return createResponseMessage(method.responseID, true, response);
|
|
62
63
|
} catch (error) {
|
|
63
|
-
return createResponseMessage(method.responseID, false,
|
|
64
|
+
return createResponseMessage(method.responseID, false, {
|
|
65
|
+
code: error.code,
|
|
66
|
+
error: error.message ?? error,
|
|
67
|
+
});
|
|
64
68
|
}
|
|
65
69
|
}
|
|
66
70
|
|
|
@@ -90,6 +94,9 @@ export const callAPI = async (message: CoreMessage) => {
|
|
|
90
94
|
method.setDevice?.(device);
|
|
91
95
|
|
|
92
96
|
device.on(DEVICE.PIN, onDevicePinHandler);
|
|
97
|
+
device.on(DEVICE.BUTTON, (d, code) => {
|
|
98
|
+
onDeviceButtonHandler(d, code);
|
|
99
|
+
});
|
|
93
100
|
|
|
94
101
|
try {
|
|
95
102
|
const inner = async (): Promise<void> => {
|
|
@@ -132,7 +139,13 @@ export const callAPI = async (message: CoreMessage) => {
|
|
|
132
139
|
Log.debug('Call API - Device Run: ', device);
|
|
133
140
|
const deviceRun = () => device.run(inner);
|
|
134
141
|
_callPromise = createDeferred(deviceRun);
|
|
135
|
-
|
|
142
|
+
|
|
143
|
+
try {
|
|
144
|
+
return await _callPromise.promise;
|
|
145
|
+
} catch (e) {
|
|
146
|
+
console.log('Device Run Error: ', e);
|
|
147
|
+
return createResponseMessage(method.responseID, false, e.message);
|
|
148
|
+
}
|
|
136
149
|
} catch (error) {
|
|
137
150
|
messageResponse = createResponseMessage(method.responseID, false, error);
|
|
138
151
|
_callPromise?.reject(ERRORS.TypedError('Call_API', error));
|
|
@@ -144,6 +157,10 @@ export const callAPI = async (message: CoreMessage) => {
|
|
|
144
157
|
method.dispose();
|
|
145
158
|
}
|
|
146
159
|
}
|
|
160
|
+
|
|
161
|
+
closePopup();
|
|
162
|
+
|
|
163
|
+
cleanup();
|
|
147
164
|
// TODO: 方法执行后,检查队列内是否有等待调用的 API,依次调用
|
|
148
165
|
}
|
|
149
166
|
};
|
|
@@ -203,6 +220,18 @@ function initDeviceForBle(method: BaseMethod) {
|
|
|
203
220
|
return device;
|
|
204
221
|
}
|
|
205
222
|
|
|
223
|
+
const cleanup = () => {
|
|
224
|
+
_uiPromises = [];
|
|
225
|
+
Log.debug('Cleanup...');
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Force close popup
|
|
230
|
+
*/
|
|
231
|
+
const closePopup = () => {
|
|
232
|
+
postMessage(createUiMessage(UI_REQUEST.CLOSE_UI_WINDOW));
|
|
233
|
+
};
|
|
234
|
+
|
|
206
235
|
const onDevicePinHandler = async (...[device, type, callback]: DeviceEvents['pin']) => {
|
|
207
236
|
console.log('onDevicePinHandler');
|
|
208
237
|
// create ui promise
|
|
@@ -220,6 +249,11 @@ const onDevicePinHandler = async (...[device, type, callback]: DeviceEvents['pin
|
|
|
220
249
|
callback(null, uiResp.payload);
|
|
221
250
|
};
|
|
222
251
|
|
|
252
|
+
const onDeviceButtonHandler = (...[device, request]: [...DeviceEvents['button']]) => {
|
|
253
|
+
postMessage(createDeviceMessage(DEVICE.BUTTON, { ...request, device: device.toMessageObject() }));
|
|
254
|
+
postMessage(createUiMessage(UI_REQUEST.REQUEST_BUTTON, { device: device.toMessageObject() }));
|
|
255
|
+
};
|
|
256
|
+
|
|
223
257
|
/**
|
|
224
258
|
* Emit message to listener (parent).
|
|
225
259
|
* Clear method reference from _callMethods
|
|
@@ -257,6 +291,12 @@ export default class Core extends EventEmitter {
|
|
|
257
291
|
break;
|
|
258
292
|
}
|
|
259
293
|
|
|
294
|
+
case UI_REQUEST.BLUETOOTH_PERMISSION:
|
|
295
|
+
case UI_REQUEST.LOCATION_PERMISSION: {
|
|
296
|
+
postMessage(message);
|
|
297
|
+
break;
|
|
298
|
+
}
|
|
299
|
+
|
|
260
300
|
case IFRAME.CALL: {
|
|
261
301
|
const response = await callAPI(message);
|
|
262
302
|
return response;
|
package/src/events/core.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Unsuccessful } from '../types/params';
|
|
2
2
|
import { IFrameCallMessage } from './call';
|
|
3
|
+
import { DeviceEventMessage } from './device';
|
|
3
4
|
import { IFrameEventMessage } from './iframe';
|
|
4
5
|
import { UiEventMessage } from './ui-request';
|
|
5
6
|
import { UiResponseMessage } from './ui-response';
|
|
@@ -9,7 +10,13 @@ export const CORE_EVENT = 'CORE_EVENT';
|
|
|
9
10
|
export type CoreMessage = {
|
|
10
11
|
id?: string;
|
|
11
12
|
success?: true | false;
|
|
12
|
-
} & (
|
|
13
|
+
} & (
|
|
14
|
+
| IFrameEventMessage
|
|
15
|
+
| IFrameCallMessage
|
|
16
|
+
| UiResponseMessage
|
|
17
|
+
| UiEventMessage
|
|
18
|
+
| DeviceEventMessage
|
|
19
|
+
);
|
|
13
20
|
|
|
14
21
|
export type PostMessageEvent = MessageEvent<any>;
|
|
15
22
|
|
package/src/events/device.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import type { PROTO } from '../constants';
|
|
2
|
+
import type { KnownDevice as Device } from '../types/device';
|
|
3
|
+
import { MessageFactoryFn } from './utils';
|
|
2
4
|
|
|
5
|
+
export const DEVICE_EVENT = 'DEVICE_EVENT';
|
|
3
6
|
export const DEVICE = {
|
|
4
7
|
// device list events
|
|
5
8
|
CONNECT: 'device-connect',
|
|
@@ -26,3 +29,27 @@ export const DEVICE = {
|
|
|
26
29
|
export interface DeviceButtonRequestPayload extends Omit<PROTO.ButtonRequest, 'code'> {
|
|
27
30
|
code?: PROTO.ButtonRequest['code'] | 'ButtonRequest_FirmwareUpdate';
|
|
28
31
|
}
|
|
32
|
+
|
|
33
|
+
export interface DeviceButtonRequest {
|
|
34
|
+
type: typeof DEVICE.BUTTON;
|
|
35
|
+
payload: DeviceButtonRequestPayload & { device: Device | null };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export type DeviceEvent = DeviceButtonRequest;
|
|
39
|
+
|
|
40
|
+
export type DeviceEventMessage = DeviceEvent & { event: typeof DEVICE_EVENT };
|
|
41
|
+
|
|
42
|
+
export type DeviceEventListenerFn = (
|
|
43
|
+
type: typeof DEVICE_EVENT,
|
|
44
|
+
cb: (event: DeviceEventMessage) => void
|
|
45
|
+
) => void;
|
|
46
|
+
|
|
47
|
+
export const createDeviceMessage: MessageFactoryFn<typeof DEVICE_EVENT, DeviceEvent> = (
|
|
48
|
+
type,
|
|
49
|
+
payload
|
|
50
|
+
) =>
|
|
51
|
+
({
|
|
52
|
+
event: DEVICE_EVENT,
|
|
53
|
+
type,
|
|
54
|
+
payload,
|
|
55
|
+
} as any);
|
package/src/events/ui-request.ts
CHANGED
|
@@ -1,13 +1,29 @@
|
|
|
1
1
|
import type { PROTO } from '../constants';
|
|
2
2
|
import type { Device } from '../types';
|
|
3
|
+
import type { DeviceButtonRequest } from './device';
|
|
3
4
|
import type { MessageFactoryFn } from './utils';
|
|
4
5
|
|
|
5
6
|
export const UI_EVENT = 'UI_EVENT';
|
|
6
7
|
|
|
7
8
|
export const UI_REQUEST = {
|
|
8
9
|
REQUEST_PIN: 'ui-request_pin',
|
|
10
|
+
INVALID_PIN: 'ui-invalid_pin',
|
|
11
|
+
REQUEST_BUTTON: 'ui-button',
|
|
12
|
+
|
|
13
|
+
CLOSE_UI_WINDOW: 'ui-close_window',
|
|
14
|
+
|
|
15
|
+
BLUETOOTH_PERMISSION: 'ui-bluetooth_permission',
|
|
16
|
+
LOCATION_PERMISSION: 'ui-location_permission',
|
|
9
17
|
} as const;
|
|
10
18
|
|
|
19
|
+
export interface UiRequestWithoutPayload {
|
|
20
|
+
type:
|
|
21
|
+
| typeof UI_REQUEST.CLOSE_UI_WINDOW
|
|
22
|
+
| typeof UI_REQUEST.BLUETOOTH_PERMISSION
|
|
23
|
+
| typeof UI_REQUEST.LOCATION_PERMISSION;
|
|
24
|
+
payload?: typeof undefined;
|
|
25
|
+
}
|
|
26
|
+
|
|
11
27
|
export type UiRequestDeviceAction = {
|
|
12
28
|
type: typeof UI_REQUEST.REQUEST_PIN;
|
|
13
29
|
payload: {
|
|
@@ -16,7 +32,12 @@ export type UiRequestDeviceAction = {
|
|
|
16
32
|
};
|
|
17
33
|
};
|
|
18
34
|
|
|
19
|
-
export
|
|
35
|
+
export interface UiRequestButton {
|
|
36
|
+
type: typeof UI_REQUEST.REQUEST_BUTTON;
|
|
37
|
+
payload: DeviceButtonRequest['payload'];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export type UiEvent = UiRequestWithoutPayload | UiRequestDeviceAction | UiRequestButton;
|
|
20
41
|
|
|
21
42
|
export type UiEventMessage = UiEvent & { event: typeof UI_EVENT };
|
|
22
43
|
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
TxInput as OrigTxInput,
|
|
3
3
|
PrevInput,
|
|
4
|
-
Success,
|
|
5
4
|
TxOutputBinType,
|
|
6
5
|
TxOutputType,
|
|
7
6
|
TxInputType,
|
|
@@ -95,4 +94,4 @@ export type BTCSignTransactionParams = {
|
|
|
95
94
|
export declare function btcSignTransaction(
|
|
96
95
|
connectId: string,
|
|
97
96
|
params: CommonParams & BTCSignTransactionParams
|
|
98
|
-
): Response<
|
|
97
|
+
): Response<SignedTransaction>;
|
package/src/types/api/export.ts
CHANGED
|
@@ -2,6 +2,14 @@ export type { BTCAddress, BTCGetAddressParams } from './btcGetAddress';
|
|
|
2
2
|
export type { BTCPublicKey, BTCGetPublicKeyParams } from './btcGetPublicKey';
|
|
3
3
|
export type { BTCSignMessageParams } from './btcSignMessage';
|
|
4
4
|
export type { BTCVerifyMessageParams } from './btcVerifyMessage';
|
|
5
|
+
export type {
|
|
6
|
+
RefTransaction,
|
|
7
|
+
AccountAddress,
|
|
8
|
+
AccountAddresses,
|
|
9
|
+
BTCSignTransactionParams,
|
|
10
|
+
SignedTransaction,
|
|
11
|
+
TransactionOptions,
|
|
12
|
+
} from './btcSignTransaction';
|
|
5
13
|
|
|
6
14
|
export type { DeviceChangePinParams } from './deviceChangePin';
|
|
7
15
|
export type { DeviceFlagsParams } from './deviceFlags';
|
package/src/utils/index.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { initLog, enableLog } from './logger';
|
|
|
3
3
|
export * from './assets';
|
|
4
4
|
export * from './versionUtils';
|
|
5
5
|
export * from './deferred';
|
|
6
|
-
export
|
|
6
|
+
export { getDeviceType, getDeviceUUID, getDeviceLabel } from './deviceFeaturesUtils';
|
|
7
|
+
export { getHDPath, getScriptType } from '../api/helpers/pathUtils';
|
|
7
8
|
|
|
8
9
|
export { initLog, enableLog };
|