@ohos-ports/trezor-device-authenticity 1.1.2-beta.1

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.
Files changed (40) hide show
  1. package/README.md +7 -0
  2. package/lib/config/deviceAuthenticityBlacklistConfig.d.ts +3 -0
  3. package/lib/config/deviceAuthenticityBlacklistConfig.js +14 -0
  4. package/lib/config/deviceAuthenticityBlacklistConfigTypes.d.ts +11 -0
  5. package/lib/config/deviceAuthenticityBlacklistConfigTypes.js +15 -0
  6. package/lib/config/deviceAuthenticityConfig.d.ts +3 -0
  7. package/lib/config/deviceAuthenticityConfig.js +36 -0
  8. package/lib/config/deviceAuthenticityConfigTypes.d.ts +47 -0
  9. package/lib/config/deviceAuthenticityConfigTypes.js +21 -0
  10. package/lib/index.d.ts +9 -0
  11. package/lib/index.js +68 -0
  12. package/lib/tsconfig.lib.tsbuildinfo +1 -0
  13. package/lib/types.d.ts +27 -0
  14. package/lib/types.js +6 -0
  15. package/lib/utils.d.ts +17 -0
  16. package/lib/utils.js +38 -0
  17. package/lib/verifyAuthenticityProof.d.ts +4 -0
  18. package/lib/verifyAuthenticityProof.js +171 -0
  19. package/lib/x509certificate.d.ts +93 -0
  20. package/lib/x509certificate.js +277 -0
  21. package/libESM/config/deviceAuthenticityBlacklistConfig.d.ts +3 -0
  22. package/libESM/config/deviceAuthenticityBlacklistConfig.js +8 -0
  23. package/libESM/config/deviceAuthenticityBlacklistConfigTypes.d.ts +11 -0
  24. package/libESM/config/deviceAuthenticityBlacklistConfigTypes.js +9 -0
  25. package/libESM/config/deviceAuthenticityConfig.d.ts +3 -0
  26. package/libESM/config/deviceAuthenticityConfig.js +30 -0
  27. package/libESM/config/deviceAuthenticityConfigTypes.d.ts +47 -0
  28. package/libESM/config/deviceAuthenticityConfigTypes.js +15 -0
  29. package/libESM/index.d.ts +9 -0
  30. package/libESM/index.js +8 -0
  31. package/libESM/tsconfig.libESM.tsbuildinfo +1 -0
  32. package/libESM/types.d.ts +27 -0
  33. package/libESM/types.js +1 -0
  34. package/libESM/utils.d.ts +17 -0
  35. package/libESM/utils.js +28 -0
  36. package/libESM/verifyAuthenticityProof.d.ts +4 -0
  37. package/libESM/verifyAuthenticityProof.js +162 -0
  38. package/libESM/x509certificate.d.ts +93 -0
  39. package/libESM/x509certificate.js +269 -0
  40. package/package.json +62 -0
