@onekeyfe/hd-core 1.2.8-alpha.111 → 1.2.8-alpha.113
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/__tests__/logBlockEvent.test.ts +0 -43
- package/__tests__/protocol-v2.test.ts +239 -0
- package/dist/api/FirmwareUpdateV4.d.ts +3 -0
- package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
- package/dist/api/index.d.ts +0 -2
- package/dist/api/index.d.ts.map +1 -1
- package/dist/events/logBlockEvent.d.ts.map +1 -1
- package/dist/index.d.ts +3 -36
- package/dist/index.js +156 -365
- package/dist/inject.d.ts.map +1 -1
- package/dist/types/api/export.d.ts +0 -2
- package/dist/types/api/export.d.ts.map +1 -1
- package/dist/types/api/index.d.ts +0 -4
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/utils/patch.d.ts +1 -1
- package/dist/utils/patch.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/api/FirmwareUpdateV4.ts +216 -51
- package/src/api/index.ts +0 -2
- package/src/data/messages/messages-protocol-v2.json +1 -138
- package/src/events/logBlockEvent.ts +2 -4
- package/src/inject.ts +0 -4
- package/src/types/api/export.ts +0 -2
- package/src/types/api/index.ts +0 -8
- package/__tests__/zcash-protobuf.test.ts +0 -141
- package/__tests__/zcash-sign-pczt.test.ts +0 -387
- package/dist/api/zcash/ZcashGetAddress.d.ts +0 -12
- package/dist/api/zcash/ZcashGetAddress.d.ts.map +0 -1
- package/dist/api/zcash/ZcashSignPczt.d.ts +0 -16
- package/dist/api/zcash/ZcashSignPczt.d.ts.map +0 -1
- package/dist/types/api/zcashGetAddress.d.ts +0 -22
- package/dist/types/api/zcashGetAddress.d.ts.map +0 -1
- package/dist/types/api/zcashSignPczt.d.ts +0 -9
- package/dist/types/api/zcashSignPczt.d.ts.map +0 -1
- package/src/api/zcash/ZcashGetAddress.ts +0 -121
- package/src/api/zcash/ZcashSignPczt.ts +0 -155
- package/src/types/api/zcashGetAddress.ts +0 -36
- package/src/types/api/zcashSignPczt.ts +0 -18
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import { ZcashAddressScope, ZcashAddressType } from '@onekeyfe/hd-transport';
|
|
2
|
-
|
|
3
|
-
import { BaseMethod } from '../BaseMethod';
|
|
4
|
-
import { serializedPath, toHardened, validatePath } from '../helpers/pathUtils';
|
|
5
|
-
import { invalidParameter, validateParams, validateResult } from '../helpers/paramsValidator';
|
|
6
|
-
import { UI_REQUEST } from '../../constants/ui-request';
|
|
7
|
-
|
|
8
|
-
import type { ZcashGetAddress as HardwareZcashGetAddress } from '@onekeyfe/hd-transport';
|
|
9
|
-
import type { ZcashGetAddressParams, ZcashAddress } from '../../types/api/zcashGetAddress';
|
|
10
|
-
import type { DeviceFirmwareRange } from '../../types';
|
|
11
|
-
|
|
12
|
-
export default class ZcashGetAddress extends BaseMethod<HardwareZcashGetAddress[]> {
|
|
13
|
-
hasBundle = false;
|
|
14
|
-
|
|
15
|
-
getSupportedProtocols() {
|
|
16
|
-
return ['V2'] as const;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
init() {
|
|
20
|
-
this.checkDeviceId = true;
|
|
21
|
-
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
22
|
-
this.strictCheckDeviceSupport = true;
|
|
23
|
-
|
|
24
|
-
this.hasBundle = !!this.payload?.bundle;
|
|
25
|
-
const payload = this.hasBundle ? this.payload : { bundle: [this.payload] };
|
|
26
|
-
|
|
27
|
-
validateParams(payload, [{ name: 'bundle', type: 'array' }]);
|
|
28
|
-
|
|
29
|
-
this.params = [];
|
|
30
|
-
payload.bundle.forEach((batch: ZcashGetAddressParams) => {
|
|
31
|
-
// ZIP-32 account path: m/32'/133'/account'
|
|
32
|
-
const addressN = validatePath(batch.path, 3);
|
|
33
|
-
if (
|
|
34
|
-
addressN.length !== 3 ||
|
|
35
|
-
addressN[0] !== toHardened(32) ||
|
|
36
|
-
addressN[1] !== toHardened(133) ||
|
|
37
|
-
addressN[2] < toHardened(0) ||
|
|
38
|
-
addressN[2] > 0xffffffff
|
|
39
|
-
) {
|
|
40
|
-
throw invalidParameter("Zcash requires a ZIP-32 account path m/32'/133'/account'");
|
|
41
|
-
}
|
|
42
|
-
const addressType = batch.addressType ?? ZcashAddressType.UNIFIED_ORCHARD_P2PKH;
|
|
43
|
-
const scope = batch.scope ?? ZcashAddressScope.EXTERNAL;
|
|
44
|
-
const diversifierIndex = batch.diversifierIndex ?? 0;
|
|
45
|
-
if (
|
|
46
|
-
![
|
|
47
|
-
ZcashAddressType.UNIFIED_ORCHARD_P2PKH,
|
|
48
|
-
ZcashAddressType.TRANSPARENT_P2PKH,
|
|
49
|
-
ZcashAddressType.UNIFIED_ORCHARD,
|
|
50
|
-
].includes(addressType) ||
|
|
51
|
-
![ZcashAddressScope.EXTERNAL, ZcashAddressScope.INTERNAL].includes(scope)
|
|
52
|
-
) {
|
|
53
|
-
throw invalidParameter('Invalid Zcash address type or scope');
|
|
54
|
-
}
|
|
55
|
-
const maxIndex = addressType === ZcashAddressType.UNIFIED_ORCHARD ? 0xffffffff : 0x7fffffff;
|
|
56
|
-
if (
|
|
57
|
-
!Number.isSafeInteger(diversifierIndex) ||
|
|
58
|
-
diversifierIndex < 0 ||
|
|
59
|
-
diversifierIndex > maxIndex
|
|
60
|
-
) {
|
|
61
|
-
throw invalidParameter('Invalid Zcash diversifier index');
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
validateParams(batch, [
|
|
65
|
-
{ name: 'path', required: true },
|
|
66
|
-
{ name: 'showOnOneKey', type: 'boolean' },
|
|
67
|
-
{ name: 'includeUfvk', type: 'boolean' },
|
|
68
|
-
{ name: 'includeSeedFingerprint', type: 'boolean' },
|
|
69
|
-
]);
|
|
70
|
-
|
|
71
|
-
this.params.push({
|
|
72
|
-
address_n: addressN,
|
|
73
|
-
address_type: addressType,
|
|
74
|
-
scope,
|
|
75
|
-
diversifier_index: diversifierIndex,
|
|
76
|
-
show_display: batch.showOnOneKey ?? true,
|
|
77
|
-
include_ufvk: batch.includeUfvk ?? false,
|
|
78
|
-
include_seed_fingerprint: batch.includeSeedFingerprint ?? false,
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
getVersionRange(): DeviceFirmwareRange {
|
|
84
|
-
return {
|
|
85
|
-
model_pro2: {
|
|
86
|
-
min: '0.0.0',
|
|
87
|
-
},
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
async run() {
|
|
92
|
-
const responses: ZcashAddress[] = [];
|
|
93
|
-
|
|
94
|
-
for (let i = 0; i < this.params.length; i++) {
|
|
95
|
-
const param = this.params[i];
|
|
96
|
-
|
|
97
|
-
const res = await this.device.commands.typedCall('ZcashGetAddress', 'ZcashAddress', {
|
|
98
|
-
...param,
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
const path = serializedPath(param.address_n);
|
|
102
|
-
responses.push({
|
|
103
|
-
path,
|
|
104
|
-
address: res.message.address,
|
|
105
|
-
ufvk: res.message.ufvk,
|
|
106
|
-
seedFingerprint: res.message.seed_fingerprint,
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
this.postPreviousAddressMessage({
|
|
110
|
-
address: res.message.address,
|
|
111
|
-
path,
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
validateResult(responses, ['address'], {
|
|
116
|
-
expectedLength: this.params.length,
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
return Promise.resolve(this.hasBundle ? responses : responses[0]);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
import { bytesToHex } from '@noble/hashes/utils';
|
|
2
|
-
import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
3
|
-
|
|
4
|
-
import { BaseMethod } from '../BaseMethod';
|
|
5
|
-
import { invalidParameter, validateParams } from '../helpers/paramsValidator';
|
|
6
|
-
import { stripHexPrefix } from '../helpers/hexUtils';
|
|
7
|
-
import { UI_REQUEST } from '../../constants/ui-request';
|
|
8
|
-
|
|
9
|
-
import type { ZcashSignPczt as HardwareZcashSignPczt } from '@onekeyfe/hd-transport';
|
|
10
|
-
import type { TypedCall, TypedResponseMessage } from '../../device/DeviceCommands';
|
|
11
|
-
import type { ZcashSignedPczt } from '../../types/api/zcashSignPczt';
|
|
12
|
-
import type { DeviceFirmwareRange } from '../../types';
|
|
13
|
-
|
|
14
|
-
const CHUNK_BYTE_SIZE = 1024;
|
|
15
|
-
// Host memory sanity bound on the device-announced length, not a device limit.
|
|
16
|
-
const SIGNED_PCZT_SANITY_MAX_BYTES = 16 * 1024 * 1024;
|
|
17
|
-
|
|
18
|
-
export default class ZcashSignPczt extends BaseMethod<HardwareZcashSignPczt> {
|
|
19
|
-
pczt: Buffer = Buffer.alloc(0);
|
|
20
|
-
|
|
21
|
-
getSupportedProtocols() {
|
|
22
|
-
return ['V2'] as const;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
init() {
|
|
26
|
-
this.checkDeviceId = true;
|
|
27
|
-
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
28
|
-
this.strictCheckDeviceSupport = true;
|
|
29
|
-
|
|
30
|
-
validateParams(this.payload, [{ name: 'pczt', type: 'hexString', required: true }]);
|
|
31
|
-
|
|
32
|
-
// Reject odd-length hex instead of left-padding it, which would shift every nibble.
|
|
33
|
-
const pcztHex = stripHexPrefix(this.payload.pczt);
|
|
34
|
-
if (pcztHex.length % 2 !== 0) {
|
|
35
|
-
throw invalidParameter('pczt hex must have an even length');
|
|
36
|
-
}
|
|
37
|
-
this.pczt = Buffer.from(pcztHex, 'hex');
|
|
38
|
-
if (this.pczt.length === 0) {
|
|
39
|
-
throw invalidParameter('pczt is empty');
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
this.params = {
|
|
43
|
-
pczt_length: this.pczt.length,
|
|
44
|
-
pczt_initial_chunk: bytesToHex(this.pczt.subarray(0, CHUNK_BYTE_SIZE)),
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
getVersionRange(): DeviceFirmwareRange {
|
|
49
|
-
return {
|
|
50
|
-
model_pro2: {
|
|
51
|
-
min: '0.0.0',
|
|
52
|
-
},
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// Upload: the device decides every chunk length via ZcashPcztChunkRequest and
|
|
57
|
-
// the host must answer with exactly that many bytes.
|
|
58
|
-
uploadPczt = async (
|
|
59
|
-
typedCall: TypedCall,
|
|
60
|
-
res: TypedResponseMessage<'ZcashSignedPczt'> | TypedResponseMessage<'ZcashPcztChunkRequest'>,
|
|
61
|
-
offset: number
|
|
62
|
-
): Promise<TypedResponseMessage<'ZcashSignedPczt'>> => {
|
|
63
|
-
if (res.type === 'ZcashSignedPczt') {
|
|
64
|
-
if (offset !== this.pczt.length) {
|
|
65
|
-
throw ERRORS.TypedError(
|
|
66
|
-
HardwareErrorCode.ResponseUnexpectTypeError,
|
|
67
|
-
'device completed signing before receiving the whole pczt'
|
|
68
|
-
);
|
|
69
|
-
}
|
|
70
|
-
return res;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
const { chunk_length: chunkLength } = res.message;
|
|
74
|
-
if (
|
|
75
|
-
!Number.isSafeInteger(chunkLength) ||
|
|
76
|
-
chunkLength <= 0 ||
|
|
77
|
-
offset + chunkLength > this.pczt.length
|
|
78
|
-
) {
|
|
79
|
-
throw ERRORS.TypedError(
|
|
80
|
-
HardwareErrorCode.ResponseUnexpectTypeError,
|
|
81
|
-
`device requested ${chunkLength} bytes at offset ${offset} of ${this.pczt.length}`
|
|
82
|
-
);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
const chunk = this.pczt.subarray(offset, offset + chunkLength);
|
|
86
|
-
const next = await typedCall(
|
|
87
|
-
'ZcashPcztChunkAck',
|
|
88
|
-
['ZcashSignedPczt', 'ZcashPcztChunkRequest'],
|
|
89
|
-
{
|
|
90
|
-
data_chunk: bytesToHex(chunk),
|
|
91
|
-
}
|
|
92
|
-
);
|
|
93
|
-
|
|
94
|
-
return this.uploadPczt(typedCall, next, offset + chunkLength);
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
// Download: the host decides chunk lengths via ZcashSignedPcztChunkRequest
|
|
98
|
-
// until the announced pczt_length has been received.
|
|
99
|
-
downloadSignedPczt = async (
|
|
100
|
-
typedCall: TypedCall,
|
|
101
|
-
res: TypedResponseMessage<'ZcashSignedPczt'>
|
|
102
|
-
): Promise<Buffer> => {
|
|
103
|
-
const { pczt_length: total, pczt_initial_chunk: initial } = res.message;
|
|
104
|
-
if (!Number.isSafeInteger(total) || total <= 0 || total > SIGNED_PCZT_SANITY_MAX_BYTES) {
|
|
105
|
-
throw ERRORS.TypedError(
|
|
106
|
-
HardwareErrorCode.ResponseUnexpectTypeError,
|
|
107
|
-
`device announced invalid signed pczt length ${total}`
|
|
108
|
-
);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
const parts: Buffer[] = [Buffer.from(initial ?? '', 'hex')];
|
|
112
|
-
let received = parts[0].length;
|
|
113
|
-
if (received > total) {
|
|
114
|
-
throw ERRORS.TypedError(
|
|
115
|
-
HardwareErrorCode.ResponseUnexpectTypeError,
|
|
116
|
-
'device returned more initial pczt bytes than announced'
|
|
117
|
-
);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
while (received < total) {
|
|
121
|
-
const chunkLength = Math.min(CHUNK_BYTE_SIZE, total - received);
|
|
122
|
-
const ack = await typedCall('ZcashSignedPcztChunkRequest', 'ZcashPcztChunkAck', {
|
|
123
|
-
chunk_length: chunkLength,
|
|
124
|
-
});
|
|
125
|
-
const chunk = Buffer.from(ack.message.data_chunk ?? '', 'hex');
|
|
126
|
-
if (chunk.length !== chunkLength) {
|
|
127
|
-
throw ERRORS.TypedError(
|
|
128
|
-
HardwareErrorCode.ResponseUnexpectTypeError,
|
|
129
|
-
`device returned ${chunk.length} of ${chunkLength} requested bytes at offset ${received} of ${total}`
|
|
130
|
-
);
|
|
131
|
-
}
|
|
132
|
-
parts.push(chunk);
|
|
133
|
-
received += chunk.length;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
return Buffer.concat(parts);
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
async run(): Promise<ZcashSignedPczt> {
|
|
140
|
-
const typedCall = this.device.getCommands().typedCall.bind(this.device.getCommands());
|
|
141
|
-
|
|
142
|
-
const first = await typedCall('ZcashSignPczt', ['ZcashSignedPczt', 'ZcashPcztChunkRequest'], {
|
|
143
|
-
...this.params,
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
const signed = await this.uploadPczt(
|
|
147
|
-
typedCall,
|
|
148
|
-
first,
|
|
149
|
-
Math.min(CHUNK_BYTE_SIZE, this.pczt.length)
|
|
150
|
-
);
|
|
151
|
-
const pczt = await this.downloadSignedPczt(typedCall, signed);
|
|
152
|
-
|
|
153
|
-
return { pczt: bytesToHex(pczt) };
|
|
154
|
-
}
|
|
155
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import type { ZcashAddressScope, ZcashAddressType } from '@onekeyfe/hd-transport';
|
|
2
|
-
|
|
3
|
-
import type { CommonParams, Response } from '../params';
|
|
4
|
-
|
|
5
|
-
export type ZcashAddress = {
|
|
6
|
-
path: string;
|
|
7
|
-
// ZIP-316 unified address or transparent P2PKH address
|
|
8
|
-
address: string;
|
|
9
|
-
// ZIP-316 unified full viewing key, present when includeUfvk was requested
|
|
10
|
-
ufvk?: string;
|
|
11
|
-
// ZIP-32 seed fingerprint (hex), present when includeSeedFingerprint was requested
|
|
12
|
-
seedFingerprint?: string;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export type ZcashGetAddressParams = {
|
|
16
|
-
// ZIP-32 account path, m/32'/133'/account'
|
|
17
|
-
path: string | number[];
|
|
18
|
-
showOnOneKey?: boolean;
|
|
19
|
-
diversifierIndex?: number;
|
|
20
|
-
addressType?: ZcashAddressType;
|
|
21
|
-
scope?: ZcashAddressScope;
|
|
22
|
-
includeUfvk?: boolean;
|
|
23
|
-
includeSeedFingerprint?: boolean;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
export declare function zcashGetAddress(
|
|
27
|
-
connectId: string,
|
|
28
|
-
deviceId: string,
|
|
29
|
-
params: CommonParams & ZcashGetAddressParams
|
|
30
|
-
): Response<ZcashAddress>;
|
|
31
|
-
|
|
32
|
-
export declare function zcashGetAddress(
|
|
33
|
-
connectId: string,
|
|
34
|
-
deviceId: string,
|
|
35
|
-
params: CommonParams & { bundle?: ZcashGetAddressParams[] }
|
|
36
|
-
): Response<Array<ZcashAddress>>;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { CommonParams, Response } from '../params';
|
|
2
|
-
|
|
3
|
-
export type ZcashSignPcztParams = {
|
|
4
|
-
// Unproved PCZT (v2, tx v6) as hex; the device signs it and returns a
|
|
5
|
-
// redacted copy with signatures filled in.
|
|
6
|
-
pczt: string;
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
export type ZcashSignedPczt = {
|
|
10
|
-
// Signed, redacted PCZT as hex
|
|
11
|
-
pczt: string;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export declare function zcashSignPczt(
|
|
15
|
-
connectId: string,
|
|
16
|
-
deviceId: string,
|
|
17
|
-
params: CommonParams & ZcashSignPcztParams
|
|
18
|
-
): Response<ZcashSignedPczt>;
|