@ukeyfe/hardware-transport 1.1.13
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/.eslintrc +24 -0
- package/README.md +29 -0
- package/__tests__/build-receive.test.js +117 -0
- package/__tests__/decode-features.test.js +72 -0
- package/__tests__/encode-decode-basic.test.js +272 -0
- package/__tests__/encode-decode.test.js +532 -0
- package/__tests__/messages.test.js +86 -0
- package/dist/constants.d.ts +6 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/index.d.ts +5203 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +942 -0
- package/dist/serialization/index.d.ts +6 -0
- package/dist/serialization/index.d.ts.map +1 -0
- package/dist/serialization/protobuf/decode.d.ts +6 -0
- package/dist/serialization/protobuf/decode.d.ts.map +1 -0
- package/dist/serialization/protobuf/encode.d.ts +5 -0
- package/dist/serialization/protobuf/encode.d.ts.map +1 -0
- package/dist/serialization/protobuf/index.d.ts +4 -0
- package/dist/serialization/protobuf/index.d.ts.map +1 -0
- package/dist/serialization/protobuf/messages.d.ts +11 -0
- package/dist/serialization/protobuf/messages.d.ts.map +1 -0
- package/dist/serialization/protocol/decode.d.ts +11 -0
- package/dist/serialization/protocol/decode.d.ts.map +1 -0
- package/dist/serialization/protocol/encode.d.ts +11 -0
- package/dist/serialization/protocol/encode.d.ts.map +1 -0
- package/dist/serialization/protocol/index.d.ts +3 -0
- package/dist/serialization/protocol/index.d.ts.map +1 -0
- package/dist/serialization/receive.d.ts +8 -0
- package/dist/serialization/receive.d.ts.map +1 -0
- package/dist/serialization/send.d.ts +7 -0
- package/dist/serialization/send.d.ts.map +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/messages.d.ts +3762 -0
- package/dist/types/messages.d.ts.map +1 -0
- package/dist/types/transport.d.ts +62 -0
- package/dist/types/transport.d.ts.map +1 -0
- package/dist/utils/highlevel-checks.d.ts +10 -0
- package/dist/utils/highlevel-checks.d.ts.map +1 -0
- package/dist/utils/logBlockCommand.d.ts +2 -0
- package/dist/utils/logBlockCommand.d.ts.map +1 -0
- package/dist/utils/protobuf.d.ts +2 -0
- package/dist/utils/protobuf.d.ts.map +1 -0
- package/jest.config.js +7 -0
- package/package.json +31 -0
- package/protocol.md +21 -0
- package/scripts/protobuf-build.sh +58 -0
- package/scripts/protobuf-patches/TxAck.js +44 -0
- package/scripts/protobuf-patches/TxInputType.js +49 -0
- package/scripts/protobuf-patches/TxOutputType.js +50 -0
- package/scripts/protobuf-patches/index.js +274 -0
- package/scripts/protobuf-types.js +283 -0
- package/src/constants.ts +8 -0
- package/src/index.ts +41 -0
- package/src/serialization/index.ts +8 -0
- package/src/serialization/protobuf/decode.ts +95 -0
- package/src/serialization/protobuf/encode.ts +79 -0
- package/src/serialization/protobuf/index.ts +3 -0
- package/src/serialization/protobuf/messages.ts +37 -0
- package/src/serialization/protocol/decode.ts +48 -0
- package/src/serialization/protocol/encode.ts +59 -0
- package/src/serialization/protocol/index.ts +2 -0
- package/src/serialization/receive.ts +18 -0
- package/src/serialization/send.ts +56 -0
- package/src/types/index.ts +2 -0
- package/src/types/messages.ts +4864 -0
- package/src/types/transport.ts +71 -0
- package/src/utils/highlevel-checks.ts +88 -0
- package/src/utils/logBlockCommand.ts +1 -0
- package/src/utils/protobuf.ts +24 -0
- package/tsconfig.json +11 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type EventEmitter from 'events';
|
|
2
|
+
|
|
3
|
+
export type UKeyUsbDeviceInfo = {
|
|
4
|
+
path: string;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export type UKeyDeviceInfoWithSession = UKeyUsbDeviceInfo & {
|
|
8
|
+
session?: string | null;
|
|
9
|
+
debugSession?: string | null;
|
|
10
|
+
debug: boolean;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export type UKeyMobileDeviceInfo = {
|
|
14
|
+
id: string;
|
|
15
|
+
name: string | null;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export type UKeyDeviceInfo = UKeyDeviceInfoWithSession & UKeyMobileDeviceInfo;
|
|
19
|
+
|
|
20
|
+
export type AcquireInput = {
|
|
21
|
+
path?: string;
|
|
22
|
+
previous?: string | null;
|
|
23
|
+
uuid?: string;
|
|
24
|
+
forceCleanRunPromise?: boolean;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export type MessageFromUKey = { type: string; message: Record<string, any> };
|
|
28
|
+
|
|
29
|
+
type ITransportInitFn = (
|
|
30
|
+
logger?: any,
|
|
31
|
+
emitter?: EventEmitter,
|
|
32
|
+
plugin?: LowlevelTransportSharedPlugin
|
|
33
|
+
) => Promise<string>;
|
|
34
|
+
|
|
35
|
+
export type Transport = {
|
|
36
|
+
enumerate(): Promise<Array<UKeyDeviceInfo>>;
|
|
37
|
+
listen(old?: Array<UKeyDeviceInfo>): Promise<Array<UKeyDeviceInfo>>;
|
|
38
|
+
acquire(input: AcquireInput): Promise<string>;
|
|
39
|
+
release(session: string, onclose: boolean): Promise<void>;
|
|
40
|
+
configure(signedData: JSON | string): Promise<void>;
|
|
41
|
+
call(session: string, name: string, data: Record<string, any>): Promise<MessageFromUKey>;
|
|
42
|
+
post(session: string, name: string, data: Record<string, any>): Promise<void>;
|
|
43
|
+
read(session: string): Promise<MessageFromUKey>;
|
|
44
|
+
cancel(): Promise<void>;
|
|
45
|
+
|
|
46
|
+
// web-usb, web-bluetooth request device
|
|
47
|
+
promptDeviceAccess?: () => Promise<USBDevice | BluetoothDevice | null>;
|
|
48
|
+
|
|
49
|
+
// resolves when the transport can be used; rejects when it cannot
|
|
50
|
+
init: ITransportInitFn;
|
|
51
|
+
stop(): void;
|
|
52
|
+
|
|
53
|
+
configured: boolean;
|
|
54
|
+
version: string;
|
|
55
|
+
name: string;
|
|
56
|
+
activeName?: string;
|
|
57
|
+
|
|
58
|
+
isOutdated: boolean;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export type LowLevelDevice = { id: string; name: string };
|
|
62
|
+
export type LowlevelTransportSharedPlugin = {
|
|
63
|
+
enumerate: () => Promise<LowLevelDevice[]>;
|
|
64
|
+
send: (uuid: string, data: string) => Promise<void>;
|
|
65
|
+
receive: () => Promise<string>;
|
|
66
|
+
connect: (uuid: string) => Promise<void>;
|
|
67
|
+
disconnect: (uuid: string) => Promise<void>;
|
|
68
|
+
|
|
69
|
+
init: () => Promise<void>;
|
|
70
|
+
version: string;
|
|
71
|
+
};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// input checks for high-level transports
|
|
2
|
+
|
|
3
|
+
import type { UKeyDeviceInfoWithSession, MessageFromUKey } from '../types';
|
|
4
|
+
|
|
5
|
+
const ERROR = 'Wrong result type.';
|
|
6
|
+
|
|
7
|
+
export function info(res: any) {
|
|
8
|
+
if (typeof res !== 'object' || res == null) {
|
|
9
|
+
throw new Error('Wrong result type.');
|
|
10
|
+
}
|
|
11
|
+
const { version } = res;
|
|
12
|
+
if (typeof version !== 'string') {
|
|
13
|
+
throw new Error(ERROR);
|
|
14
|
+
}
|
|
15
|
+
const configured = !!res.configured;
|
|
16
|
+
return { version, configured };
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function version(version: any) {
|
|
20
|
+
if (typeof version !== 'string') {
|
|
21
|
+
throw new Error(ERROR);
|
|
22
|
+
}
|
|
23
|
+
return version.trim();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function convertSession(r: any) {
|
|
27
|
+
if (r == null) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
if (typeof r !== 'string') {
|
|
31
|
+
throw new Error(ERROR);
|
|
32
|
+
}
|
|
33
|
+
return r;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function devices(res: any): Array<UKeyDeviceInfoWithSession> {
|
|
37
|
+
if (typeof res !== 'object') {
|
|
38
|
+
throw new Error(ERROR);
|
|
39
|
+
}
|
|
40
|
+
if (!(res instanceof Array)) {
|
|
41
|
+
throw new Error(ERROR);
|
|
42
|
+
}
|
|
43
|
+
return res.map((o: any): UKeyDeviceInfoWithSession => {
|
|
44
|
+
if (typeof o !== 'object' || o == null) {
|
|
45
|
+
throw new Error(ERROR);
|
|
46
|
+
}
|
|
47
|
+
const { path } = o;
|
|
48
|
+
if (typeof path !== 'string') {
|
|
49
|
+
throw new Error(ERROR);
|
|
50
|
+
}
|
|
51
|
+
const pathS = path.toString();
|
|
52
|
+
return {
|
|
53
|
+
path: pathS,
|
|
54
|
+
session: convertSession(o.session),
|
|
55
|
+
debugSession: convertSession(o.debugSession),
|
|
56
|
+
// @ts-ignore
|
|
57
|
+
product: o.product,
|
|
58
|
+
vendor: o.vendor,
|
|
59
|
+
debug: !!o.debug,
|
|
60
|
+
};
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function acquire(res: any) {
|
|
65
|
+
if (typeof res !== 'object' || res == null) {
|
|
66
|
+
throw new Error(ERROR);
|
|
67
|
+
}
|
|
68
|
+
const { session } = res;
|
|
69
|
+
if (typeof session !== 'string' && typeof session !== 'number') {
|
|
70
|
+
throw new Error(ERROR);
|
|
71
|
+
}
|
|
72
|
+
return session.toString();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function call(res: any): MessageFromUKey {
|
|
76
|
+
if (typeof res !== 'object' || res == null) {
|
|
77
|
+
throw new Error(ERROR);
|
|
78
|
+
}
|
|
79
|
+
const { type } = res;
|
|
80
|
+
if (typeof type !== 'string') {
|
|
81
|
+
throw new Error(ERROR);
|
|
82
|
+
}
|
|
83
|
+
const { message } = res;
|
|
84
|
+
if (typeof message !== 'object' || message == null) {
|
|
85
|
+
throw new Error(ERROR);
|
|
86
|
+
}
|
|
87
|
+
return { type, message };
|
|
88
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const LogBlockCommand = new Set(['PassphraseAck', 'PinMatrixAck']);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const primitiveTypes = [
|
|
2
|
+
'bool',
|
|
3
|
+
'string',
|
|
4
|
+
'bytes',
|
|
5
|
+
'int32',
|
|
6
|
+
'int64',
|
|
7
|
+
'uint32',
|
|
8
|
+
'uint64',
|
|
9
|
+
'sint32',
|
|
10
|
+
'sint64',
|
|
11
|
+
'fixed32',
|
|
12
|
+
'fixed64',
|
|
13
|
+
'sfixed32',
|
|
14
|
+
'sfixed64',
|
|
15
|
+
'double',
|
|
16
|
+
'float',
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Determines whether given field is "primitive"
|
|
21
|
+
* bool, strings, uint32 => true
|
|
22
|
+
* HDNodeType => false
|
|
23
|
+
*/
|
|
24
|
+
export const isPrimitiveField = (field: any) => primitiveTypes.includes(field);
|