@hwlt/era-connect 0.1.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.
- package/LICENSE +201 -0
- package/NOTICE +9 -0
- package/README.md +101 -0
- package/btc/package.json +6 -0
- package/dist/btc-DfQ0q79G.d.ts +58 -0
- package/dist/btc-Dn6_Y12c.d.cts +58 -0
- package/dist/btc-Fr6Jz4Fi.cjs +104 -0
- package/dist/btc-Fr6Jz4Fi.cjs.map +1 -0
- package/dist/btc-VyJKXq7d.js +99 -0
- package/dist/btc-VyJKXq7d.js.map +1 -0
- package/dist/btc.cjs +9 -0
- package/dist/btc.d.cts +3 -0
- package/dist/btc.d.ts +3 -0
- package/dist/btc.js +3 -0
- package/dist/evm-BHj_2OTG.cjs +134 -0
- package/dist/evm-BHj_2OTG.cjs.map +1 -0
- package/dist/evm-DJxGGAbD.d.cts +76 -0
- package/dist/evm-KrV5wK08.d.ts +76 -0
- package/dist/evm-kJb3-oiR.js +117 -0
- package/dist/evm-kJb3-oiR.js.map +1 -0
- package/dist/evm.cjs +11 -0
- package/dist/evm.d.cts +3 -0
- package/dist/evm.d.ts +3 -0
- package/dist/evm.js +3 -0
- package/dist/index.cjs +530 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +285 -0
- package/dist/index.d.ts +285 -0
- package/dist/index.js +506 -0
- package/dist/index.js.map +1 -0
- package/dist/messages-17Oup0-Z.js +208 -0
- package/dist/messages-17Oup0-Z.js.map +1 -0
- package/dist/messages-BzcdWlg1.cjs +243 -0
- package/dist/messages-BzcdWlg1.cjs.map +1 -0
- package/dist/messages-DsPvW8Oi.d.cts +29 -0
- package/dist/messages-DsPvW8Oi.d.ts +29 -0
- package/dist/shared-B8Wc7ViU.js +1472 -0
- package/dist/shared-B8Wc7ViU.js.map +1 -0
- package/dist/shared-CI8zhQiE.d.cts +218 -0
- package/dist/shared-CI8zhQiE.d.ts +218 -0
- package/dist/shared-nISrEktU.cjs +1777 -0
- package/dist/shared-nISrEktU.cjs.map +1 -0
- package/dist/solana-8eOwz0gM.d.cts +49 -0
- package/dist/solana-C2Xm7w8a.d.ts +49 -0
- package/dist/solana-C7JQEAec.js +87 -0
- package/dist/solana-C7JQEAec.js.map +1 -0
- package/dist/solana-DdEn24X4.cjs +98 -0
- package/dist/solana-DdEn24X4.cjs.map +1 -0
- package/dist/solana.cjs +10 -0
- package/dist/solana.d.cts +3 -0
- package/dist/solana.d.ts +3 -0
- package/dist/solana.js +3 -0
- package/dist/tron-Bo9HnvVE.js +158 -0
- package/dist/tron-Bo9HnvVE.js.map +1 -0
- package/dist/tron-CQIEqjCA.cjs +163 -0
- package/dist/tron-CQIEqjCA.cjs.map +1 -0
- package/dist/tron-YllfTmx6.d.ts +63 -0
- package/dist/tron-gG51KMnX.d.cts +63 -0
- package/dist/tron.cjs +11 -0
- package/dist/tron.d.cts +4 -0
- package/dist/tron.d.ts +4 -0
- package/dist/tron.js +4 -0
- package/dist/verify.cjs +445 -0
- package/dist/verify.cjs.map +1 -0
- package/dist/verify.d.cts +162 -0
- package/dist/verify.d.ts +162 -0
- package/dist/verify.js +438 -0
- package/dist/verify.js.map +1 -0
- package/evm/package.json +6 -0
- package/package.json +140 -0
- package/proto/tron/base.proto +16 -0
- package/proto/tron/message.proto +12 -0
- package/proto/tron/payload.proto +35 -0
- package/proto/tron/sign_transaction_result.proto +10 -0
- package/proto/tron/sync.proto +21 -0
- package/proto/tron/transaction.proto +17 -0
- package/proto/tron/tron_transaction.proto +31 -0
- package/proto/tron/verify_address.proto +10 -0
- package/solana/package.json +6 -0
- package/tron/package.json +6 -0
- package/verify/package.json +6 -0
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { G as cbMap, L as xfpToHex, N as normalizeXfp, P as parsePath, T as concatBytes, W as cbBytes, Y as mapGet, Z as EraSdkError, _ as Ur, c as resolveRequestId, g as uuidStringify, h as normalizeRequestId, l as toUr, n as makeSignRequest, o as requireUrType, q as cbText, r as requireReplyMap, s as resolveContext, x as cborEncode, y as crc32, z as asBytes } from "./shared-B8Wc7ViU.js";
|
|
2
|
+
import { n as encodeSignRequestProto, r as splitSignedTronTx, t as decodeSignResultProto } from "./messages-17Oup0-Z.js";
|
|
3
|
+
import { Gunzip, gzipSync } from "fflate";
|
|
4
|
+
//#region src/tron-proto/gzip.ts
|
|
5
|
+
/** Smallest possible gzip stream: 10-byte header + 8-byte trailer. */
|
|
6
|
+
const MIN_GZIP_BYTES = 18;
|
|
7
|
+
/** Bytes fed to the inflater per step; bounds the overshoot past the cap. */
|
|
8
|
+
const SLICE_BYTES = 1024;
|
|
9
|
+
/** Deterministic gzip (fixed level, zeroed mtime) for reproducible request bytes. */
|
|
10
|
+
function gzipCompress(data) {
|
|
11
|
+
return gzipSync(data, {
|
|
12
|
+
level: 9,
|
|
13
|
+
mtime: 0
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Inflate with a hard output ceiling.
|
|
18
|
+
*
|
|
19
|
+
* A one-shot gunzip allocates the entire output before anyone can refuse it —
|
|
20
|
+
* gzip reaches ~1000:1 in practice, so a few hundred scanned bytes could ask
|
|
21
|
+
* for an arbitrary allocation. The decoder is therefore driven in slices and
|
|
22
|
+
* the output counted as it arrives; the moment the total would pass the cap,
|
|
23
|
+
* feeding stops and the reply is refused.
|
|
24
|
+
*
|
|
25
|
+
* The trailer's ISIZE (declared inflated length) is used twice: as a cheap
|
|
26
|
+
* refusal of honest bombs before any work, and as a truncation check at the
|
|
27
|
+
* end — an inflater hands back a partial buffer for a truncated stream
|
|
28
|
+
* without erroring, and a genuine device reply always declares honestly.
|
|
29
|
+
*/
|
|
30
|
+
function gunzipCapped(data, maxOutputBytes) {
|
|
31
|
+
if (data.length < MIN_GZIP_BYTES) throw new EraSdkError("gzip-error", "compressed payload is too short to be a gzip stream");
|
|
32
|
+
if (data[0] !== 31 || data[1] !== 139) throw new EraSdkError("gzip-error", "compressed payload is not a gzip stream");
|
|
33
|
+
const n = data.length;
|
|
34
|
+
const isize = (data[n - 4] | data[n - 3] << 8 | data[n - 2] << 16 | data[n - 1] << 24) >>> 0;
|
|
35
|
+
if (isize > maxOutputBytes) throw new EraSdkError("gzip-error", `compressed payload declares ${isize} bytes, over the ${maxOutputBytes} byte ceiling`);
|
|
36
|
+
const chunks = [];
|
|
37
|
+
let total = 0;
|
|
38
|
+
let overflowed = false;
|
|
39
|
+
let malformed = null;
|
|
40
|
+
const gunzip = new Gunzip((chunk) => {
|
|
41
|
+
if (overflowed) return;
|
|
42
|
+
if (total + chunk.length > maxOutputBytes) {
|
|
43
|
+
overflowed = true;
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
chunks.push(chunk);
|
|
47
|
+
total += chunk.length;
|
|
48
|
+
});
|
|
49
|
+
try {
|
|
50
|
+
for (let offset = 0; offset < n && !overflowed; offset += SLICE_BYTES) {
|
|
51
|
+
const end = Math.min(offset + SLICE_BYTES, n);
|
|
52
|
+
const isLast = end === n;
|
|
53
|
+
gunzip.push(data.slice(offset, end), isLast);
|
|
54
|
+
}
|
|
55
|
+
} catch (e) {
|
|
56
|
+
malformed = e.message ?? "inflate error";
|
|
57
|
+
}
|
|
58
|
+
if (overflowed) throw new EraSdkError("gzip-error", `compressed payload inflates past the ${maxOutputBytes} byte ceiling`);
|
|
59
|
+
if (malformed !== null) throw new EraSdkError("gzip-error", `compressed payload is malformed: ${malformed}`);
|
|
60
|
+
const out = concatBytes(...chunks);
|
|
61
|
+
if (out.length !== isize) throw new EraSdkError("gzip-error", `compressed payload inflated to ${out.length} bytes but declares ${isize} — truncated or malformed`);
|
|
62
|
+
const declaredCrc = (data[n - 8] | data[n - 7] << 8 | data[n - 6] << 16 | data[n - 5] << 24) >>> 0;
|
|
63
|
+
if (crc32(out) !== declaredCrc) throw new EraSdkError("gzip-error", "compressed payload is malformed: CRC mismatch");
|
|
64
|
+
return out;
|
|
65
|
+
}
|
|
66
|
+
//#endregion
|
|
67
|
+
//#region src/chains/tron.ts
|
|
68
|
+
/**
|
|
69
|
+
* Ceilings on the gzip blob a `keystone-sign-result` may carry. Tron is the
|
|
70
|
+
* only chain whose reply is compressed, so it is the only one where a few
|
|
71
|
+
* hundred scanned bytes can ask for an arbitrary allocation. Generous
|
|
72
|
+
* multiples of the largest real device reply.
|
|
73
|
+
*/
|
|
74
|
+
const MAX_COMPRESSED_BYTES = 8192;
|
|
75
|
+
const MAX_INFLATED_BYTES = 65536;
|
|
76
|
+
const REPLY_TYPES = ["keystone-sign-result"];
|
|
77
|
+
/**
|
|
78
|
+
* Tron signing rides the structured `keystone-sign-request` (6101) envelope —
|
|
79
|
+
* a gzip-compressed protobuf inside CBOR `{1: gzip(protobuf), 2: origin}`.
|
|
80
|
+
* The registry's generic `tron-sign-request` (5101) is NOT accepted by the
|
|
81
|
+
* device and gets no response; do not emit it.
|
|
82
|
+
*/
|
|
83
|
+
var TronChain = class {
|
|
84
|
+
constructor(config) {
|
|
85
|
+
this.context = resolveContext(config);
|
|
86
|
+
}
|
|
87
|
+
/** Build a `keystone-sign-request` (6101). Reply: `keystone-sign-result` (6102). */
|
|
88
|
+
generateSignRequest(props) {
|
|
89
|
+
const requestId = resolveRequestId(this.context, props.requestId);
|
|
90
|
+
parsePath(props.path);
|
|
91
|
+
const xfp = normalizeXfp(props.xfp);
|
|
92
|
+
if (props.rawData.length === 0) throw new EraSdkError("invalid-props", "rawData must not be empty");
|
|
93
|
+
if (!/^[0-9a-fA-F]{64}$/.test(props.latestBlock.hash)) throw new EraSdkError("invalid-props", "latestBlock.hash must be the FULL 64-hex block id (the device slices ref_block_hash from it)");
|
|
94
|
+
const proto = encodeSignRequestProto({
|
|
95
|
+
xfpHex: xfpToHex(xfp),
|
|
96
|
+
signId: uuidStringify(requestId),
|
|
97
|
+
hdPath: props.path,
|
|
98
|
+
timestamp: props.timestamp ?? 0,
|
|
99
|
+
decimals: props.display?.decimals ?? 6,
|
|
100
|
+
token: props.display?.token ?? "",
|
|
101
|
+
contractAddress: props.display?.contractAddress,
|
|
102
|
+
from: props.display?.from,
|
|
103
|
+
to: props.display?.to,
|
|
104
|
+
memo: props.display?.memo,
|
|
105
|
+
value: props.display?.value,
|
|
106
|
+
fee: props.display?.fee,
|
|
107
|
+
latestBlock: props.latestBlock,
|
|
108
|
+
rawData: props.rawData
|
|
109
|
+
});
|
|
110
|
+
const ur = new Ur("keystone-sign-request", cborEncode(cbMap([[1, cbBytes(gzipCompress(proto))], [2, cbText(props.origin ?? this.context.origin)]])));
|
|
111
|
+
return makeSignRequest({
|
|
112
|
+
ur,
|
|
113
|
+
requestId,
|
|
114
|
+
replyTypes: REPLY_TYPES,
|
|
115
|
+
context: this.context,
|
|
116
|
+
parse: (reply) => parseTronSignature(reply, requestId)
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Parse a `keystone-sign-result` standalone. Tron carries the request id
|
|
121
|
+
* INSIDE the protobuf (`signId`); passing `expect.requestId` is what makes
|
|
122
|
+
* the echo check possible here — prefer `SignRequest.scanner().parse()`.
|
|
123
|
+
*/
|
|
124
|
+
parseSignature(input, expect) {
|
|
125
|
+
return parseTronSignature(toUr(input), expect?.requestId === void 0 ? void 0 : normalizeRequestId(expect.requestId));
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
function parseTronSignature(ur, expectedRequestId) {
|
|
129
|
+
requireUrType(ur, [...REPLY_TYPES], "keystone-sign-result");
|
|
130
|
+
const map = requireReplyMap(ur, "keystone-sign-result");
|
|
131
|
+
const compressed = asBytes(mapGet(map, 1));
|
|
132
|
+
if (!compressed) throw new EraSdkError("malformed-reply", "keystone-sign-result is missing the payload (key 1)");
|
|
133
|
+
if (compressed.length > MAX_COMPRESSED_BYTES) throw new EraSdkError("limit-exceeded", `keystone-sign-result payload is ${compressed.length} bytes, over the ${MAX_COMPRESSED_BYTES} byte ceiling`);
|
|
134
|
+
const result = decodeSignResultProto(gunzipCapped(compressed, MAX_INFLATED_BYTES));
|
|
135
|
+
if (expectedRequestId !== void 0) {
|
|
136
|
+
const expected = uuidStringify(expectedRequestId).toLowerCase();
|
|
137
|
+
if (result.signId.toLowerCase() !== expected) throw new EraSdkError("request-id-mismatch", result.signId === "" ? "keystone-sign-result does not echo the request id (signId)" : "keystone-sign-result echoes a different request id — it answers another sign request, not this one");
|
|
138
|
+
}
|
|
139
|
+
if (result.rawTx === "") throw new EraSdkError("malformed-reply", "keystone-sign-result has no signed transaction");
|
|
140
|
+
const signedTx = splitSignedTronTx(result.rawTx);
|
|
141
|
+
return {
|
|
142
|
+
requestId: expectedRequestId ?? signIdToBytes(result.signId),
|
|
143
|
+
txId: result.txId,
|
|
144
|
+
rawTx: result.rawTx,
|
|
145
|
+
signedTx
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
function signIdToBytes(signId) {
|
|
149
|
+
try {
|
|
150
|
+
return normalizeRequestId(signId);
|
|
151
|
+
} catch {
|
|
152
|
+
return /* @__PURE__ */ new Uint8Array(16);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
//#endregion
|
|
156
|
+
export { TronChain as t };
|
|
157
|
+
|
|
158
|
+
//# sourceMappingURL=tron-Bo9HnvVE.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tron-Bo9HnvVE.js","names":["UrValue"],"sources":["../src/tron-proto/gzip.ts","../src/chains/tron.ts"],"sourcesContent":["import { Gunzip, gzipSync } from 'fflate';\nimport { concatBytes } from '../core/bytes';\nimport { EraSdkError } from '../core/errors';\nimport { crc32 } from '../ur/crc32';\n\n/** Smallest possible gzip stream: 10-byte header + 8-byte trailer. */\nconst MIN_GZIP_BYTES = 18;\n\n/** Bytes fed to the inflater per step; bounds the overshoot past the cap. */\nconst SLICE_BYTES = 1024;\n\n/** Deterministic gzip (fixed level, zeroed mtime) for reproducible request bytes. */\nexport function gzipCompress(data: Uint8Array): Uint8Array {\n return gzipSync(data, { level: 9, mtime: 0 });\n}\n\n/**\n * Inflate with a hard output ceiling.\n *\n * A one-shot gunzip allocates the entire output before anyone can refuse it —\n * gzip reaches ~1000:1 in practice, so a few hundred scanned bytes could ask\n * for an arbitrary allocation. The decoder is therefore driven in slices and\n * the output counted as it arrives; the moment the total would pass the cap,\n * feeding stops and the reply is refused.\n *\n * The trailer's ISIZE (declared inflated length) is used twice: as a cheap\n * refusal of honest bombs before any work, and as a truncation check at the\n * end — an inflater hands back a partial buffer for a truncated stream\n * without erroring, and a genuine device reply always declares honestly.\n */\nexport function gunzipCapped(data: Uint8Array, maxOutputBytes: number): Uint8Array {\n if (data.length < MIN_GZIP_BYTES) {\n throw new EraSdkError('gzip-error', 'compressed payload is too short to be a gzip stream');\n }\n if (data[0] !== 0x1f || data[1] !== 0x8b) {\n throw new EraSdkError('gzip-error', 'compressed payload is not a gzip stream');\n }\n const n = data.length;\n const isize =\n (data[n - 4]! | (data[n - 3]! << 8) | (data[n - 2]! << 16) | (data[n - 1]! << 24)) >>> 0;\n if (isize > maxOutputBytes) {\n throw new EraSdkError(\n 'gzip-error',\n `compressed payload declares ${isize} bytes, over the ${maxOutputBytes} byte ceiling`,\n );\n }\n\n const chunks: Uint8Array[] = [];\n let total = 0;\n let overflowed = false;\n let malformed: string | null = null;\n\n const gunzip = new Gunzip((chunk) => {\n if (overflowed) return;\n if (total + chunk.length > maxOutputBytes) {\n overflowed = true;\n return;\n }\n chunks.push(chunk);\n total += chunk.length;\n });\n\n try {\n for (let offset = 0; offset < n && !overflowed; offset += SLICE_BYTES) {\n const end = Math.min(offset + SLICE_BYTES, n);\n const isLast = end === n;\n gunzip.push(data.slice(offset, end), isLast);\n }\n } catch (e) {\n malformed = (e as Error).message ?? 'inflate error';\n }\n\n if (overflowed) {\n throw new EraSdkError(\n 'gzip-error',\n `compressed payload inflates past the ${maxOutputBytes} byte ceiling`,\n );\n }\n if (malformed !== null) {\n throw new EraSdkError('gzip-error', `compressed payload is malformed: ${malformed}`);\n }\n const out = concatBytes(...chunks);\n if (out.length !== isize) {\n throw new EraSdkError(\n 'gzip-error',\n `compressed payload inflated to ${out.length} bytes but declares ${isize} — truncated or malformed`,\n );\n }\n // The trailer CRC32 (little-endian, bytes n-8..n-5) must cover the inflated\n // output. The streaming inflater does not verify it, and the reference\n // implementation's native decoder does — without this check a corrupted\n // stream, or a CONCATENATED multi-member stream (whose final member's CRC\n // cannot cover the whole output), would be accepted here and refused there.\n const declaredCrc =\n (data[n - 8]! | (data[n - 7]! << 8) | (data[n - 6]! << 16) | (data[n - 5]! << 24)) >>> 0;\n if (crc32(out) !== declaredCrc) {\n throw new EraSdkError('gzip-error', 'compressed payload is malformed: CRC mismatch');\n }\n return out;\n}\n","import { cborEncode } from '../cbor/encode';\nimport { asBytes, cbBytes, cbMap, cbText, mapGet } from '../cbor/model';\nimport { EraSdkError } from '../core/errors';\nimport { normalizeRequestId, uuidStringify } from '../core/rand';\nimport { normalizeXfp, parsePath, xfpToHex } from '../registry/keypath';\nimport { gunzipCapped, gzipCompress } from '../tron-proto/gzip';\nimport type { SignedTronTx, TronLatestBlock } from '../tron-proto/messages';\nimport {\n decodeSignResultProto,\n encodeSignRequestProto,\n splitSignedTronTx,\n} from '../tron-proto/messages';\nimport type { Ur } from '../ur/ur';\nimport { Ur as UrValue } from '../ur/ur';\nimport type { ChainContext, EraConnectConfig, ExpectedReply, SignRequest } from './shared';\nimport {\n makeSignRequest,\n requireReplyMap,\n requireUrType,\n resolveContext,\n resolveRequestId,\n toUr,\n} from './shared';\n\nexport type { TronLatestBlock } from '../tron-proto/messages';\n\nexport interface TronSignRequestProps {\n readonly requestId?: Uint8Array | string;\n /**\n * Serialized `Transaction.raw_data` — THE signing source of truth. The\n * device signs `sha256(rawData) = txID` and returns the transaction with\n * `raw_data` unmodified.\n */\n readonly rawData: Uint8Array;\n /** Full signing path, e.g. `m/44'/195'/0'/0/0`. */\n readonly path: string;\n readonly xfp: string | number;\n /**\n * Reference block context. Source it from a LIVE now-block query and pass\n * the FULL 64-hex block id.\n */\n readonly latestBlock: TronLatestBlock;\n /** On-device display only; safe to omit for opaque dApp transactions. */\n readonly display?: {\n readonly token?: string;\n readonly contractAddress?: string;\n readonly from?: string;\n readonly to?: string;\n readonly value?: string;\n readonly memo?: string;\n readonly fee?: number;\n readonly decimals?: number;\n };\n readonly timestamp?: number;\n readonly origin?: string;\n}\n\nexport interface TronSignatureResult {\n readonly requestId: Uint8Array;\n /** `sha256(raw_data)` hex, as computed by the device. */\n readonly txId: string;\n /** Hex of the fully assembled signed transaction — broadcast as-is. */\n readonly rawTx: string;\n /** The signed frame split into `raw_data` + signatures (65-byte r||s||recovery each). */\n readonly signedTx: SignedTronTx;\n}\n\n/**\n * Ceilings on the gzip blob a `keystone-sign-result` may carry. Tron is the\n * only chain whose reply is compressed, so it is the only one where a few\n * hundred scanned bytes can ask for an arbitrary allocation. Generous\n * multiples of the largest real device reply.\n */\nconst MAX_COMPRESSED_BYTES = 8 * 1024;\nconst MAX_INFLATED_BYTES = 64 * 1024;\n\nconst REPLY_TYPES = ['keystone-sign-result'] as const;\n\n/**\n * Tron signing rides the structured `keystone-sign-request` (6101) envelope —\n * a gzip-compressed protobuf inside CBOR `{1: gzip(protobuf), 2: origin}`.\n * The registry's generic `tron-sign-request` (5101) is NOT accepted by the\n * device and gets no response; do not emit it.\n */\nexport class TronChain {\n private readonly context: ChainContext;\n\n constructor(config?: EraConnectConfig) {\n this.context = resolveContext(config);\n }\n\n /** Build a `keystone-sign-request` (6101). Reply: `keystone-sign-result` (6102). */\n generateSignRequest(props: TronSignRequestProps): SignRequest<TronSignatureResult> {\n const requestId = resolveRequestId(this.context, props.requestId);\n parsePath(props.path); // validate shape; the wire carries the string form\n const xfp = normalizeXfp(props.xfp);\n if (props.rawData.length === 0) {\n throw new EraSdkError('invalid-props', 'rawData must not be empty');\n }\n if (!/^[0-9a-fA-F]{64}$/.test(props.latestBlock.hash)) {\n throw new EraSdkError(\n 'invalid-props',\n 'latestBlock.hash must be the FULL 64-hex block id (the device slices ref_block_hash from it)',\n );\n }\n\n const proto = encodeSignRequestProto({\n // Zero-padded to eight characters: the firmware parses this string with\n // a hex reader that yields 0 for anything shorter than 4 bytes, and a\n // zero fingerprint fails validation — a wallet whose fingerprint starts\n // with a zero byte (1 in 256) could not sign at all without the pad.\n xfpHex: xfpToHex(xfp),\n signId: uuidStringify(requestId),\n hdPath: props.path,\n timestamp: props.timestamp ?? 0,\n decimals: props.display?.decimals ?? 6,\n token: props.display?.token ?? '',\n contractAddress: props.display?.contractAddress,\n from: props.display?.from,\n to: props.display?.to,\n memo: props.display?.memo,\n value: props.display?.value,\n fee: props.display?.fee,\n latestBlock: props.latestBlock,\n rawData: props.rawData,\n });\n\n const ur = new UrValue(\n 'keystone-sign-request',\n cborEncode(\n cbMap([\n [1, cbBytes(gzipCompress(proto))],\n [2, cbText(props.origin ?? this.context.origin)],\n ]),\n ),\n );\n return makeSignRequest({\n ur,\n requestId,\n replyTypes: REPLY_TYPES,\n context: this.context,\n parse: (reply) => parseTronSignature(reply, requestId),\n });\n }\n\n /**\n * Parse a `keystone-sign-result` standalone. Tron carries the request id\n * INSIDE the protobuf (`signId`); passing `expect.requestId` is what makes\n * the echo check possible here — prefer `SignRequest.scanner().parse()`.\n */\n parseSignature(input: Ur | string, expect?: ExpectedReply): TronSignatureResult {\n return parseTronSignature(\n toUr(input),\n expect?.requestId === undefined ? undefined : normalizeRequestId(expect.requestId),\n );\n }\n}\n\nfunction parseTronSignature(\n ur: Ur,\n expectedRequestId: Uint8Array | undefined,\n): TronSignatureResult {\n requireUrType(ur, [...REPLY_TYPES], 'keystone-sign-result');\n const map = requireReplyMap(ur, 'keystone-sign-result');\n const compressed = asBytes(mapGet(map, 1));\n if (!compressed) {\n throw new EraSdkError('malformed-reply', 'keystone-sign-result is missing the payload (key 1)');\n }\n if (compressed.length > MAX_COMPRESSED_BYTES) {\n throw new EraSdkError(\n 'limit-exceeded',\n `keystone-sign-result payload is ${compressed.length} bytes, over the ${MAX_COMPRESSED_BYTES} byte ceiling`,\n );\n }\n const result = decodeSignResultProto(gunzipCapped(compressed, MAX_INFLATED_BYTES));\n\n // The signId echo is the ONLY anti-replay binding on this chain — the\n // device's own bytes are broadcast verbatim, so a stale reply that skipped\n // this check would finalize a payment the user did not approve now.\n if (expectedRequestId !== undefined) {\n const expected = uuidStringify(expectedRequestId).toLowerCase();\n if (result.signId.toLowerCase() !== expected) {\n throw new EraSdkError(\n 'request-id-mismatch',\n result.signId === ''\n ? 'keystone-sign-result does not echo the request id (signId)'\n : 'keystone-sign-result echoes a different request id — it answers another sign request, not this one',\n );\n }\n }\n if (result.rawTx === '') {\n throw new EraSdkError('malformed-reply', 'keystone-sign-result has no signed transaction');\n }\n const signedTx = splitSignedTronTx(result.rawTx);\n const requestId = expectedRequestId ?? signIdToBytes(result.signId);\n return { requestId, txId: result.txId, rawTx: result.rawTx, signedTx };\n}\n\nfunction signIdToBytes(signId: string): Uint8Array {\n try {\n return normalizeRequestId(signId);\n } catch {\n return new Uint8Array(16);\n }\n}\n"],"mappings":";;;;;AAMA,MAAM,iBAAiB;;AAGvB,MAAM,cAAc;;AAGpB,SAAgB,aAAa,MAA8B;CACzD,OAAO,SAAS,MAAM;EAAE,OAAO;EAAG,OAAO;CAAE,CAAC;AAC9C;;;;;;;;;;;;;;;AAgBA,SAAgB,aAAa,MAAkB,gBAAoC;CACjF,IAAI,KAAK,SAAS,gBAChB,MAAM,IAAI,YAAY,cAAc,qDAAqD;CAE3F,IAAI,KAAK,OAAO,MAAQ,KAAK,OAAO,KAClC,MAAM,IAAI,YAAY,cAAc,yCAAyC;CAE/E,MAAM,IAAI,KAAK;CACf,MAAM,SACH,KAAK,IAAI,KAAO,KAAK,IAAI,MAAO,IAAM,KAAK,IAAI,MAAO,KAAO,KAAK,IAAI,MAAO,QAAS;CACzF,IAAI,QAAQ,gBACV,MAAM,IAAI,YACR,cACA,+BAA+B,MAAM,mBAAmB,eAAe,cACzE;CAGF,MAAM,SAAuB,CAAC;CAC9B,IAAI,QAAQ;CACZ,IA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YACR,kBACA,mCAAmC,WAAW,OAAO,mBAAmB,qBAAqB,cAC/F;CAEF,MAAM,SAAS,sBAAsB,aAAa,YAAY,kBAAkB,CAAC;CAKjF,IAAI,sBAAsB,KAAA,GAAW;EACnC,MAAM,WAAW,cAAc,iBAAiB,CAAC,CAAC,YAAY;EAC9D,IAAI,OAAO,OAAO,YAAY,MAAM,UAClC,MAAM,IAAI,YACR,uBACA,OAAO,WAAW,KACd,+DACA,oGACN;CAEJ;CACA,IAAI,OAAO,UAAU,IACnB,MAAM,IAAI,YAAY,mBAAmB,gDAAgD;CAE3F,MAAM,WAAW,kBAAkB,OAAO,KAAK;CAE/C,OAAO;EAAE,WADS,qBAAqB,cAAc,OAAO,MAAM;EAC9C,MAAM,OAAO;EAAM,OAAO,OAAO;EAAO;CAAS;AACvE;AAEA,SAAS,cAAc,QAA4B;CACjD,IAAI;EACF,OAAO,mBAAmB,MAAM;CAClC,QAAQ;EACN,uBAAO,IAAI,WAAW,EAAE;CAC1B;AACF"}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
const require_shared = require("./shared-nISrEktU.cjs");
|
|
2
|
+
const require_messages = require("./messages-BzcdWlg1.cjs");
|
|
3
|
+
let fflate = require("fflate");
|
|
4
|
+
//#region src/tron-proto/gzip.ts
|
|
5
|
+
/** Smallest possible gzip stream: 10-byte header + 8-byte trailer. */
|
|
6
|
+
const MIN_GZIP_BYTES = 18;
|
|
7
|
+
/** Bytes fed to the inflater per step; bounds the overshoot past the cap. */
|
|
8
|
+
const SLICE_BYTES = 1024;
|
|
9
|
+
/** Deterministic gzip (fixed level, zeroed mtime) for reproducible request bytes. */
|
|
10
|
+
function gzipCompress(data) {
|
|
11
|
+
return (0, fflate.gzipSync)(data, {
|
|
12
|
+
level: 9,
|
|
13
|
+
mtime: 0
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Inflate with a hard output ceiling.
|
|
18
|
+
*
|
|
19
|
+
* A one-shot gunzip allocates the entire output before anyone can refuse it —
|
|
20
|
+
* gzip reaches ~1000:1 in practice, so a few hundred scanned bytes could ask
|
|
21
|
+
* for an arbitrary allocation. The decoder is therefore driven in slices and
|
|
22
|
+
* the output counted as it arrives; the moment the total would pass the cap,
|
|
23
|
+
* feeding stops and the reply is refused.
|
|
24
|
+
*
|
|
25
|
+
* The trailer's ISIZE (declared inflated length) is used twice: as a cheap
|
|
26
|
+
* refusal of honest bombs before any work, and as a truncation check at the
|
|
27
|
+
* end — an inflater hands back a partial buffer for a truncated stream
|
|
28
|
+
* without erroring, and a genuine device reply always declares honestly.
|
|
29
|
+
*/
|
|
30
|
+
function gunzipCapped(data, maxOutputBytes) {
|
|
31
|
+
if (data.length < MIN_GZIP_BYTES) throw new require_shared.EraSdkError("gzip-error", "compressed payload is too short to be a gzip stream");
|
|
32
|
+
if (data[0] !== 31 || data[1] !== 139) throw new require_shared.EraSdkError("gzip-error", "compressed payload is not a gzip stream");
|
|
33
|
+
const n = data.length;
|
|
34
|
+
const isize = (data[n - 4] | data[n - 3] << 8 | data[n - 2] << 16 | data[n - 1] << 24) >>> 0;
|
|
35
|
+
if (isize > maxOutputBytes) throw new require_shared.EraSdkError("gzip-error", `compressed payload declares ${isize} bytes, over the ${maxOutputBytes} byte ceiling`);
|
|
36
|
+
const chunks = [];
|
|
37
|
+
let total = 0;
|
|
38
|
+
let overflowed = false;
|
|
39
|
+
let malformed = null;
|
|
40
|
+
const gunzip = new fflate.Gunzip((chunk) => {
|
|
41
|
+
if (overflowed) return;
|
|
42
|
+
if (total + chunk.length > maxOutputBytes) {
|
|
43
|
+
overflowed = true;
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
chunks.push(chunk);
|
|
47
|
+
total += chunk.length;
|
|
48
|
+
});
|
|
49
|
+
try {
|
|
50
|
+
for (let offset = 0; offset < n && !overflowed; offset += SLICE_BYTES) {
|
|
51
|
+
const end = Math.min(offset + SLICE_BYTES, n);
|
|
52
|
+
const isLast = end === n;
|
|
53
|
+
gunzip.push(data.slice(offset, end), isLast);
|
|
54
|
+
}
|
|
55
|
+
} catch (e) {
|
|
56
|
+
malformed = e.message ?? "inflate error";
|
|
57
|
+
}
|
|
58
|
+
if (overflowed) throw new require_shared.EraSdkError("gzip-error", `compressed payload inflates past the ${maxOutputBytes} byte ceiling`);
|
|
59
|
+
if (malformed !== null) throw new require_shared.EraSdkError("gzip-error", `compressed payload is malformed: ${malformed}`);
|
|
60
|
+
const out = require_shared.concatBytes(...chunks);
|
|
61
|
+
if (out.length !== isize) throw new require_shared.EraSdkError("gzip-error", `compressed payload inflated to ${out.length} bytes but declares ${isize} — truncated or malformed`);
|
|
62
|
+
const declaredCrc = (data[n - 8] | data[n - 7] << 8 | data[n - 6] << 16 | data[n - 5] << 24) >>> 0;
|
|
63
|
+
if (require_shared.crc32(out) !== declaredCrc) throw new require_shared.EraSdkError("gzip-error", "compressed payload is malformed: CRC mismatch");
|
|
64
|
+
return out;
|
|
65
|
+
}
|
|
66
|
+
//#endregion
|
|
67
|
+
//#region src/chains/tron.ts
|
|
68
|
+
/**
|
|
69
|
+
* Ceilings on the gzip blob a `keystone-sign-result` may carry. Tron is the
|
|
70
|
+
* only chain whose reply is compressed, so it is the only one where a few
|
|
71
|
+
* hundred scanned bytes can ask for an arbitrary allocation. Generous
|
|
72
|
+
* multiples of the largest real device reply.
|
|
73
|
+
*/
|
|
74
|
+
const MAX_COMPRESSED_BYTES = 8192;
|
|
75
|
+
const MAX_INFLATED_BYTES = 65536;
|
|
76
|
+
const REPLY_TYPES = ["keystone-sign-result"];
|
|
77
|
+
/**
|
|
78
|
+
* Tron signing rides the structured `keystone-sign-request` (6101) envelope —
|
|
79
|
+
* a gzip-compressed protobuf inside CBOR `{1: gzip(protobuf), 2: origin}`.
|
|
80
|
+
* The registry's generic `tron-sign-request` (5101) is NOT accepted by the
|
|
81
|
+
* device and gets no response; do not emit it.
|
|
82
|
+
*/
|
|
83
|
+
var TronChain = class {
|
|
84
|
+
constructor(config) {
|
|
85
|
+
this.context = require_shared.resolveContext(config);
|
|
86
|
+
}
|
|
87
|
+
/** Build a `keystone-sign-request` (6101). Reply: `keystone-sign-result` (6102). */
|
|
88
|
+
generateSignRequest(props) {
|
|
89
|
+
const requestId = require_shared.resolveRequestId(this.context, props.requestId);
|
|
90
|
+
require_shared.parsePath(props.path);
|
|
91
|
+
const xfp = require_shared.normalizeXfp(props.xfp);
|
|
92
|
+
if (props.rawData.length === 0) throw new require_shared.EraSdkError("invalid-props", "rawData must not be empty");
|
|
93
|
+
if (!/^[0-9a-fA-F]{64}$/.test(props.latestBlock.hash)) throw new require_shared.EraSdkError("invalid-props", "latestBlock.hash must be the FULL 64-hex block id (the device slices ref_block_hash from it)");
|
|
94
|
+
const proto = require_messages.encodeSignRequestProto({
|
|
95
|
+
xfpHex: require_shared.xfpToHex(xfp),
|
|
96
|
+
signId: require_shared.uuidStringify(requestId),
|
|
97
|
+
hdPath: props.path,
|
|
98
|
+
timestamp: props.timestamp ?? 0,
|
|
99
|
+
decimals: props.display?.decimals ?? 6,
|
|
100
|
+
token: props.display?.token ?? "",
|
|
101
|
+
contractAddress: props.display?.contractAddress,
|
|
102
|
+
from: props.display?.from,
|
|
103
|
+
to: props.display?.to,
|
|
104
|
+
memo: props.display?.memo,
|
|
105
|
+
value: props.display?.value,
|
|
106
|
+
fee: props.display?.fee,
|
|
107
|
+
latestBlock: props.latestBlock,
|
|
108
|
+
rawData: props.rawData
|
|
109
|
+
});
|
|
110
|
+
const ur = new require_shared.Ur("keystone-sign-request", require_shared.cborEncode(require_shared.cbMap([[1, require_shared.cbBytes(gzipCompress(proto))], [2, require_shared.cbText(props.origin ?? this.context.origin)]])));
|
|
111
|
+
return require_shared.makeSignRequest({
|
|
112
|
+
ur,
|
|
113
|
+
requestId,
|
|
114
|
+
replyTypes: REPLY_TYPES,
|
|
115
|
+
context: this.context,
|
|
116
|
+
parse: (reply) => parseTronSignature(reply, requestId)
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Parse a `keystone-sign-result` standalone. Tron carries the request id
|
|
121
|
+
* INSIDE the protobuf (`signId`); passing `expect.requestId` is what makes
|
|
122
|
+
* the echo check possible here — prefer `SignRequest.scanner().parse()`.
|
|
123
|
+
*/
|
|
124
|
+
parseSignature(input, expect) {
|
|
125
|
+
return parseTronSignature(require_shared.toUr(input), expect?.requestId === void 0 ? void 0 : require_shared.normalizeRequestId(expect.requestId));
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
function parseTronSignature(ur, expectedRequestId) {
|
|
129
|
+
require_shared.requireUrType(ur, [...REPLY_TYPES], "keystone-sign-result");
|
|
130
|
+
const map = require_shared.requireReplyMap(ur, "keystone-sign-result");
|
|
131
|
+
const compressed = require_shared.asBytes(require_shared.mapGet(map, 1));
|
|
132
|
+
if (!compressed) throw new require_shared.EraSdkError("malformed-reply", "keystone-sign-result is missing the payload (key 1)");
|
|
133
|
+
if (compressed.length > MAX_COMPRESSED_BYTES) throw new require_shared.EraSdkError("limit-exceeded", `keystone-sign-result payload is ${compressed.length} bytes, over the ${MAX_COMPRESSED_BYTES} byte ceiling`);
|
|
134
|
+
const result = require_messages.decodeSignResultProto(gunzipCapped(compressed, MAX_INFLATED_BYTES));
|
|
135
|
+
if (expectedRequestId !== void 0) {
|
|
136
|
+
const expected = require_shared.uuidStringify(expectedRequestId).toLowerCase();
|
|
137
|
+
if (result.signId.toLowerCase() !== expected) throw new require_shared.EraSdkError("request-id-mismatch", result.signId === "" ? "keystone-sign-result does not echo the request id (signId)" : "keystone-sign-result echoes a different request id — it answers another sign request, not this one");
|
|
138
|
+
}
|
|
139
|
+
if (result.rawTx === "") throw new require_shared.EraSdkError("malformed-reply", "keystone-sign-result has no signed transaction");
|
|
140
|
+
const signedTx = require_messages.splitSignedTronTx(result.rawTx);
|
|
141
|
+
return {
|
|
142
|
+
requestId: expectedRequestId ?? signIdToBytes(result.signId),
|
|
143
|
+
txId: result.txId,
|
|
144
|
+
rawTx: result.rawTx,
|
|
145
|
+
signedTx
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
function signIdToBytes(signId) {
|
|
149
|
+
try {
|
|
150
|
+
return require_shared.normalizeRequestId(signId);
|
|
151
|
+
} catch {
|
|
152
|
+
return /* @__PURE__ */ new Uint8Array(16);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
//#endregion
|
|
156
|
+
Object.defineProperty(exports, "TronChain", {
|
|
157
|
+
enumerable: true,
|
|
158
|
+
get: function() {
|
|
159
|
+
return TronChain;
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
//# sourceMappingURL=tron-CQIEqjCA.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tron-CQIEqjCA.cjs","names":["gzipSync","EraSdkError","Gunzip","concatBytes","crc32","resolveContext","resolveRequestId","normalizeXfp","EraSdkError","encodeSignRequestProto","xfpToHex","uuidStringify","UrValue","cborEncode","cbMap","cbBytes","cbText","makeSignRequest","toUr","normalizeRequestId","requireReplyMap","asBytes","mapGet","decodeSignResultProto","splitSignedTronTx"],"sources":["../src/tron-proto/gzip.ts","../src/chains/tron.ts"],"sourcesContent":["import { Gunzip, gzipSync } from 'fflate';\nimport { concatBytes } from '../core/bytes';\nimport { EraSdkError } from '../core/errors';\nimport { crc32 } from '../ur/crc32';\n\n/** Smallest possible gzip stream: 10-byte header + 8-byte trailer. */\nconst MIN_GZIP_BYTES = 18;\n\n/** Bytes fed to the inflater per step; bounds the overshoot past the cap. */\nconst SLICE_BYTES = 1024;\n\n/** Deterministic gzip (fixed level, zeroed mtime) for reproducible request bytes. */\nexport function gzipCompress(data: Uint8Array): Uint8Array {\n return gzipSync(data, { level: 9, mtime: 0 });\n}\n\n/**\n * Inflate with a hard output ceiling.\n *\n * A one-shot gunzip allocates the entire output before anyone can refuse it —\n * gzip reaches ~1000:1 in practice, so a few hundred scanned bytes could ask\n * for an arbitrary allocation. The decoder is therefore driven in slices and\n * the output counted as it arrives; the moment the total would pass the cap,\n * feeding stops and the reply is refused.\n *\n * The trailer's ISIZE (declared inflated length) is used twice: as a cheap\n * refusal of honest bombs before any work, and as a truncation check at the\n * end — an inflater hands back a partial buffer for a truncated stream\n * without erroring, and a genuine device reply always declares honestly.\n */\nexport function gunzipCapped(data: Uint8Array, maxOutputBytes: number): Uint8Array {\n if (data.length < MIN_GZIP_BYTES) {\n throw new EraSdkError('gzip-error', 'compressed payload is too short to be a gzip stream');\n }\n if (data[0] !== 0x1f || data[1] !== 0x8b) {\n throw new EraSdkError('gzip-error', 'compressed payload is not a gzip stream');\n }\n const n = data.length;\n const isize =\n (data[n - 4]! | (data[n - 3]! << 8) | (data[n - 2]! << 16) | (data[n - 1]! << 24)) >>> 0;\n if (isize > maxOutputBytes) {\n throw new EraSdkError(\n 'gzip-error',\n `compressed payload declares ${isize} bytes, over the ${maxOutputBytes} byte ceiling`,\n );\n }\n\n const chunks: Uint8Array[] = [];\n let total = 0;\n let overflowed = false;\n let malformed: string | null = null;\n\n const gunzip = new Gunzip((chunk) => {\n if (overflowed) return;\n if (total + chunk.length > maxOutputBytes) {\n overflowed = true;\n return;\n }\n chunks.push(chunk);\n total += chunk.length;\n });\n\n try {\n for (let offset = 0; offset < n && !overflowed; offset += SLICE_BYTES) {\n const end = Math.min(offset + SLICE_BYTES, n);\n const isLast = end === n;\n gunzip.push(data.slice(offset, end), isLast);\n }\n } catch (e) {\n malformed = (e as Error).message ?? 'inflate error';\n }\n\n if (overflowed) {\n throw new EraSdkError(\n 'gzip-error',\n `compressed payload inflates past the ${maxOutputBytes} byte ceiling`,\n );\n }\n if (malformed !== null) {\n throw new EraSdkError('gzip-error', `compressed payload is malformed: ${malformed}`);\n }\n const out = concatBytes(...chunks);\n if (out.length !== isize) {\n throw new EraSdkError(\n 'gzip-error',\n `compressed payload inflated to ${out.length} bytes but declares ${isize} — truncated or malformed`,\n );\n }\n // The trailer CRC32 (little-endian, bytes n-8..n-5) must cover the inflated\n // output. The streaming inflater does not verify it, and the reference\n // implementation's native decoder does — without this check a corrupted\n // stream, or a CONCATENATED multi-member stream (whose final member's CRC\n // cannot cover the whole output), would be accepted here and refused there.\n const declaredCrc =\n (data[n - 8]! | (data[n - 7]! << 8) | (data[n - 6]! << 16) | (data[n - 5]! << 24)) >>> 0;\n if (crc32(out) !== declaredCrc) {\n throw new EraSdkError('gzip-error', 'compressed payload is malformed: CRC mismatch');\n }\n return out;\n}\n","import { cborEncode } from '../cbor/encode';\nimport { asBytes, cbBytes, cbMap, cbText, mapGet } from '../cbor/model';\nimport { EraSdkError } from '../core/errors';\nimport { normalizeRequestId, uuidStringify } from '../core/rand';\nimport { normalizeXfp, parsePath, xfpToHex } from '../registry/keypath';\nimport { gunzipCapped, gzipCompress } from '../tron-proto/gzip';\nimport type { SignedTronTx, TronLatestBlock } from '../tron-proto/messages';\nimport {\n decodeSignResultProto,\n encodeSignRequestProto,\n splitSignedTronTx,\n} from '../tron-proto/messages';\nimport type { Ur } from '../ur/ur';\nimport { Ur as UrValue } from '../ur/ur';\nimport type { ChainContext, EraConnectConfig, ExpectedReply, SignRequest } from './shared';\nimport {\n makeSignRequest,\n requireReplyMap,\n requireUrType,\n resolveContext,\n resolveRequestId,\n toUr,\n} from './shared';\n\nexport type { TronLatestBlock } from '../tron-proto/messages';\n\nexport interface TronSignRequestProps {\n readonly requestId?: Uint8Array | string;\n /**\n * Serialized `Transaction.raw_data` — THE signing source of truth. The\n * device signs `sha256(rawData) = txID` and returns the transaction with\n * `raw_data` unmodified.\n */\n readonly rawData: Uint8Array;\n /** Full signing path, e.g. `m/44'/195'/0'/0/0`. */\n readonly path: string;\n readonly xfp: string | number;\n /**\n * Reference block context. Source it from a LIVE now-block query and pass\n * the FULL 64-hex block id.\n */\n readonly latestBlock: TronLatestBlock;\n /** On-device display only; safe to omit for opaque dApp transactions. */\n readonly display?: {\n readonly token?: string;\n readonly contractAddress?: string;\n readonly from?: string;\n readonly to?: string;\n readonly value?: string;\n readonly memo?: string;\n readonly fee?: number;\n readonly decimals?: number;\n };\n readonly timestamp?: number;\n readonly origin?: string;\n}\n\nexport interface TronSignatureResult {\n readonly requestId: Uint8Array;\n /** `sha256(raw_data)` hex, as computed by the device. */\n readonly txId: string;\n /** Hex of the fully assembled signed transaction — broadcast as-is. */\n readonly rawTx: string;\n /** The signed frame split into `raw_data` + signatures (65-byte r||s||recovery each). */\n readonly signedTx: SignedTronTx;\n}\n\n/**\n * Ceilings on the gzip blob a `keystone-sign-result` may carry. Tron is the\n * only chain whose reply is compressed, so it is the only one where a few\n * hundred scanned bytes can ask for an arbitrary allocation. Generous\n * multiples of the largest real device reply.\n */\nconst MAX_COMPRESSED_BYTES = 8 * 1024;\nconst MAX_INFLATED_BYTES = 64 * 1024;\n\nconst REPLY_TYPES = ['keystone-sign-result'] as const;\n\n/**\n * Tron signing rides the structured `keystone-sign-request` (6101) envelope —\n * a gzip-compressed protobuf inside CBOR `{1: gzip(protobuf), 2: origin}`.\n * The registry's generic `tron-sign-request` (5101) is NOT accepted by the\n * device and gets no response; do not emit it.\n */\nexport class TronChain {\n private readonly context: ChainContext;\n\n constructor(config?: EraConnectConfig) {\n this.context = resolveContext(config);\n }\n\n /** Build a `keystone-sign-request` (6101). Reply: `keystone-sign-result` (6102). */\n generateSignRequest(props: TronSignRequestProps): SignRequest<TronSignatureResult> {\n const requestId = resolveRequestId(this.context, props.requestId);\n parsePath(props.path); // validate shape; the wire carries the string form\n const xfp = normalizeXfp(props.xfp);\n if (props.rawData.length === 0) {\n throw new EraSdkError('invalid-props', 'rawData must not be empty');\n }\n if (!/^[0-9a-fA-F]{64}$/.test(props.latestBlock.hash)) {\n throw new EraSdkError(\n 'invalid-props',\n 'latestBlock.hash must be the FULL 64-hex block id (the device slices ref_block_hash from it)',\n );\n }\n\n const proto = encodeSignRequestProto({\n // Zero-padded to eight characters: the firmware parses this string with\n // a hex reader that yields 0 for anything shorter than 4 bytes, and a\n // zero fingerprint fails validation — a wallet whose fingerprint starts\n // with a zero byte (1 in 256) could not sign at all without the pad.\n xfpHex: xfpToHex(xfp),\n signId: uuidStringify(requestId),\n hdPath: props.path,\n timestamp: props.timestamp ?? 0,\n decimals: props.display?.decimals ?? 6,\n token: props.display?.token ?? '',\n contractAddress: props.display?.contractAddress,\n from: props.display?.from,\n to: props.display?.to,\n memo: props.display?.memo,\n value: props.display?.value,\n fee: props.display?.fee,\n latestBlock: props.latestBlock,\n rawData: props.rawData,\n });\n\n const ur = new UrValue(\n 'keystone-sign-request',\n cborEncode(\n cbMap([\n [1, cbBytes(gzipCompress(proto))],\n [2, cbText(props.origin ?? this.context.origin)],\n ]),\n ),\n );\n return makeSignRequest({\n ur,\n requestId,\n replyTypes: REPLY_TYPES,\n context: this.context,\n parse: (reply) => parseTronSignature(reply, requestId),\n });\n }\n\n /**\n * Parse a `keystone-sign-result` standalone. Tron carries the request id\n * INSIDE the protobuf (`signId`); passing `expect.requestId` is what makes\n * the echo check possible here — prefer `SignRequest.scanner().parse()`.\n */\n parseSignature(input: Ur | string, expect?: ExpectedReply): TronSignatureResult {\n return parseTronSignature(\n toUr(input),\n expect?.requestId === undefined ? undefined : normalizeRequestId(expect.requestId),\n );\n }\n}\n\nfunction parseTronSignature(\n ur: Ur,\n expectedRequestId: Uint8Array | undefined,\n): TronSignatureResult {\n requireUrType(ur, [...REPLY_TYPES], 'keystone-sign-result');\n const map = requireReplyMap(ur, 'keystone-sign-result');\n const compressed = asBytes(mapGet(map, 1));\n if (!compressed) {\n throw new EraSdkError('malformed-reply', 'keystone-sign-result is missing the payload (key 1)');\n }\n if (compressed.length > MAX_COMPRESSED_BYTES) {\n throw new EraSdkError(\n 'limit-exceeded',\n `keystone-sign-result payload is ${compressed.length} bytes, over the ${MAX_COMPRESSED_BYTES} byte ceiling`,\n );\n }\n const result = decodeSignResultProto(gunzipCapped(compressed, MAX_INFLATED_BYTES));\n\n // The signId echo is the ONLY anti-replay binding on this chain — the\n // device's own bytes are broadcast verbatim, so a stale reply that skipped\n // this check would finalize a payment the user did not approve now.\n if (expectedRequestId !== undefined) {\n const expected = uuidStringify(expectedRequestId).toLowerCase();\n if (result.signId.toLowerCase() !== expected) {\n throw new EraSdkError(\n 'request-id-mismatch',\n result.signId === ''\n ? 'keystone-sign-result does not echo the request id (signId)'\n : 'keystone-sign-result echoes a different request id — it answers another sign request, not this one',\n );\n }\n }\n if (result.rawTx === '') {\n throw new EraSdkError('malformed-reply', 'keystone-sign-result has no signed transaction');\n }\n const signedTx = splitSignedTronTx(result.rawTx);\n const requestId = expectedRequestId ?? signIdToBytes(result.signId);\n return { requestId, txId: result.txId, rawTx: result.rawTx, signedTx };\n}\n\nfunction signIdToBytes(signId: string): Uint8Array {\n try {\n return normalizeRequestId(signId);\n } catch {\n return new Uint8Array(16);\n }\n}\n"],"mappings":";;;;;AAMA,MAAM,iBAAiB;;AAGvB,MAAM,cAAc;;AAGpB,SAAgB,aAAa,MAA8B;CACzD,QAAA,GAAOA,OAAAA,SAAAA,CAAS,MAAM;EAAE,OAAO;EAAG,OAAO;CAAE,CAAC;AAC9C;;;;;;;;;;;;;;;AAgBA,SAAgB,aAAa,MAAkB,gBAAoC;CACjF,IAAI,KAAK,SAAS,gBAChB,MAAM,IAAIC,eAAAA,YAAY,cAAc,qDAAqD;CAE3F,IAAI,KAAK,OAAO,MAAQ,KAAK,OAAO,KAClC,MAAM,IAAIA,eAAAA,YAAY,cAAc,yCAAyC;CAE/E,MAAM,IAAI,KAAK;CACf,MAAM,SACH,KAAK,IAAI,KAAO,KAAK,IAAI,MAAO,IAAM,KAAK,IAAI,MAAO,KAAO,KAAK,IAAI,MAAO,QAAS;CACzF,IAAI,QAAQ,gBACV,MAAM,IAAIA,eAAAA,YACR,cACA,+BAA+B,MAAM,mBAAmB,eAAe,cACzE;CAGF,MAAM,SAAuB,CAAC;CAC9B,IAAI,QAAQ;CACZ,IAAI,aAAa;CACjB,IAAI,YAA2B;CAE/B,MAAM,SAAS,IAAIC,OAA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tD,MAAM,aAAaC,eAAAA,QAAQC,eAAAA,OAAO,KAAK,CAAC,CAAC;CACzC,IAAI,CAAC,YACH,MAAM,IAAId,eAAAA,YAAY,mBAAmB,qDAAqD;CAEhG,IAAI,WAAW,SAAS,sBACtB,MAAM,IAAIA,eAAAA,YACR,kBACA,mCAAmC,WAAW,OAAO,mBAAmB,qBAAqB,cAC/F;CAEF,MAAM,SAASe,iBAAAA,sBAAsB,aAAa,YAAY,kBAAkB,CAAC;CAKjF,IAAI,sBAAsB,KAAA,GAAW;EACnC,MAAM,WAAWZ,eAAAA,cAAc,iBAAiB,CAAC,CAAC,YAAY;EAC9D,IAAI,OAAO,OAAO,YAAY,MAAM,UAClC,MAAM,IAAIH,eAAAA,YACR,uBACA,OAAO,WAAW,KACd,+DACA,oGACN;CAEJ;CACA,IAAI,OAAO,UAAU,IACnB,MAAM,IAAIA,eAAAA,YAAY,mBAAmB,gDAAgD;CAE3F,MAAM,WAAWgB,iBAAAA,kBAAkB,OAAO,KAAK;CAE/C,OAAO;EAAE,WADS,qBAAqB,cAAc,OAAO,MAAM;EAC9C,MAAM,OAAO;EAAM,OAAO,OAAO;EAAO;CAAS;AACvE;AAEA,SAAS,cAAc,QAA4B;CACjD,IAAI;EACF,OAAOL,eAAAA,mBAAmB,MAAM;CAClC,QAAQ;EACN,uBAAO,IAAI,WAAW,EAAE;CAC1B;AACF"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { _ as Ur, a as SignRequest, i as ExpectedReply, r as EraConnectConfig } from "./shared-CI8zhQiE.js";
|
|
2
|
+
import { n as TronLatestBlock, t as SignedTronTx } from "./messages-DsPvW8Oi.js";
|
|
3
|
+
//#region src/chains/tron.d.ts
|
|
4
|
+
interface TronSignRequestProps {
|
|
5
|
+
readonly requestId?: Uint8Array | string;
|
|
6
|
+
/**
|
|
7
|
+
* Serialized `Transaction.raw_data` — THE signing source of truth. The
|
|
8
|
+
* device signs `sha256(rawData) = txID` and returns the transaction with
|
|
9
|
+
* `raw_data` unmodified.
|
|
10
|
+
*/
|
|
11
|
+
readonly rawData: Uint8Array;
|
|
12
|
+
/** Full signing path, e.g. `m/44'/195'/0'/0/0`. */
|
|
13
|
+
readonly path: string;
|
|
14
|
+
readonly xfp: string | number;
|
|
15
|
+
/**
|
|
16
|
+
* Reference block context. Source it from a LIVE now-block query and pass
|
|
17
|
+
* the FULL 64-hex block id.
|
|
18
|
+
*/
|
|
19
|
+
readonly latestBlock: TronLatestBlock;
|
|
20
|
+
/** On-device display only; safe to omit for opaque dApp transactions. */
|
|
21
|
+
readonly display?: {
|
|
22
|
+
readonly token?: string;
|
|
23
|
+
readonly contractAddress?: string;
|
|
24
|
+
readonly from?: string;
|
|
25
|
+
readonly to?: string;
|
|
26
|
+
readonly value?: string;
|
|
27
|
+
readonly memo?: string;
|
|
28
|
+
readonly fee?: number;
|
|
29
|
+
readonly decimals?: number;
|
|
30
|
+
};
|
|
31
|
+
readonly timestamp?: number;
|
|
32
|
+
readonly origin?: string;
|
|
33
|
+
}
|
|
34
|
+
interface TronSignatureResult {
|
|
35
|
+
readonly requestId: Uint8Array;
|
|
36
|
+
/** `sha256(raw_data)` hex, as computed by the device. */
|
|
37
|
+
readonly txId: string;
|
|
38
|
+
/** Hex of the fully assembled signed transaction — broadcast as-is. */
|
|
39
|
+
readonly rawTx: string;
|
|
40
|
+
/** The signed frame split into `raw_data` + signatures (65-byte r||s||recovery each). */
|
|
41
|
+
readonly signedTx: SignedTronTx;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Tron signing rides the structured `keystone-sign-request` (6101) envelope —
|
|
45
|
+
* a gzip-compressed protobuf inside CBOR `{1: gzip(protobuf), 2: origin}`.
|
|
46
|
+
* The registry's generic `tron-sign-request` (5101) is NOT accepted by the
|
|
47
|
+
* device and gets no response; do not emit it.
|
|
48
|
+
*/
|
|
49
|
+
declare class TronChain {
|
|
50
|
+
private readonly context;
|
|
51
|
+
constructor(config?: EraConnectConfig);
|
|
52
|
+
/** Build a `keystone-sign-request` (6101). Reply: `keystone-sign-result` (6102). */
|
|
53
|
+
generateSignRequest(props: TronSignRequestProps): SignRequest<TronSignatureResult>;
|
|
54
|
+
/**
|
|
55
|
+
* Parse a `keystone-sign-result` standalone. Tron carries the request id
|
|
56
|
+
* INSIDE the protobuf (`signId`); passing `expect.requestId` is what makes
|
|
57
|
+
* the echo check possible here — prefer `SignRequest.scanner().parse()`.
|
|
58
|
+
*/
|
|
59
|
+
parseSignature(input: Ur | string, expect?: ExpectedReply): TronSignatureResult;
|
|
60
|
+
}
|
|
61
|
+
//#endregion
|
|
62
|
+
export { TronSignRequestProps as n, TronSignatureResult as r, TronChain as t };
|
|
63
|
+
//# sourceMappingURL=tron-YllfTmx6.d.ts.map
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { _ as Ur, a as SignRequest, i as ExpectedReply, r as EraConnectConfig } from "./shared-CI8zhQiE.cjs";
|
|
2
|
+
import { n as TronLatestBlock, t as SignedTronTx } from "./messages-DsPvW8Oi.cjs";
|
|
3
|
+
//#region src/chains/tron.d.ts
|
|
4
|
+
interface TronSignRequestProps {
|
|
5
|
+
readonly requestId?: Uint8Array | string;
|
|
6
|
+
/**
|
|
7
|
+
* Serialized `Transaction.raw_data` — THE signing source of truth. The
|
|
8
|
+
* device signs `sha256(rawData) = txID` and returns the transaction with
|
|
9
|
+
* `raw_data` unmodified.
|
|
10
|
+
*/
|
|
11
|
+
readonly rawData: Uint8Array;
|
|
12
|
+
/** Full signing path, e.g. `m/44'/195'/0'/0/0`. */
|
|
13
|
+
readonly path: string;
|
|
14
|
+
readonly xfp: string | number;
|
|
15
|
+
/**
|
|
16
|
+
* Reference block context. Source it from a LIVE now-block query and pass
|
|
17
|
+
* the FULL 64-hex block id.
|
|
18
|
+
*/
|
|
19
|
+
readonly latestBlock: TronLatestBlock;
|
|
20
|
+
/** On-device display only; safe to omit for opaque dApp transactions. */
|
|
21
|
+
readonly display?: {
|
|
22
|
+
readonly token?: string;
|
|
23
|
+
readonly contractAddress?: string;
|
|
24
|
+
readonly from?: string;
|
|
25
|
+
readonly to?: string;
|
|
26
|
+
readonly value?: string;
|
|
27
|
+
readonly memo?: string;
|
|
28
|
+
readonly fee?: number;
|
|
29
|
+
readonly decimals?: number;
|
|
30
|
+
};
|
|
31
|
+
readonly timestamp?: number;
|
|
32
|
+
readonly origin?: string;
|
|
33
|
+
}
|
|
34
|
+
interface TronSignatureResult {
|
|
35
|
+
readonly requestId: Uint8Array;
|
|
36
|
+
/** `sha256(raw_data)` hex, as computed by the device. */
|
|
37
|
+
readonly txId: string;
|
|
38
|
+
/** Hex of the fully assembled signed transaction — broadcast as-is. */
|
|
39
|
+
readonly rawTx: string;
|
|
40
|
+
/** The signed frame split into `raw_data` + signatures (65-byte r||s||recovery each). */
|
|
41
|
+
readonly signedTx: SignedTronTx;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Tron signing rides the structured `keystone-sign-request` (6101) envelope —
|
|
45
|
+
* a gzip-compressed protobuf inside CBOR `{1: gzip(protobuf), 2: origin}`.
|
|
46
|
+
* The registry's generic `tron-sign-request` (5101) is NOT accepted by the
|
|
47
|
+
* device and gets no response; do not emit it.
|
|
48
|
+
*/
|
|
49
|
+
declare class TronChain {
|
|
50
|
+
private readonly context;
|
|
51
|
+
constructor(config?: EraConnectConfig);
|
|
52
|
+
/** Build a `keystone-sign-request` (6101). Reply: `keystone-sign-result` (6102). */
|
|
53
|
+
generateSignRequest(props: TronSignRequestProps): SignRequest<TronSignatureResult>;
|
|
54
|
+
/**
|
|
55
|
+
* Parse a `keystone-sign-result` standalone. Tron carries the request id
|
|
56
|
+
* INSIDE the protobuf (`signId`); passing `expect.requestId` is what makes
|
|
57
|
+
* the echo check possible here — prefer `SignRequest.scanner().parse()`.
|
|
58
|
+
*/
|
|
59
|
+
parseSignature(input: Ur | string, expect?: ExpectedReply): TronSignatureResult;
|
|
60
|
+
}
|
|
61
|
+
//#endregion
|
|
62
|
+
export { TronSignRequestProps as n, TronSignatureResult as r, TronChain as t };
|
|
63
|
+
//# sourceMappingURL=tron-gG51KMnX.d.cts.map
|
package/dist/tron.cjs
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_shared = require("./shared-nISrEktU.cjs");
|
|
3
|
+
const require_tron = require("./tron-CQIEqjCA.cjs");
|
|
4
|
+
const require_messages = require("./messages-BzcdWlg1.cjs");
|
|
5
|
+
exports.AnimatedUr = require_shared.AnimatedUr;
|
|
6
|
+
exports.EraSdkError = require_shared.EraSdkError;
|
|
7
|
+
exports.TronChain = require_tron.TronChain;
|
|
8
|
+
exports.TypedUrScanner = require_shared.TypedUrScanner;
|
|
9
|
+
exports.Ur = require_shared.Ur;
|
|
10
|
+
exports.UrScanner = require_shared.UrScanner;
|
|
11
|
+
exports.splitSignedTronTx = require_messages.splitSignedTronTx;
|
package/dist/tron.d.cts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { _ as Ur, a as SignRequest, c as TypedUrScanner, d as EraErrorCode, f as EraSdkError, i as ExpectedReply, l as UrScanner, p as AnimatedUr, r as EraConnectConfig } from "./shared-CI8zhQiE.cjs";
|
|
2
|
+
import { n as TronLatestBlock, r as splitSignedTronTx, t as SignedTronTx } from "./messages-DsPvW8Oi.cjs";
|
|
3
|
+
import { n as TronSignRequestProps, r as TronSignatureResult, t as TronChain } from "./tron-gG51KMnX.cjs";
|
|
4
|
+
export { AnimatedUr, type EraConnectConfig, type EraErrorCode, EraSdkError, type ExpectedReply, type SignRequest, type SignedTronTx, TronChain, type TronLatestBlock, type TronSignRequestProps, type TronSignatureResult, TypedUrScanner, Ur, UrScanner, splitSignedTronTx };
|
package/dist/tron.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { _ as Ur, a as SignRequest, c as TypedUrScanner, d as EraErrorCode, f as EraSdkError, i as ExpectedReply, l as UrScanner, p as AnimatedUr, r as EraConnectConfig } from "./shared-CI8zhQiE.js";
|
|
2
|
+
import { n as TronLatestBlock, r as splitSignedTronTx, t as SignedTronTx } from "./messages-DsPvW8Oi.js";
|
|
3
|
+
import { n as TronSignRequestProps, r as TronSignatureResult, t as TronChain } from "./tron-YllfTmx6.js";
|
|
4
|
+
export { AnimatedUr, type EraConnectConfig, type EraErrorCode, EraSdkError, type ExpectedReply, type SignRequest, type SignedTronTx, TronChain, type TronLatestBlock, type TronSignRequestProps, type TronSignatureResult, TypedUrScanner, Ur, UrScanner, splitSignedTronTx };
|
package/dist/tron.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Z as EraSdkError, _ as Ur, d as UrScanner, f as AnimatedUr, u as TypedUrScanner } from "./shared-B8Wc7ViU.js";
|
|
2
|
+
import { t as TronChain } from "./tron-Bo9HnvVE.js";
|
|
3
|
+
import { r as splitSignedTronTx } from "./messages-17Oup0-Z.js";
|
|
4
|
+
export { AnimatedUr, EraSdkError, TronChain, TypedUrScanner, Ur, UrScanner, splitSignedTronTx };
|