@@ -0,0 +1,277 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.parseCertificate = exports.parseName = void 0;
7
+ const parseOidToAlgorithmName = oid => {
8
+ if (oid === '1.2.840.10045.4.3.2') return 'P-256';
9
+ if (oid === '1.3.101.112') return 'Ed25519';
10
+ return 'unknown';
11
+ };
12
+ const derToAsn1 = byteArray => {
13
+ let position = 0;
14
+ function getTag() {
15
+ let tag = byteArray[0] & 0x1f;
16
+ position += 1;
17
+ if (tag === 0x1f) {
18
+ tag = 0;
19
+ while (byteArray[position] >= 0x80) {
20
+ tag = tag * 128 + byteArray[position] - 0x80;
21
+ position += 1;
22
+ }
23
+ tag = tag * 128 + byteArray[position] - 0x80;
24
+ position += 1;
25
+ }
26
+ return tag;
27
+ }
28
+ function getLength() {
29
+ let length = 0;
30
+ if (byteArray[position] < 0x80) {
31
+ length = byteArray[position];
32
+ position += 1;
33
+ } else {
34
+ const numberOfDigits = byteArray[position] & 0x7f;
35
+ position += 1;
36
+ length = 0;
37
+ for (let i = 0; i < numberOfDigits; i++) {
38
+ length = length * 256 + byteArray[position];
39
+ position += 1;
40
+ }
41
+ }
42
+ return length;
43
+ }
44
+ const cls = (byteArray[0] & 0xc0) / 64;
45
+ const structured = (byteArray[0] & 0x20) === 0x20;
46
+ const tag = getTag();
47
+ if (byteArray[position] === 0x80) {
48
+ throw new Error('Unsupported length encoding');
49
+ }
50
+ const length = getLength();
51
+ const byteLength = position + length;
52
+ const contents = byteArray.subarray(position, byteLength);
53
+ const raw = byteArray.subarray(0, byteLength);
54
+ return {
55
+ cls,
56
+ tag,
57
+ structured,
58
+ byteLength,
59
+ contents,
60
+ raw
61
+ };
62
+ };
63
+ const derToAsn1List = byteArray => {
64
+ const result = [];
65
+ let nextPosition = 0;
66
+ while (nextPosition < byteArray.length) {
67
+ const nextPiece = derToAsn1(byteArray.subarray(nextPosition));
68
+ result.push(nextPiece);
69
+ nextPosition += nextPiece.byteLength;
70
+ }
71
+ return result;
72
+ };
73
+ const derBitStringValue = byteArray => ({
74
+ unusedBits: byteArray[0],
75
+ bytes: byteArray.subarray(1)
76
+ });
77
+ const parseSignatureValue = asn1 => {
78
+ if (asn1.cls !== 0 || asn1.tag !== 3 || asn1.structured) {
79
+ throw new Error('Bad signature value. Not a BIT STRING.');
80
+ }
81
+ return {
82
+ asn1,
83
+ bits: derBitStringValue(asn1.contents)
84
+ };
85
+ };
86
+ const derObjectIdentifierValue = byteArray => {
87
+ let oid = `${Math.floor(byteArray[0] / 40)}.${byteArray[0] % 40}`;
88
+ let position = 1;
89
+ while (position < byteArray.length) {
90
+ let nextInteger = 0;
91
+ while (byteArray[position] >= 0x80) {
92
+ nextInteger = nextInteger * 0x80 + (byteArray[position] & 0x7f);
93
+ position += 1;
94
+ }
95
+ nextInteger = nextInteger * 0x80 + byteArray[position];
96
+ position += 1;
97
+ oid += `.${nextInteger}`;
98
+ }
99
+ return oid;
100
+ };
101
+ const parseAlgorithmIdentifier = asn1 => {
102
+ if (asn1.cls !== 0 || asn1.tag !== 16 || !asn1.structured) {
103
+ throw new Error('Bad algorithm identifier. Not a SEQUENCE.');
104
+ }
105
+ const pieces = derToAsn1List(asn1.contents);
106
+ if (pieces.length > 2) {
107
+ throw new Error('Bad algorithm identifier. Contains too many child objects.');
108
+ }
109
+ const encodedAlgorithm = pieces[0];
110
+ if (encodedAlgorithm.cls !== 0 || encodedAlgorithm.tag !== 6 || encodedAlgorithm.structured) {
111
+ throw new Error('Bad algorithm identifier. Does not begin with an OBJECT IDENTIFIER.');
112
+ }
113
+ const algorithmOid = derObjectIdentifierValue(encodedAlgorithm.contents);
114
+ const algorithmName = parseOidToAlgorithmName(algorithmOid);
115
+ return {
116
+ asn1,
117
+ algorithmOid,
118
+ algorithmName,
119
+ parameters: pieces.length === 2 ? {
120
+ asn1: pieces[1]
121
+ } : null
122
+ };
123
+ };
124
+ const parseName = asn1 => derToAsn1List(asn1.contents).map(item => {
125
+ const attrSet = derToAsn1(item.contents);
126
+ return parseAlgorithmIdentifier(attrSet);
127
+ });
128
+ exports.parseName = parseName;
129
+ const parseSubjectPublicKeyInfo = asn1 => {
130
+ if (asn1.cls !== 0 || asn1.tag !== 16 || !asn1.structured) {
131
+ throw new Error('Bad SPKI. Not a SEQUENCE.');
132
+ }
133
+ const pieces = derToAsn1List(asn1.contents);
134
+ if (pieces.length !== 2) {
135
+ throw new Error('Bad SubjectPublicKeyInfo. Wrong number of child objects.');
136
+ }
137
+ return {
138
+ asn1,
139
+ algorithm: parseAlgorithmIdentifier(pieces[0]),
140
+ bits: derBitStringValue(pieces[1].contents)
141
+ };
142
+ };
143
+ const parseUtcTime = time => {
144
+ let offset = 4;
145
+ let yearOffset = 0;
146
+ if (time.tag === 23) {
147
+ offset = 2;
148
+ yearOffset = 2000;
149
+ }
150
+ const utc = Buffer.from(time.contents).toString();
151
+ const year = yearOffset + Number(utc.substring(0, offset));
152
+ const month = Number(utc.substring(offset, offset + 2)) - 1;
153
+ const day = Number(utc.substring(offset + 2, offset + 4));
154
+ const hour = Number(utc.substring(offset + 4, offset + 6));
155
+ const minute = Number(utc.substring(offset + 6, offset + 8));
156
+ const date = new Date();
157
+ date.setUTCFullYear(year, month, day);
158
+ date.setUTCHours(hour, minute, 0);
159
+ return date;
160
+ };
161
+ const parseValidity = asn1 => {
162
+ const [from, to] = derToAsn1List(asn1.contents);
163
+ return {
164
+ from: parseUtcTime(from),
165
+ to: parseUtcTime(to)
166
+ };
167
+ };
168
+ const parseExtensions = data => {
169
+ const asn1 = derToAsn1(data.contents);
170
+ if (asn1.cls !== 0 || asn1.tag !== 16 || !asn1.structured) {
171
+ throw new Error("This can't be a Extension. Wrong data type.");
172
+ }
173
+ const readBoolean = value => {
174
+ if (!value) return false;
175
+ if (value.cls !== 0 || value.tag !== 1 || value.contents.length !== 1 || value.structured) {
176
+ throw new Error("This can't be a boolean. Wrong data type.");
177
+ }
178
+ if (![0x00, 0xff].includes(value.contents[0])) {
179
+ throw new Error('Invalid boolean value.');
180
+ }
181
+ return value.contents[0] === 0xff;
182
+ };
183
+ const readBitString = uint8Array => {
184
+ const buffer = Buffer.from(uint8Array);
185
+ const tag = buffer.readUInt8(0);
186
+ if (tag !== 3) {
187
+ throw new Error("This can't be a bit string. Wrong data type.");
188
+ }
189
+ const length = buffer.readUInt8(1);
190
+ const unusedBits = buffer.readUInt8(2);
191
+ const bitStringBytes = buffer.subarray(3, 3 + length - 1);
192
+ const bitString = bitStringBytes.reduce((str, byte) => str + byte.toString(2).padStart(8, '0'), '');
193
+ return bitString.slice(0, bitString.length - unusedBits);
194
+ };
195
+ const readInteger = value => {
196
+ if (!value) return undefined;
197
+ if (value.cls !== 0 || value.tag !== 2 || value.contents.length !== 1 || value.structured) {
198
+ throw new Error("This can't be a integer. Wrong data type.");
199
+ }
200
+ return Buffer.from(value.contents).readInt8();
201
+ };
202
+ const extensions = [];
203
+ derToAsn1List(asn1.contents).forEach(item => {
204
+ const [id, ...pieces] = derToAsn1List(item.contents);
205
+ if (id.cls !== 0 || id.tag !== 6 || id.structured) {
206
+ throw new Error('Bad extension. Does not begin with an OBJECT IDENTIFIER.');
207
+ }
208
+ const algorithm = derObjectIdentifierValue(id.contents);
209
+ const critical = pieces.length > 1 ? readBoolean(pieces[0]) : false;
210
+ const extnValue = pieces.length > 1 ? pieces[1] : pieces[0];
211
+ if (extnValue.cls !== 0 || extnValue.tag !== 4 || extnValue.structured) {
212
+ throw new Error("This can't be a octet string. Wrong data type.");
213
+ }
214
+ if (algorithm === '2.5.29.15') {
215
+ extensions.push({
216
+ key: 'keyUsage',
217
+ critical,
218
+ keyCertSign: readBitString(extnValue.contents)[5]
219
+ });
220
+ } else if (algorithm === '2.5.29.19') {
221
+ const fields = derToAsn1List(derToAsn1(extnValue.contents).contents);
222
+ const ca = fields.length > 0 && fields[0].tag === 1 ? fields[0] : undefined;
223
+ const len = fields.length > 0 && fields[0].tag === 2 ? fields[0] : fields[1];
224
+ extensions.push({
225
+ key: 'basicConstraints',
226
+ critical,
227
+ cA: readBoolean(ca),
228
+ pathLenConstraint: readInteger(len)
229
+ });
230
+ } else {
231
+ extensions.push({
232
+ key: algorithm,
233
+ critical,
234
+ ...item
235
+ });
236
+ }
237
+ });
238
+ return extensions;
239
+ };
240
+ const parseTBSCertificate = asn1 => {
241
+ if (asn1.cls !== 0 || asn1.tag !== 16 || !asn1.structured) {
242
+ throw new Error("This can't be a TBSCertificate. Wrong data type.");
243
+ }
244
+ const pieces = derToAsn1List(asn1.contents);
245
+ if (pieces.length < 7) {
246
+ throw new Error('Bad TBS Certificate. There are fewer than the seven required children.');
247
+ }
248
+ return {
249
+ asn1,
250
+ version: pieces[0],
251
+ serialNumber: pieces[1],
252
+ signature: parseAlgorithmIdentifier(pieces[2]),
253
+ issuer: pieces[3],
254
+ validity: parseValidity(pieces[4]),
255
+ subject: (0, exports.parseName)(pieces[5]),
256
+ subjectPublicKeyInfo: parseSubjectPublicKeyInfo(pieces[6]),
257
+ extensions: parseExtensions(pieces[7])
258
+ };
259
+ };
260
+ const parseCertificate = byteArray => {
261
+ const asn1 = derToAsn1(byteArray);
262
+ if (asn1.cls !== 0 || asn1.tag !== 16 || !asn1.structured) {
263
+ throw new Error("This can't be an X.509 certificate. Wrong data type.");
264
+ }
265
+ const pieces = derToAsn1List(asn1.contents);
266
+ if (pieces.length !== 3) {
267
+ throw new Error('Certificate contains more than the three specified children.');
268
+ }
269
+ return {
270
+ asn1,
271
+ tbsCertificate: parseTBSCertificate(pieces[0]),
272
+ signatureAlgorithm: parseAlgorithmIdentifier(pieces[1]),
273
+ signatureValue: parseSignatureValue(pieces[2])
274
+ };
275
+ };
276
+ exports.parseCertificate = parseCertificate;
277
+ //# sourceMappingURL=x509certificate.js.map
@@ -0,0 +1,3 @@
1
+ import type { DeviceAuthenticityBlacklistConfig } from './deviceAuthenticityBlacklistConfigTypes';
2
+ export declare const deviceAuthenticityBlacklistConfig: DeviceAuthenticityBlacklistConfig;
3
+ //# sourceMappingURL=deviceAuthenticityBlacklistConfig.d.ts.map
@@ -0,0 +1,8 @@
1
+ export const deviceAuthenticityBlacklistConfig = {
2
+ version: 1,
3
+ blacklistedCaPubKeys: [],
4
+ debug: {
5
+ blacklistedCaPubKeys: []
6
+ }
7
+ };
8
+ //# sourceMappingURL=deviceAuthenticityBlacklistConfig.js.map
@@ -0,0 +1,11 @@
1
+ import { Static } from '@trezor/schema-utils';
2
+ export type DeviceAuthenticityBlacklistConfig = Static<typeof DeviceAuthenticityBlacklistConfig>;
3
+ export declare const DeviceAuthenticityBlacklistConfig: import("@sinclair/typebox").TIntersect<[import("@sinclair/typebox").TObject<{
4
+ blacklistedCaPubKeys: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString>;
5
+ }>, import("@sinclair/typebox").TObject<{
6
+ version: import("@sinclair/typebox").TNumber;
7
+ debug: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
8
+ blacklistedCaPubKeys: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString>;
9
+ }>>;
10
+ }>]>;
11
+ //# sourceMappingURL=deviceAuthenticityBlacklistConfigTypes.d.ts.map
@@ -0,0 +1,9 @@
1
+ import { Type } from "@trezor/schema-utils";
2
+ const CertPubKeysBlacklist = Type.Object({
3
+ blacklistedCaPubKeys: Type.Array(Type.String())
4
+ });
5
+ export const DeviceAuthenticityBlacklistConfig = Type.Intersect([CertPubKeysBlacklist, Type.Object({
6
+ version: Type.Number(),
7
+ debug: Type.Optional(CertPubKeysBlacklist)
8
+ })]);
9
+ //# sourceMappingURL=deviceAuthenticityBlacklistConfigTypes.js.map
@@ -0,0 +1,3 @@
1
+ import type { DeviceAuthenticityConfig } from './deviceAuthenticityConfigTypes';
2
+ export declare const deviceAuthenticityConfig: DeviceAuthenticityConfig;
3
+ //# sourceMappingURL=deviceAuthenticityConfig.d.ts.map
@@ -0,0 +1,30 @@
1
+ export const deviceAuthenticityConfig = {
2
+ version: 2,
3
+ T2B1: {
4
+ rootPubKeysOptiga: ['04ca97480ac0d7b1e6efafe518cd433cec2bf8ab9822d76eafd34363b55d63e60380bff20acc75cde03cffcb50ab6f8ce70c878e37ebc58ff7cca0a83b16b15fa5'],
5
+ debug: {
6
+ rootPubKeysOptiga: ['047f77368dea2d4d61e989f474a56723c3212dacf8a808d8795595ef38441427c4389bc454f02089d7f08b873005e4c28d432468997871c0bf286fd3861e21e96a']
7
+ }
8
+ },
9
+ T3B1: {
10
+ rootPubKeysOptiga: ['045b5c3fdd01f3602092834209b86df0ca86a9faf25cac35c73bf6237d66eb21eafcec3706f1ccd5eb4cc7f2fa1751213eccb1c78389afba89a5788ff31ee46a5d'],
11
+ debug: {
12
+ rootPubKeysOptiga: ['047f77368dea2d4d61e989f474a56723c3212dacf8a808d8795595ef38441427c4389bc454f02089d7f08b873005e4c28d432468997871c0bf286fd3861e21e96a']
13
+ }
14
+ },
15
+ T3T1: {
16
+ rootPubKeysOptiga: ['041854b27fb1d9f65abb66828e78c9dc0ca301e66081ab0c6a4d104f9df1cd0ad5a7c75f77a8c092f55cf825d2abaf734f934c9394d5e75f75a5a06a5ee9be93ae'],
17
+ debug: {
18
+ rootPubKeysOptiga: ['04e48b69cd7962068d3cca3bcc6b1747ef496c1e28b5529e34ad7295215ea161dbe8fb08ae0479568f9d2cb07630cb3e52f4af0692102da5873559e45e9fa72959']
19
+ }
20
+ },
21
+ T3W1: {
22
+ rootPubKeysOptiga: ['040dde0d3e0d4da593fac6fd02a461d0e7eef238aca55c7c50b4e9ec37f3873303b6429ef1c9b78b4411a7dcbbc5dde5225979c1c2da3b073e82b1ed3f5f9825bb'],
23
+ rootPubKeysTropic: ['59237acd17134061d655b3f8d624573ca06ce8d862f38ba4e05140ce1d3d609d'],
24
+ debug: {
25
+ rootPubKeysOptiga: ['04521192e173a9da4e3023f747d836563725372681eba3079c56ff11b2fc137ab189eb4155f371127651b5594f8c332fc1e9c0f3b80d4212822668b63189706578'],
26
+ rootPubKeysTropic: []
27
+ }
28
+ }
29
+ };
30
+ //# sourceMappingURL=deviceAuthenticityConfig.js.map
@@ -0,0 +1,47 @@
1
+ import { Static } from '@trezor/schema-utils';
2
+ export type DeviceAuthenticityConfig = Static<typeof DeviceAuthenticityConfig>;
3
+ export declare const DeviceAuthenticityConfig: import("@sinclair/typebox").TIntersect<[import("@sinclair/typebox").TIntersect<[import("@sinclair/typebox").TObject<{
4
+ T2B1: import("@sinclair/typebox").TIntersect<[import("@sinclair/typebox").TObject<{
5
+ rootPubKeysOptiga: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString>;
6
+ rootPubKeysTropic: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString>>;
7
+ }>, import("@sinclair/typebox").TObject<{
8
+ debug: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
9
+ rootPubKeysOptiga: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString>;
10
+ rootPubKeysTropic: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString>>;
11
+ }>>;
12
+ }>]>;
13
+ T3B1: import("@sinclair/typebox").TIntersect<[import("@sinclair/typebox").TObject<{
14
+ rootPubKeysOptiga: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString>;
15
+ rootPubKeysTropic: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString>>;
16
+ }>, import("@sinclair/typebox").TObject<{
17
+ debug: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
18
+ rootPubKeysOptiga: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString>;
19
+ rootPubKeysTropic: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString>>;
20
+ }>>;
21
+ }>]>;
22
+ T3T1: import("@sinclair/typebox").TIntersect<[import("@sinclair/typebox").TObject<{
23
+ rootPubKeysOptiga: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString>;
24
+ rootPubKeysTropic: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString>>;
25
+ }>, import("@sinclair/typebox").TObject<{
26
+ debug: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
27
+ rootPubKeysOptiga: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString>;
28
+ rootPubKeysTropic: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString>>;
29
+ }>>;
30
+ }>]>;
31
+ T3W1: import("@sinclair/typebox").TIntersect<[import("@sinclair/typebox").TObject<{
32
+ rootPubKeysOptiga: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString>;
33
+ rootPubKeysTropic: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString>>;
34
+ }>, import("@sinclair/typebox").TObject<{
35
+ debug: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
36
+ rootPubKeysOptiga: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString>;
37
+ rootPubKeysTropic: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString>>;
38
+ }>>;
39
+ }>]>;
40
+ }>, import("@sinclair/typebox").TObject<{
41
+ T1B1: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUndefined>;
42
+ T2T1: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUndefined>;
43
+ UNKNOWN: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUndefined>;
44
+ }>]>, import("@sinclair/typebox").TObject<{
45
+ version: import("@sinclair/typebox").TNumber;
46
+ }>]>;
47
+ //# sourceMappingURL=deviceAuthenticityConfigTypes.d.ts.map
@@ -0,0 +1,15 @@
1
+ import { MessagesSchema as PROTO } from "@trezor/protobuf";
2
+ import { Type } from "@trezor/schema-utils";
3
+ const CertPubKeys = Type.Object({
4
+ rootPubKeysOptiga: Type.Array(Type.String()),
5
+ rootPubKeysTropic: Type.Optional(Type.Array(Type.String()))
6
+ });
7
+ const ModelsWithKeys = Type.Exclude(Type.KeyOfEnum(PROTO.DeviceModelInternal), Type.Union([Type.Literal('T1B1'), Type.Literal('T2T1'), Type.Literal('UNKNOWN')]));
8
+ const ModelsWithoutKeys = Type.Extract(Type.KeyOfEnum(PROTO.DeviceModelInternal), Type.Union([Type.Literal('T1B1'), Type.Literal('T2T1'), Type.Literal('UNKNOWN')]));
9
+ const ModelPubKeys = Type.Intersect([Type.Record(ModelsWithKeys, Type.Intersect([CertPubKeys, Type.Object({
10
+ debug: Type.Optional(CertPubKeys)
11
+ })])), Type.Partial(Type.Record(ModelsWithoutKeys, Type.Undefined()))]);
12
+ export const DeviceAuthenticityConfig = Type.Intersect([ModelPubKeys, Type.Object({
13
+ version: Type.Number()
14
+ })]);
15
+ //# sourceMappingURL=deviceAuthenticityConfigTypes.js.map
@@ -0,0 +1,9 @@
1
+ export { verifyAuthenticityProof, verifySignatureP256 } from './verifyAuthenticityProof';
2
+ export { type AlgorithmName, parseName, parseCertificate } from './x509certificate';
3
+ export { getRandomChallenge } from './utils';
4
+ export type { VerifySignature, VerifyAuthenticityProofParams, VerifyAuthenticityProofResult, } from './types';
5
+ export { deviceAuthenticityBlacklistConfig } from './config/deviceAuthenticityBlacklistConfig';
6
+ export { DeviceAuthenticityBlacklistConfig } from './config/deviceAuthenticityBlacklistConfigTypes';
7
+ export { deviceAuthenticityConfig } from './config/deviceAuthenticityConfig';
8
+ export { DeviceAuthenticityConfig } from './config/deviceAuthenticityConfigTypes';
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,8 @@
1
+ export { verifyAuthenticityProof, verifySignatureP256 } from "./verifyAuthenticityProof.js";
2
+ export { parseName, parseCertificate } from "./x509certificate.js";
3
+ export { getRandomChallenge } from "./utils.js";
4
+ export { deviceAuthenticityBlacklistConfig } from "./config/deviceAuthenticityBlacklistConfig.js";
5
+ export { DeviceAuthenticityBlacklistConfig } from "./config/deviceAuthenticityBlacklistConfigTypes.js";
6
+ export { deviceAuthenticityConfig } from "./config/deviceAuthenticityConfig.js";
7
+ export { DeviceAuthenticityConfig } from "./config/deviceAuthenticityConfigTypes.js";
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"root":["../src/index.ts","../src/types.ts","../src/utils.ts","../src/verifyAuthenticityProof.ts","../src/x509certificate.ts","../src/config/deviceAuthenticityBlacklistConfig.ts","../src/config/deviceAuthenticityBlacklistConfigTypes.ts","../src/config/deviceAuthenticityConfig.ts","../src/config/deviceAuthenticityConfigTypes.ts"],"version":"5.8.3"}
@@ -0,0 +1,27 @@
1
+ import { MessagesSchema as PROTO } from '@trezor/protobuf';
2
+ import type { DeviceAuthenticityBlacklistConfig } from './config/deviceAuthenticityBlacklistConfigTypes';
3
+ import type { DeviceAuthenticityConfig } from './config/deviceAuthenticityConfigTypes';
4
+ export type VerifySignature = (rawKey: Buffer, data: Uint8Array, signature: Uint8Array) => boolean | Promise<boolean>;
5
+ export type VerifyAuthenticityProofParams = {
6
+ challenge: Buffer;
7
+ certificates: string[];
8
+ signature: string;
9
+ deviceModel: keyof typeof PROTO.DeviceModelInternal;
10
+ config: DeviceAuthenticityConfig;
11
+ blacklistConfig: DeviceAuthenticityBlacklistConfig;
12
+ allowDebugKeys?: boolean;
13
+ challengePrefix?: string;
14
+ bufferChunks?: Buffer[];
15
+ };
16
+ export type VerifyAuthenticityProofResult = {
17
+ valid: true;
18
+ caPubKey: string;
19
+ rootPubKey: string;
20
+ error?: typeof undefined;
21
+ } | {
22
+ valid: false;
23
+ caPubKey?: string;
24
+ rootPubKey?: string;
25
+ error: 'ROOT_PUBKEY_NOT_FOUND' | 'CA_PUBKEY_BLACKLISTED' | 'INVALID_DEVICE_MODEL' | 'INVALID_DEVICE_CERTIFICATE' | 'INVALID_DEVICE_SIGNATURE' | 'RESPONSE_PAYLOAD_MISSING';
26
+ };
27
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,17 @@
1
+ import { MessagesSchema as PROTO } from '@trezor/protobuf';
2
+ import type { DeviceAuthenticityBlacklistConfig } from './config/deviceAuthenticityBlacklistConfigTypes';
3
+ import type { DeviceAuthenticityConfig } from './config/deviceAuthenticityConfigTypes';
4
+ export declare const getRandomChallenge: () => Buffer<ArrayBufferLike>;
5
+ type GetRootPubKeyBlacklistParams = {
6
+ blacklistConfig: DeviceAuthenticityBlacklistConfig;
7
+ allowDebugKeys?: boolean;
8
+ };
9
+ export declare const getRootPubKeyBlacklist: ({ blacklistConfig, allowDebugKeys, }: GetRootPubKeyBlacklistParams) => string[];
10
+ type GetRootPubKeysParams = {
11
+ config: DeviceAuthenticityConfig;
12
+ deviceModel: keyof typeof PROTO.DeviceModelInternal;
13
+ allowDebugKeys?: boolean;
14
+ };
15
+ export declare const getRootPubKeys: ({ config, deviceModel, allowDebugKeys, }: GetRootPubKeysParams) => string[];
16
+ export {};
17
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1,28 @@
1
+ import * as crypto from "crypto";
2
+ export const getRandomChallenge = () => crypto.randomBytes(32);
3
+ export const getRootPubKeyBlacklist = ({
4
+ blacklistConfig,
5
+ allowDebugKeys
6
+ }) => {
7
+ const normalBlacklist = blacklistConfig.blacklistedCaPubKeys ?? [];
8
+ const debugBlacklist = blacklistConfig.debug?.blacklistedCaPubKeys ?? [];
9
+ return allowDebugKeys ? normalBlacklist.concat(debugBlacklist) : normalBlacklist;
10
+ };
11
+ export const getRootPubKeys = ({
12
+ config,
13
+ deviceModel,
14
+ allowDebugKeys
15
+ }) => {
16
+ const modelConfig = config[deviceModel];
17
+ if (modelConfig === undefined) {
18
+ throw new Error(`Pubkeys for ${deviceModel} not found in config`);
19
+ }
20
+ const rootPubKeysNormalOptiga = modelConfig.rootPubKeysOptiga ?? [];
21
+ const rootPubKeysNormalTropic = modelConfig.rootPubKeysTropic ?? [];
22
+ const rootPubKeysDebugOptiga = modelConfig.debug?.rootPubKeysOptiga ?? [];
23
+ const rootPubKeysDebugTropic = modelConfig.debug?.rootPubKeysTropic ?? [];
24
+ const rootPubKeysNormal = [...rootPubKeysNormalOptiga, ...rootPubKeysNormalTropic];
25
+ if (!allowDebugKeys) return rootPubKeysNormal;
26
+ return [...rootPubKeysNormal, ...rootPubKeysDebugOptiga, ...rootPubKeysDebugTropic];
27
+ };
28
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1,4 @@
1
+ import { VerifyAuthenticityProofParams, VerifyAuthenticityProofResult, VerifySignature } from './types';
2
+ export declare const verifySignatureP256: VerifySignature;
3
+ export declare const verifyAuthenticityProof: ({ challenge, certificates, signature, deviceModel, allowDebugKeys, config, blacklistConfig, challengePrefix, bufferChunks, }: VerifyAuthenticityProofParams) => Promise<VerifyAuthenticityProofResult>;
4
+ //# sourceMappingURL=verifyAuthenticityProof.d.ts.map