@qntx/ur 2.1.0 → 4.0.0

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.
@@ -0,0 +1,530 @@
1
+ import { o as isUrType, s as parseUrType, w as UrError } from "./ur-ChGW72hQ.mjs";
2
+ import { a as fromUrWith, c as Ur, i as fromUr, n as codecUrTypes, o as toTagged, r as fromTagged, s as toUr, t as codecMap } from "./typed-C8j8iVYT.mjs";
3
+ import { A as assertText, C as cryptoKeypathCodec, M as expectUint, N as copyBuf, P as copyBytes, g as writeDerivedMeta, h as readDerivedMeta, j as expectClosedIntMap, k as TAGS, p as decodeDerivedHdKeyBody } from "./registry-BGnkPqkV.mjs";
4
+ import { CborError, CborMap, MajorType, Tag, cbor, expectArray, expectInteger, expectMap, expectText, expectUnsigned, extractTaggedContent, taggedValue, validateTag } from "@blockchaincommons/dcbor";
5
+ //#region src/interop/tags.ts
6
+ const TAG_ETH_SIGN_REQUEST = 401;
7
+ const TAG_ETH_SIGNATURE = 402;
8
+ const TAG_SOL_SIGN_REQUEST = 1101;
9
+ const TAG_SOL_SIGNATURE = 1102;
10
+ const TAG_TRON_SIGN_REQUEST = 5101;
11
+ const TAG_TRON_SIGNATURE = 5102;
12
+ const TAG_CRYPTO_MULTI_ACCOUNTS = 1103;
13
+ const TAG_UUID = 37;
14
+ const TAG_ONEKEY_TRON_SIGN_REQUEST = 5201;
15
+ /**
16
+ * Interop (vendor-extension) tags — Keystone / OneKey / ERC-4527. `401`/`402` collide with the
17
+ * BCR-2020-010 `wsh`/`pk` script-expression tags; these types are never embedded tagged, so no
18
+ * global name registration happens here.
19
+ */
20
+ const INTEROP_TAGS = {
21
+ "crypto-multi-accounts": Tag.from(TAG_CRYPTO_MULTI_ACCOUNTS, "crypto-multi-accounts"),
22
+ "eth-sign-request": Tag.from(TAG_ETH_SIGN_REQUEST, "eth-sign-request"),
23
+ "eth-signature": Tag.from(TAG_ETH_SIGNATURE, "eth-signature"),
24
+ "sol-sign-request": Tag.from(TAG_SOL_SIGN_REQUEST, "sol-sign-request"),
25
+ "sol-signature": Tag.from(TAG_SOL_SIGNATURE, "sol-signature"),
26
+ "tron-sign-request": Tag.from(TAG_TRON_SIGN_REQUEST, "tron-sign-request"),
27
+ "tron-signature": Tag.from(TAG_TRON_SIGNATURE, "tron-signature"),
28
+ uuid: Tag.from(TAG_UUID, "uuid")
29
+ };
30
+ /** OneKey's `tron-sign-request` tag (5201); same UR type name as Keystone's 5101. */
31
+ const ONEKEY_TRON_SIGN_REQUEST_TAG = Tag.from(TAG_ONEKEY_TRON_SIGN_REQUEST, "tron-sign-request");
32
+ //#endregion
33
+ //#region src/interop/common.ts
34
+ const UUID_LEN = 16;
35
+ /** `#6.37(bstr .size 16)` for a 16-byte request id (out-of-range otherwise). */
36
+ function requestIdTagged(requestId) {
37
+ if (requestId.length !== UUID_LEN) throw CborError.outOfRange();
38
+ return taggedValue(INTEROP_TAGS.uuid, cbor(copyBuf(requestId)));
39
+ }
40
+ /** Reads a `#6.37` tagged 16-byte request id (untagged ⇒ WrongType, foreign tag ⇒ WrongTag). */
41
+ function readRequestId(cbor) {
42
+ validateTag(cbor, [INTEROP_TAGS.uuid]);
43
+ const bytes = copyBytes(extractTaggedContent(cbor));
44
+ if (bytes.length !== UUID_LEN) throw CborError.outOfRange();
45
+ return bytes;
46
+ }
47
+ /** A signing path is concrete: at least one component, every one an index step. */
48
+ function assertConcretePath(path) {
49
+ if (path.components.length === 0 || path.components.some((component) => component.kind !== "index")) throw CborError.outOfRange();
50
+ return path;
51
+ }
52
+ /** `derivationPath` written `#6.304`; the path must be concrete. */
53
+ function derivationPathTagged(path) {
54
+ assertConcretePath(path);
55
+ return taggedValue(cryptoKeypathCodec.tags[0], cryptoKeypathCodec.encode(path));
56
+ }
57
+ /** Reads `#6.304`/`#6.40304` and requires a concrete path. */
58
+ function readDerivationPath(cbor) {
59
+ validateTag(cbor, [...cryptoKeypathCodec.tags]);
60
+ return assertConcretePath(cryptoKeypathCodec.decode(extractTaggedContent(cbor)));
61
+ }
62
+ /** Non-empty byte string (`signData`/`address`), copied. */
63
+ function readNonEmptyBytes(cbor) {
64
+ const bytes = copyBytes(cbor);
65
+ if (bytes.length === 0) throw CborError.outOfRange();
66
+ return bytes;
67
+ }
68
+ /** Byte string of exactly `len` bytes, copied. */
69
+ function readBytesLen(cbor, len) {
70
+ const bytes = copyBytes(cbor);
71
+ if (bytes.length !== len) throw CborError.outOfRange();
72
+ return bytes;
73
+ }
74
+ /** Writes `key: text` unless `text` is undefined or `""` (which encode as absent). */
75
+ function setOptionalText(map, key, text) {
76
+ if (text !== void 0 && text !== "") map.set(key, assertText(text));
77
+ }
78
+ /** Reads `key` as text when present; `""` on the wire reads as absent. */
79
+ function optionalText(map, key) {
80
+ const value = map.get(key);
81
+ if (value === void 0) return;
82
+ const text = expectText(value);
83
+ return text === "" ? void 0 : text;
84
+ }
85
+ //#endregion
86
+ //#region src/interop/eth.ts
87
+ const SIGN_REQUEST_KEYS$2 = /* @__PURE__ */ new Set([
88
+ 1,
89
+ 2,
90
+ 3,
91
+ 4,
92
+ 5,
93
+ 6,
94
+ 7
95
+ ]);
96
+ const SIGNATURE_KEYS$2 = /* @__PURE__ */ new Set([
97
+ 1,
98
+ 2,
99
+ 3
100
+ ]);
101
+ const ADDRESS_LEN = 20;
102
+ const SIGNATURE_MIN = 65;
103
+ const SIGNATURE_MAX = 72;
104
+ const CHAIN_ID_MAX = 35184372088831;
105
+ const DATA_TYPE_WIRE = {
106
+ transaction: 1,
107
+ typedData: 2,
108
+ personalMessage: 3,
109
+ typedTransaction: 4
110
+ };
111
+ function decodeDataType(cbor) {
112
+ switch (expectUnsigned(cbor)) {
113
+ case 1: return "transaction";
114
+ case 2: return "typedData";
115
+ case 3: return "personalMessage";
116
+ case 4: return "typedTransaction";
117
+ default: throw CborError.outOfRange();
118
+ }
119
+ }
120
+ function dataTypeWire(dataType) {
121
+ const wire = DATA_TYPE_WIRE[dataType];
122
+ if (wire === void 0) throw CborError.wrongType();
123
+ return wire;
124
+ }
125
+ function assertChainId(chainId) {
126
+ if (!Number.isInteger(chainId) || chainId < 1 || chainId > CHAIN_ID_MAX) throw CborError.outOfRange();
127
+ return chainId;
128
+ }
129
+ function readChainId(value) {
130
+ const n = expectInteger(value);
131
+ if (typeof n !== "number" || !Number.isInteger(n) || n < 1 || n > CHAIN_ID_MAX) throw CborError.outOfRange();
132
+ return n;
133
+ }
134
+ function assertAddress(address) {
135
+ if (address.length !== ADDRESS_LEN) throw CborError.outOfRange();
136
+ return copyBuf(address);
137
+ }
138
+ const ethSignRequestCodec = {
139
+ tags: [INTEROP_TAGS["eth-sign-request"]],
140
+ encode(request) {
141
+ const map = new CborMap();
142
+ if (request.requestId !== void 0) map.set(1, requestIdTagged(request.requestId));
143
+ const signData = copyBuf(request.signData);
144
+ if (signData.length === 0) throw CborError.outOfRange();
145
+ map.set(2, cbor(signData));
146
+ map.set(3, dataTypeWire(request.dataType));
147
+ if (request.chainId !== void 0) map.set(4, assertChainId(request.chainId));
148
+ map.set(5, derivationPathTagged(request.derivationPath));
149
+ if (request.address !== void 0) map.set(6, cbor(assertAddress(request.address)));
150
+ setOptionalText(map, 7, request.origin);
151
+ return cbor(map);
152
+ },
153
+ decode(value) {
154
+ const map = expectClosedIntMap(value, SIGN_REQUEST_KEYS$2);
155
+ const requestId = map.get(1);
156
+ const chainId = map.get(4);
157
+ const address = map.get(6);
158
+ const origin = optionalText(map, 7);
159
+ return Object.freeze({
160
+ ...requestId === void 0 ? {} : { requestId: readRequestId(requestId) },
161
+ signData: readNonEmptyBytes(map.getOrThrow(2)),
162
+ dataType: decodeDataType(map.getOrThrow(3)),
163
+ ...chainId === void 0 ? {} : { chainId: readChainId(chainId) },
164
+ derivationPath: readDerivationPath(map.getOrThrow(5)),
165
+ ...address === void 0 ? {} : { address: readBytesLen(address, ADDRESS_LEN) },
166
+ ...origin === void 0 ? {} : { origin }
167
+ });
168
+ }
169
+ };
170
+ const ethSignatureCodec = {
171
+ tags: [INTEROP_TAGS["eth-signature"]],
172
+ encode(signature) {
173
+ const map = new CborMap();
174
+ if (signature.requestId !== void 0) map.set(1, requestIdTagged(signature.requestId));
175
+ const bytes = copyBuf(signature.signature);
176
+ if (bytes.length < SIGNATURE_MIN || bytes.length > SIGNATURE_MAX) throw CborError.outOfRange();
177
+ map.set(2, cbor(bytes));
178
+ setOptionalText(map, 3, signature.origin);
179
+ return cbor(map);
180
+ },
181
+ decode(value) {
182
+ const map = expectClosedIntMap(value, SIGNATURE_KEYS$2);
183
+ const requestId = map.get(1);
184
+ const signature = copyBytes(map.getOrThrow(2));
185
+ if (signature.length < SIGNATURE_MIN || signature.length > SIGNATURE_MAX) throw CborError.outOfRange();
186
+ const origin = optionalText(map, 3);
187
+ return Object.freeze({
188
+ ...requestId === void 0 ? {} : { requestId: readRequestId(requestId) },
189
+ signature,
190
+ ...origin === void 0 ? {} : { origin }
191
+ });
192
+ }
193
+ };
194
+ //#endregion
195
+ //#region src/interop/sol.ts
196
+ const SIGN_REQUEST_KEYS$1 = /* @__PURE__ */ new Set([
197
+ 1,
198
+ 2,
199
+ 3,
200
+ 4,
201
+ 5,
202
+ 6
203
+ ]);
204
+ const SIGNATURE_KEYS$1 = /* @__PURE__ */ new Set([1, 2]);
205
+ const SIGNATURE_LEN$1 = 64;
206
+ const SIGN_TYPE_WIRE = {
207
+ transaction: 1,
208
+ message: 2,
209
+ offchainMessageLegacy: 3,
210
+ offchainMessageStandard: 4
211
+ };
212
+ function decodeSignType(cbor) {
213
+ switch (expectUnsigned(cbor)) {
214
+ case 1: return "transaction";
215
+ case 2: return "message";
216
+ case 3: return "offchainMessageLegacy";
217
+ case 4: return "offchainMessageStandard";
218
+ default: throw CborError.outOfRange();
219
+ }
220
+ }
221
+ function signTypeWire(signType) {
222
+ const wire = SIGN_TYPE_WIRE[signType];
223
+ if (wire === void 0) throw CborError.wrongType();
224
+ return wire;
225
+ }
226
+ const solSignRequestCodec = {
227
+ tags: [INTEROP_TAGS["sol-sign-request"]],
228
+ encode(request) {
229
+ const map = new CborMap();
230
+ if (request.requestId !== void 0) map.set(1, requestIdTagged(request.requestId));
231
+ const signData = copyBuf(request.signData);
232
+ if (signData.length === 0) throw CborError.outOfRange();
233
+ map.set(2, cbor(signData));
234
+ map.set(3, derivationPathTagged(request.derivationPath));
235
+ if (request.address !== void 0) {
236
+ if (request.address.length === 0) throw CborError.outOfRange();
237
+ map.set(4, cbor(copyBuf(request.address)));
238
+ }
239
+ setOptionalText(map, 5, request.origin);
240
+ map.set(6, signTypeWire(request.signType));
241
+ return cbor(map);
242
+ },
243
+ decode(value) {
244
+ const map = expectClosedIntMap(value, SIGN_REQUEST_KEYS$1);
245
+ const requestId = map.get(1);
246
+ const address = map.get(4);
247
+ const origin = optionalText(map, 5);
248
+ return Object.freeze({
249
+ ...requestId === void 0 ? {} : { requestId: readRequestId(requestId) },
250
+ signData: readNonEmptyBytes(map.getOrThrow(2)),
251
+ derivationPath: readDerivationPath(map.getOrThrow(3)),
252
+ ...address === void 0 ? {} : { address: readNonEmptyBytes(address) },
253
+ ...origin === void 0 ? {} : { origin },
254
+ signType: decodeSignType(map.getOrThrow(6))
255
+ });
256
+ }
257
+ };
258
+ const solSignatureCodec = {
259
+ tags: [INTEROP_TAGS["sol-signature"]],
260
+ encode(signature) {
261
+ const map = new CborMap();
262
+ if (signature.requestId !== void 0) map.set(1, requestIdTagged(signature.requestId));
263
+ const bytes = copyBuf(signature.signature);
264
+ if (bytes.length !== SIGNATURE_LEN$1) throw CborError.outOfRange();
265
+ map.set(2, cbor(bytes));
266
+ return cbor(map);
267
+ },
268
+ decode(value) {
269
+ const map = expectClosedIntMap(value, SIGNATURE_KEYS$1);
270
+ const requestId = map.get(1);
271
+ return Object.freeze({
272
+ ...requestId === void 0 ? {} : { requestId: readRequestId(requestId) },
273
+ signature: readBytesLen(map.getOrThrow(2), SIGNATURE_LEN$1)
274
+ });
275
+ }
276
+ };
277
+ //#endregion
278
+ //#region src/interop/tron.ts
279
+ const SIGN_REQUEST_KEYS = /* @__PURE__ */ new Set([
280
+ 1,
281
+ 2,
282
+ 3,
283
+ 4,
284
+ 5,
285
+ 6
286
+ ]);
287
+ const SIGNATURE_KEYS = /* @__PURE__ */ new Set([1, 2]);
288
+ const SIGNATURE_LEN = 65;
289
+ function decodeBody(value) {
290
+ const map = expectClosedIntMap(value, SIGN_REQUEST_KEYS);
291
+ const requestId = map.get(1);
292
+ const discriminator = map.getOrThrow(3);
293
+ let request;
294
+ if (discriminator.type === MajorType.Unsigned) {
295
+ const dataType = keystoneDataType(expectUnsigned(discriminator));
296
+ request = {
297
+ ...requestId === void 0 ? {} : { requestId: readRequestId(requestId) },
298
+ signData: readNonEmptyBytes(map.getOrThrow(2)),
299
+ dataType,
300
+ derivationPath: readDerivationPath(map.getOrThrow(4)),
301
+ ...optionalAddressOrigin(map, 5, 6)
302
+ };
303
+ } else if (discriminator.type === MajorType.Tagged) request = {
304
+ ...requestId === void 0 ? {} : { requestId: readRequestId(requestId) },
305
+ signData: readNonEmptyBytes(map.getOrThrow(2)),
306
+ dataType: oneKeyRequestType(map.getOrThrow(6)),
307
+ derivationPath: readDerivationPath(discriminator),
308
+ ...optionalAddressOrigin(map, 4, 5)
309
+ };
310
+ else throw CborError.wrongType();
311
+ return Object.freeze(request);
312
+ }
313
+ function keystoneDataType(n) {
314
+ switch (n) {
315
+ case 1: return "transaction";
316
+ case 2: return "messageV2";
317
+ default: throw CborError.outOfRange();
318
+ }
319
+ }
320
+ function oneKeyRequestType(cbor) {
321
+ switch (expectUnsigned(cbor)) {
322
+ case 1: return "transaction";
323
+ case 2: return "messageV1";
324
+ case 3: return "messageV2";
325
+ default: throw CborError.outOfRange();
326
+ }
327
+ }
328
+ function optionalAddressOrigin(map, addressKey, originKey) {
329
+ const address = map.get(addressKey);
330
+ const origin = optionalText(map, originKey);
331
+ return {
332
+ ...address === void 0 ? {} : { address: readNonEmptyBytes(address) },
333
+ ...origin === void 0 ? {} : { origin }
334
+ };
335
+ }
336
+ function keystoneDataTypeWire(dataType) {
337
+ switch (dataType) {
338
+ case "transaction": return 1;
339
+ case "messageV2": return 2;
340
+ default: throw CborError.outOfRange();
341
+ }
342
+ }
343
+ const ONEKEY_REQUEST_TYPE_WIRE = {
344
+ transaction: 1,
345
+ messageV1: 2,
346
+ messageV2: 3
347
+ };
348
+ function oneKeyRequestTypeWire(dataType) {
349
+ const wire = ONEKEY_REQUEST_TYPE_WIRE[dataType];
350
+ if (wire === void 0) throw CborError.wrongType();
351
+ return wire;
352
+ }
353
+ function sharedFields(map, request) {
354
+ if (request.requestId !== void 0) map.set(1, requestIdTagged(request.requestId));
355
+ const signData = copyBuf(request.signData);
356
+ if (signData.length === 0) throw CborError.outOfRange();
357
+ map.set(2, cbor(signData));
358
+ }
359
+ function optionalTail(map, request, addressKey, originKey) {
360
+ if (request.address !== void 0) {
361
+ if (request.address.length === 0) throw CborError.outOfRange();
362
+ map.set(addressKey, cbor(copyBuf(request.address)));
363
+ }
364
+ setOptionalText(map, originKey, request.origin);
365
+ }
366
+ /**
367
+ * Keystone's `tron-sign-request` writer (tag 5101): `{1 uuid?, 2 signData, 3 dataType, 4 path, 5
368
+ * address?, 6 origin?}` where `dataType` is 1 transaction / 2 messageV2 — `messageV1` has no
369
+ * Keystone wire value, so both encode and decode reject it (decode would not round-trip). Reads the
370
+ * OneKey dialect too at the body level: key 3's CBOR type picks the layout, and `transaction`/
371
+ * `messageV2` OneKey bodies decode because they re-encode under this writer. `fromTagged` requires
372
+ * this codec's own tag (5101).
373
+ */
374
+ const tronSignRequestCodec = {
375
+ tags: [INTEROP_TAGS["tron-sign-request"]],
376
+ encode(request) {
377
+ const map = new CborMap();
378
+ sharedFields(map, request);
379
+ map.set(3, keystoneDataTypeWire(request.dataType));
380
+ map.set(4, derivationPathTagged(request.derivationPath));
381
+ optionalTail(map, request, 5, 6);
382
+ return cbor(map);
383
+ },
384
+ decode(value) {
385
+ const request = decodeBody(value);
386
+ if (request.dataType === "messageV1") throw CborError.outOfRange();
387
+ return request;
388
+ }
389
+ };
390
+ /**
391
+ * OneKey's `tron-sign-request` writer (tag 5201, same UR type name): the `BaseSignRequest` layout
392
+ * `{1 uuid?, 2 signData, 3 path, 4 address?, 5 origin?, 6 requestType}` where `requestType` is 1
393
+ * transaction / 2 messageV1 / 3 messageV2. Accepts every data type and reads the Keystone dialect
394
+ * too at the body level. `fromTagged` requires this codec's own tag (5201).
395
+ */
396
+ const oneKeyTronSignRequestCodec = {
397
+ tags: [ONEKEY_TRON_SIGN_REQUEST_TAG],
398
+ encode(request) {
399
+ const map = new CborMap();
400
+ sharedFields(map, request);
401
+ map.set(3, derivationPathTagged(request.derivationPath));
402
+ optionalTail(map, request, 4, 5);
403
+ map.set(6, oneKeyRequestTypeWire(request.dataType));
404
+ return cbor(map);
405
+ },
406
+ decode: decodeBody
407
+ };
408
+ const tronSignatureCodec = {
409
+ tags: [INTEROP_TAGS["tron-signature"]],
410
+ encode(signature) {
411
+ const map = new CborMap();
412
+ if (signature.requestId !== void 0) map.set(1, requestIdTagged(signature.requestId));
413
+ const bytes = copyBuf(signature.signature);
414
+ if (bytes.length !== SIGNATURE_LEN) throw CborError.outOfRange();
415
+ map.set(2, cbor(bytes));
416
+ return cbor(map);
417
+ },
418
+ decode(value) {
419
+ const map = expectClosedIntMap(value, SIGNATURE_KEYS);
420
+ const requestId = map.get(1);
421
+ return Object.freeze({
422
+ ...requestId === void 0 ? {} : { requestId: readRequestId(requestId) },
423
+ signature: readBytesLen(map.getOrThrow(2), SIGNATURE_LEN)
424
+ });
425
+ }
426
+ };
427
+ //#endregion
428
+ //#region src/interop/multi-accounts.ts
429
+ const ACCOUNT_KEYS = /* @__PURE__ */ new Set([
430
+ 1,
431
+ 2,
432
+ 3,
433
+ 4,
434
+ 5
435
+ ]);
436
+ const KEY_BODY_KEYS = /* @__PURE__ */ new Set([
437
+ 2,
438
+ 3,
439
+ 4,
440
+ 5,
441
+ 6,
442
+ 7,
443
+ 8,
444
+ 9,
445
+ 10
446
+ ]);
447
+ const KEY_DATA_LEN = 33;
448
+ const ED25519_KEY_DATA_LEN = 32;
449
+ const CHAIN_CODE_LEN = 32;
450
+ function encodeKey(key) {
451
+ if (key.curve === "secp256k1") {
452
+ const derived = key.key;
453
+ if (derived.isPrivate === true || derived.keyData.length !== KEY_DATA_LEN) throw CborError.outOfRange();
454
+ const map = new CborMap();
455
+ map.set(3, cbor(copyBuf(derived.keyData)));
456
+ writeDerivedMeta(map, derived, true);
457
+ return taggedValue(TAGS["crypto-hdkey"], cbor(map));
458
+ }
459
+ const ed = key.key;
460
+ if (ed.isPrivate !== void 0 && ed.isPrivate) throw CborError.outOfRange();
461
+ if (ed.keyData.length !== ED25519_KEY_DATA_LEN) throw CborError.outOfRange();
462
+ const map = new CborMap();
463
+ map.set(3, cbor(copyBuf(ed.keyData)));
464
+ writeDerivedMeta(map, ed, true);
465
+ return taggedValue(TAGS["crypto-hdkey"], cbor(map));
466
+ }
467
+ function decodeKey(cbor) {
468
+ validateTag(cbor, [TAGS["crypto-hdkey"], TAGS.hdkey]);
469
+ const body = extractTaggedContent(cbor);
470
+ const keyData = expectMap(body).get(3);
471
+ if (keyData === void 0) throw CborError.wrongType();
472
+ const bytes = copyBytes(keyData);
473
+ if (bytes.length === KEY_DATA_LEN) {
474
+ const derived = decodeDerivedHdKeyBody(body);
475
+ if (derived.isPrivate === true) throw CborError.outOfRange();
476
+ return Object.freeze({
477
+ curve: "secp256k1",
478
+ key: derived
479
+ });
480
+ }
481
+ if (bytes.length !== ED25519_KEY_DATA_LEN) throw CborError.outOfRange();
482
+ const map = expectClosedIntMap(body, KEY_BODY_KEYS);
483
+ const meta = readDerivedMeta(map, true);
484
+ if (meta.isPrivate === true) throw CborError.outOfRange();
485
+ if (meta.chainCode !== void 0 && meta.chainCode.length !== CHAIN_CODE_LEN) throw CborError.outOfRange();
486
+ const { isPrivate: _isPrivate, ...rest } = meta;
487
+ return Object.freeze({
488
+ curve: "ed25519",
489
+ key: Object.freeze({
490
+ ...rest,
491
+ keyData: bytes,
492
+ ...meta.isPrivate === void 0 ? {} : { isPrivate: false }
493
+ })
494
+ });
495
+ }
496
+ function assertFingerprint(n) {
497
+ if (!Number.isInteger(n) || n < 0 || n > 4294967295) throw CborError.outOfRange();
498
+ }
499
+ const cryptoMultiAccountsCodec = {
500
+ tags: [INTEROP_TAGS["crypto-multi-accounts"]],
501
+ encode(accounts) {
502
+ if (accounts.keys.length === 0) throw CborError.outOfRange();
503
+ assertFingerprint(accounts.masterFingerprint);
504
+ const map = new CborMap();
505
+ map.set(1, accounts.masterFingerprint);
506
+ const keys = accounts.keys.map(encodeKey);
507
+ map.set(2, keys);
508
+ setOptionalText(map, 3, accounts.device);
509
+ setOptionalText(map, 4, accounts.deviceId);
510
+ setOptionalText(map, 5, accounts.version);
511
+ return cbor(map);
512
+ },
513
+ decode(value) {
514
+ const map = expectClosedIntMap(value, ACCOUNT_KEYS);
515
+ const keys = expectArray(map.getOrThrow(2));
516
+ if (keys.length === 0) throw CborError.outOfRange();
517
+ const device = optionalText(map, 3);
518
+ const deviceId = optionalText(map, 4);
519
+ const version = optionalText(map, 5);
520
+ return Object.freeze({
521
+ masterFingerprint: expectUint(map.getOrThrow(1), 4294967295),
522
+ keys: keys.map(decodeKey),
523
+ ...device === void 0 ? {} : { device },
524
+ ...deviceId === void 0 ? {} : { deviceId },
525
+ ...version === void 0 ? {} : { version }
526
+ });
527
+ }
528
+ };
529
+ //#endregion
530
+ export { INTEROP_TAGS, Ur, UrError, codecMap, codecUrTypes, cryptoKeypathCodec, cryptoMultiAccountsCodec, ethSignRequestCodec, ethSignatureCodec, fromTagged, fromUr, fromUrWith, isUrType, oneKeyTronSignRequestCodec, parseUrType, solSignRequestCodec, solSignatureCodec, toTagged, toUr, tronSignRequestCodec, tronSignatureCodec };