@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,208 @@
|
|
|
1
|
+
import { A as utf8Encode, D as hexToBytes, T as concatBytes, Z as EraSdkError, k as utf8Decode } from "./shared-B8Wc7ViU.js";
|
|
2
|
+
//#region src/tron-proto/wire.ts
|
|
3
|
+
/**
|
|
4
|
+
* Minimal protobuf wire codec for the Tron signing envelope. Varint and
|
|
5
|
+
* length-delimited wire types only — the schema uses nothing else.
|
|
6
|
+
*
|
|
7
|
+
* Writer semantics mirror the reference implementation: EXPLICITLY SET fields
|
|
8
|
+
* are written even when they hold default values (a `timestamp` of 0 is
|
|
9
|
+
* `tag, 0x00` on the wire), and fields are emitted in ascending field-number
|
|
10
|
+
* order. Byte-exactness against the golden fixtures depends on both.
|
|
11
|
+
*/
|
|
12
|
+
var ProtoWriter = class {
|
|
13
|
+
constructor() {
|
|
14
|
+
this.parts = [];
|
|
15
|
+
}
|
|
16
|
+
varintField(field, value) {
|
|
17
|
+
this.parts.push(tag(field, 0), varint(value));
|
|
18
|
+
return this;
|
|
19
|
+
}
|
|
20
|
+
stringField(field, value) {
|
|
21
|
+
const bytes = utf8Encode(value);
|
|
22
|
+
this.parts.push(tag(field, 2), varint(bytes.length), bytes);
|
|
23
|
+
return this;
|
|
24
|
+
}
|
|
25
|
+
bytesField(field, value) {
|
|
26
|
+
this.parts.push(tag(field, 2), varint(value.length), value);
|
|
27
|
+
return this;
|
|
28
|
+
}
|
|
29
|
+
messageField(field, encoded) {
|
|
30
|
+
this.parts.push(tag(field, 2), varint(encoded.length), encoded);
|
|
31
|
+
return this;
|
|
32
|
+
}
|
|
33
|
+
finish() {
|
|
34
|
+
return concatBytes(...this.parts);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
function tag(field, wireType) {
|
|
38
|
+
return varint(field << 3 | wireType);
|
|
39
|
+
}
|
|
40
|
+
function varint(value) {
|
|
41
|
+
let v = typeof value === "number" ? BigInt(value) : value;
|
|
42
|
+
if (v < 0n) throw new EraSdkError("protobuf-error", "negative varint");
|
|
43
|
+
const out = [];
|
|
44
|
+
do {
|
|
45
|
+
let byte = Number(v & 127n);
|
|
46
|
+
v >>= 7n;
|
|
47
|
+
if (v > 0n) byte |= 128;
|
|
48
|
+
out.push(byte);
|
|
49
|
+
} while (v > 0n);
|
|
50
|
+
return new Uint8Array(out);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Hardened field reader: varint shift capped, lengths bounds-checked before
|
|
54
|
+
* slicing, unknown fields skippable by wire type, group wire types refused.
|
|
55
|
+
*/
|
|
56
|
+
function readFields(bytes) {
|
|
57
|
+
const fields = [];
|
|
58
|
+
let offset = 0;
|
|
59
|
+
const readVarint = () => {
|
|
60
|
+
let result = 0n;
|
|
61
|
+
let shift = 0n;
|
|
62
|
+
for (;;) {
|
|
63
|
+
const byte = bytes[offset];
|
|
64
|
+
if (byte === void 0) throw new EraSdkError("protobuf-error", "truncated varint");
|
|
65
|
+
offset += 1;
|
|
66
|
+
result |= BigInt(byte & 127) << shift;
|
|
67
|
+
if ((byte & 128) === 0) return result;
|
|
68
|
+
shift += 7n;
|
|
69
|
+
if (shift > 63n) throw new EraSdkError("protobuf-error", "varint exceeds 64 bits");
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
while (offset < bytes.length) {
|
|
73
|
+
const key = readVarint();
|
|
74
|
+
const field = Number(key >> 3n);
|
|
75
|
+
const wireType = Number(key & 7n);
|
|
76
|
+
if (field === 0) throw new EraSdkError("protobuf-error", "field number 0");
|
|
77
|
+
switch (wireType) {
|
|
78
|
+
case 0:
|
|
79
|
+
fields.push({
|
|
80
|
+
field,
|
|
81
|
+
wireType,
|
|
82
|
+
value: readVarint(),
|
|
83
|
+
bytes: EMPTY
|
|
84
|
+
});
|
|
85
|
+
break;
|
|
86
|
+
case 1:
|
|
87
|
+
if (offset + 8 > bytes.length) throw new EraSdkError("protobuf-error", "truncated fixed64");
|
|
88
|
+
fields.push({
|
|
89
|
+
field,
|
|
90
|
+
wireType,
|
|
91
|
+
value: 0n,
|
|
92
|
+
bytes: bytes.slice(offset, offset + 8)
|
|
93
|
+
});
|
|
94
|
+
offset += 8;
|
|
95
|
+
break;
|
|
96
|
+
case 2: {
|
|
97
|
+
const length = readVarint();
|
|
98
|
+
if (length > BigInt(bytes.length - offset)) throw new EraSdkError("protobuf-error", "length-delimited field exceeds input");
|
|
99
|
+
const len = Number(length);
|
|
100
|
+
fields.push({
|
|
101
|
+
field,
|
|
102
|
+
wireType,
|
|
103
|
+
value: 0n,
|
|
104
|
+
bytes: bytes.slice(offset, offset + len)
|
|
105
|
+
});
|
|
106
|
+
offset += len;
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
case 5:
|
|
110
|
+
if (offset + 4 > bytes.length) throw new EraSdkError("protobuf-error", "truncated fixed32");
|
|
111
|
+
fields.push({
|
|
112
|
+
field,
|
|
113
|
+
wireType,
|
|
114
|
+
value: 0n,
|
|
115
|
+
bytes: bytes.slice(offset, offset + 4)
|
|
116
|
+
});
|
|
117
|
+
offset += 4;
|
|
118
|
+
break;
|
|
119
|
+
default: throw new EraSdkError("protobuf-error", `unsupported wire type ${wireType}`);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return fields;
|
|
123
|
+
}
|
|
124
|
+
const EMPTY = /* @__PURE__ */ new Uint8Array(0);
|
|
125
|
+
/** First occurrence of a length-delimited field, or null. */
|
|
126
|
+
function firstBytes(fields, field) {
|
|
127
|
+
for (const f of fields) if (f.field === field && f.wireType === 2) return f.bytes;
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
/** First occurrence of a varint field, or null. */
|
|
131
|
+
function firstVarint(fields, field) {
|
|
132
|
+
for (const f of fields) if (f.field === field && f.wireType === 0) return f.value;
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
//#endregion
|
|
136
|
+
//#region src/tron-proto/messages.ts
|
|
137
|
+
const PAYLOAD_TYPE_SIGN_TX = 2;
|
|
138
|
+
function encodeSignRequestProto(req) {
|
|
139
|
+
if (req.fee !== void 0 && (req.fee < 0 || req.fee > 2147483647)) throw new EraSdkError("invalid-props", "tron fee must fit a positive int32");
|
|
140
|
+
const latestBlock = new ProtoWriter().stringField(1, req.latestBlock.hash).varintField(2, req.latestBlock.number).varintField(3, req.latestBlock.timestamp).finish();
|
|
141
|
+
const tronTx = new ProtoWriter().stringField(1, req.token);
|
|
142
|
+
if (req.contractAddress !== void 0) tronTx.stringField(2, req.contractAddress);
|
|
143
|
+
if (req.from !== void 0) tronTx.stringField(3, req.from);
|
|
144
|
+
if (req.to !== void 0) tronTx.stringField(4, req.to);
|
|
145
|
+
if (req.memo !== void 0) tronTx.stringField(5, req.memo);
|
|
146
|
+
if (req.value !== void 0) tronTx.stringField(6, req.value);
|
|
147
|
+
tronTx.messageField(7, latestBlock);
|
|
148
|
+
if (req.fee !== void 0) tronTx.varintField(9, req.fee);
|
|
149
|
+
tronTx.bytesField(10, req.rawData);
|
|
150
|
+
const signTx = new ProtoWriter().stringField(1, "TRON").stringField(2, req.signId).stringField(3, req.hdPath).varintField(4, req.timestamp).varintField(5, req.decimals).messageField(8, tronTx.finish()).finish();
|
|
151
|
+
const payload = new ProtoWriter().varintField(1, PAYLOAD_TYPE_SIGN_TX).stringField(2, req.xfpHex).messageField(4, signTx).finish();
|
|
152
|
+
return new ProtoWriter().varintField(1, 2).stringField(2, "QrCode Protocol").messageField(3, payload).finish();
|
|
153
|
+
}
|
|
154
|
+
/** Parse a `keystone-sign-result` Base protobuf. Unknown fields are skipped. */
|
|
155
|
+
function decodeSignResultProto(bytes) {
|
|
156
|
+
const payloadBytes = firstBytes(readFields(bytes), 3);
|
|
157
|
+
if (!payloadBytes) throw new EraSdkError("malformed-reply", "keystone-sign-result carries no payload");
|
|
158
|
+
const resultBytes = firstBytes(readFields(payloadBytes), 7);
|
|
159
|
+
if (!resultBytes) return {
|
|
160
|
+
signId: "",
|
|
161
|
+
txId: "",
|
|
162
|
+
rawTx: ""
|
|
163
|
+
};
|
|
164
|
+
const result = readFields(resultBytes);
|
|
165
|
+
return {
|
|
166
|
+
signId: text(firstBytes(result, 1)),
|
|
167
|
+
txId: text(firstBytes(result, 2)),
|
|
168
|
+
rawTx: text(firstBytes(result, 3))
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
function text(bytes) {
|
|
172
|
+
if (!bytes) return "";
|
|
173
|
+
try {
|
|
174
|
+
return utf8Decode(bytes);
|
|
175
|
+
} catch {
|
|
176
|
+
throw new EraSdkError("malformed-reply", "protobuf string field is not valid UTF-8");
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Split a signed Tron network `Transaction` frame (`{1: raw_data, 2: signature*}`)
|
|
181
|
+
* from the reply's `rawTx` hex. Top-level fields must be length-delimited —
|
|
182
|
+
* anything else is not a transaction frame.
|
|
183
|
+
*/
|
|
184
|
+
function splitSignedTronTx(rawTxHex) {
|
|
185
|
+
let frame;
|
|
186
|
+
try {
|
|
187
|
+
frame = hexToBytes(rawTxHex);
|
|
188
|
+
} catch {
|
|
189
|
+
throw new EraSdkError("malformed-reply", "signed Tron transaction is not hex");
|
|
190
|
+
}
|
|
191
|
+
const fields = readFields(frame);
|
|
192
|
+
let rawData = null;
|
|
193
|
+
const signatures = [];
|
|
194
|
+
for (const f of fields) {
|
|
195
|
+
if (f.wireType !== 2) throw new EraSdkError("malformed-reply", "unexpected wire type in signed Tron transaction");
|
|
196
|
+
if (f.field === 1 && rawData === null) rawData = f.bytes;
|
|
197
|
+
if (f.field === 2) signatures.push(f.bytes);
|
|
198
|
+
}
|
|
199
|
+
if (rawData === null) throw new EraSdkError("malformed-reply", "signed Tron transaction carries no raw_data");
|
|
200
|
+
return {
|
|
201
|
+
rawData,
|
|
202
|
+
signatures
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
//#endregion
|
|
206
|
+
export { firstVarint as a, firstBytes as i, encodeSignRequestProto as n, readFields as o, splitSignedTronTx as r, decodeSignResultProto as t };
|
|
207
|
+
|
|
208
|
+
//# sourceMappingURL=messages-17Oup0-Z.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages-17Oup0-Z.js","names":[],"sources":["../src/tron-proto/wire.ts","../src/tron-proto/messages.ts"],"sourcesContent":["import { concatBytes, utf8Encode } from '../core/bytes';\nimport { EraSdkError } from '../core/errors';\n\n/**\n * Minimal protobuf wire codec for the Tron signing envelope. Varint and\n * length-delimited wire types only — the schema uses nothing else.\n *\n * Writer semantics mirror the reference implementation: EXPLICITLY SET fields\n * are written even when they hold default values (a `timestamp` of 0 is\n * `tag, 0x00` on the wire), and fields are emitted in ascending field-number\n * order. Byte-exactness against the golden fixtures depends on both.\n */\n\nexport class ProtoWriter {\n private readonly parts: Uint8Array[] = [];\n\n varintField(field: number, value: number | bigint): this {\n this.parts.push(tag(field, 0), varint(value));\n return this;\n }\n\n stringField(field: number, value: string): this {\n const bytes = utf8Encode(value);\n this.parts.push(tag(field, 2), varint(bytes.length), bytes);\n return this;\n }\n\n bytesField(field: number, value: Uint8Array): this {\n this.parts.push(tag(field, 2), varint(value.length), value);\n return this;\n }\n\n messageField(field: number, encoded: Uint8Array): this {\n this.parts.push(tag(field, 2), varint(encoded.length), encoded);\n return this;\n }\n\n finish(): Uint8Array {\n return concatBytes(...this.parts);\n }\n}\n\nfunction tag(field: number, wireType: number): Uint8Array {\n return varint((field << 3) | wireType);\n}\n\nexport function varint(value: number | bigint): Uint8Array {\n let v = typeof value === 'number' ? BigInt(value) : value;\n if (v < 0n) throw new EraSdkError('protobuf-error', 'negative varint');\n const out: number[] = [];\n do {\n let byte = Number(v & 0x7fn);\n v >>= 7n;\n if (v > 0n) byte |= 0x80;\n out.push(byte);\n } while (v > 0n);\n return new Uint8Array(out);\n}\n\nexport interface ProtoField {\n readonly field: number;\n readonly wireType: number;\n /** Set for wire type 0. */\n readonly value: bigint;\n /** Set for wire type 2 (verbatim slice of the input). */\n readonly bytes: Uint8Array;\n}\n\n/**\n * Hardened field reader: varint shift capped, lengths bounds-checked before\n * slicing, unknown fields skippable by wire type, group wire types refused.\n */\nexport function readFields(bytes: Uint8Array): ProtoField[] {\n const fields: ProtoField[] = [];\n let offset = 0;\n\n const readVarint = (): bigint => {\n let result = 0n;\n let shift = 0n;\n for (;;) {\n const byte = bytes[offset];\n if (byte === undefined) throw new EraSdkError('protobuf-error', 'truncated varint');\n offset += 1;\n result |= BigInt(byte & 0x7f) << shift;\n if ((byte & 0x80) === 0) return result;\n shift += 7n;\n if (shift > 63n) throw new EraSdkError('protobuf-error', 'varint exceeds 64 bits');\n }\n };\n\n while (offset < bytes.length) {\n const key = readVarint();\n const field = Number(key >> 3n);\n const wireType = Number(key & 7n);\n if (field === 0) throw new EraSdkError('protobuf-error', 'field number 0');\n switch (wireType) {\n case 0: {\n fields.push({ field, wireType, value: readVarint(), bytes: EMPTY });\n break;\n }\n case 1: {\n if (offset + 8 > bytes.length) throw new EraSdkError('protobuf-error', 'truncated fixed64');\n fields.push({ field, wireType, value: 0n, bytes: bytes.slice(offset, offset + 8) });\n offset += 8;\n break;\n }\n case 2: {\n const length = readVarint();\n if (length > BigInt(bytes.length - offset)) {\n throw new EraSdkError('protobuf-error', 'length-delimited field exceeds input');\n }\n const len = Number(length);\n fields.push({ field, wireType, value: 0n, bytes: bytes.slice(offset, offset + len) });\n offset += len;\n break;\n }\n case 5: {\n if (offset + 4 > bytes.length) throw new EraSdkError('protobuf-error', 'truncated fixed32');\n fields.push({ field, wireType, value: 0n, bytes: bytes.slice(offset, offset + 4) });\n offset += 4;\n break;\n }\n default:\n throw new EraSdkError('protobuf-error', `unsupported wire type ${wireType}`);\n }\n }\n return fields;\n}\n\nconst EMPTY = new Uint8Array(0);\n\n/** First occurrence of a length-delimited field, or null. */\nexport function firstBytes(fields: ProtoField[], field: number): Uint8Array | null {\n for (const f of fields) {\n if (f.field === field && f.wireType === 2) return f.bytes;\n }\n return null;\n}\n\n/** First occurrence of a varint field, or null. */\nexport function firstVarint(fields: ProtoField[], field: number): bigint | null {\n for (const f of fields) {\n if (f.field === field && f.wireType === 0) return f.value;\n }\n return null;\n}\n","import { hexToBytes, utf8Decode } from '../core/bytes';\nimport { EraSdkError } from '../core/errors';\nimport { firstBytes, ProtoWriter, readFields } from './wire';\n\n/**\n * The Tron signing envelope (\"QrCode Protocol\"):\n * `Base -> Payload -> SignTransaction -> TronTx`, gzip-compressed and wrapped\n * in a `keystone-sign-request` (6101) CBOR map. Schemas are vendored under\n * `proto/tron/`; this codec hand-writes the five messages the wallet side\n * speaks, with reference-exact field emission (explicitly-set defaults ARE\n * written; ascending field order).\n */\n\nexport interface TronLatestBlock {\n /** FULL 64-hex block id of a live now-block (the device slices ref_block_hash from it). */\n readonly hash: string;\n readonly number: number;\n readonly timestamp: number;\n}\n\nexport interface TronSignRequestProto {\n /** Lowercase, ZERO-PADDED 8-hex source fingerprint (the wire demands the string form). */\n readonly xfpHex: string;\n /** Hyphenated UUID string; echoed by the device as the only reply binding. */\n readonly signId: string;\n readonly hdPath: string;\n readonly timestamp: number;\n readonly decimals: number;\n readonly token: string;\n readonly contractAddress?: string | undefined;\n readonly from?: string | undefined;\n readonly to?: string | undefined;\n readonly memo?: string | undefined;\n readonly value?: string | undefined;\n readonly fee?: number | undefined;\n readonly latestBlock: TronLatestBlock;\n /** Serialized `Transaction.raw_data` — the signing source of truth. */\n readonly rawData: Uint8Array;\n}\n\nconst PAYLOAD_TYPE_SIGN_TX = 2;\n\nexport function encodeSignRequestProto(req: TronSignRequestProto): Uint8Array {\n if (req.fee !== undefined && (req.fee < 0 || req.fee > 0x7fffffff)) {\n throw new EraSdkError('invalid-props', 'tron fee must fit a positive int32');\n }\n const latestBlock = new ProtoWriter()\n .stringField(1, req.latestBlock.hash)\n .varintField(2, req.latestBlock.number)\n .varintField(3, req.latestBlock.timestamp)\n .finish();\n\n const tronTx = new ProtoWriter().stringField(1, req.token);\n if (req.contractAddress !== undefined) tronTx.stringField(2, req.contractAddress);\n if (req.from !== undefined) tronTx.stringField(3, req.from);\n if (req.to !== undefined) tronTx.stringField(4, req.to);\n if (req.memo !== undefined) tronTx.stringField(5, req.memo);\n if (req.value !== undefined) tronTx.stringField(6, req.value);\n tronTx.messageField(7, latestBlock);\n if (req.fee !== undefined) tronTx.varintField(9, req.fee);\n tronTx.bytesField(10, req.rawData);\n\n const signTx = new ProtoWriter()\n .stringField(1, 'TRON')\n .stringField(2, req.signId)\n .stringField(3, req.hdPath)\n .varintField(4, req.timestamp)\n .varintField(5, req.decimals)\n .messageField(8, tronTx.finish())\n .finish();\n\n const payload = new ProtoWriter()\n .varintField(1, PAYLOAD_TYPE_SIGN_TX)\n .stringField(2, req.xfpHex)\n .messageField(4, signTx)\n .finish();\n\n return new ProtoWriter()\n .varintField(1, 2) // Base.version\n .stringField(2, 'QrCode Protocol')\n .messageField(3, payload)\n .finish();\n}\n\nexport interface TronSignResultProto {\n readonly signId: string;\n readonly txId: string;\n readonly rawTx: string;\n}\n\n/** Parse a `keystone-sign-result` Base protobuf. Unknown fields are skipped. */\nexport function decodeSignResultProto(bytes: Uint8Array): TronSignResultProto {\n const base = readFields(bytes);\n const payloadBytes = firstBytes(base, 3);\n if (!payloadBytes) {\n throw new EraSdkError('malformed-reply', 'keystone-sign-result carries no payload');\n }\n const payload = readFields(payloadBytes);\n const resultBytes = firstBytes(payload, 7); // Payload.signTxResult\n if (!resultBytes) {\n return { signId: '', txId: '', rawTx: '' };\n }\n const result = readFields(resultBytes);\n return {\n signId: text(firstBytes(result, 1)),\n txId: text(firstBytes(result, 2)),\n rawTx: text(firstBytes(result, 3)),\n };\n}\n\nfunction text(bytes: Uint8Array | null): string {\n if (!bytes) return '';\n try {\n return utf8Decode(bytes);\n } catch {\n throw new EraSdkError('malformed-reply', 'protobuf string field is not valid UTF-8');\n }\n}\n\nexport interface SignedTronTx {\n /** Verbatim `raw_data` slice — the digest is sha256 over the device's own serialization. */\n readonly rawData: Uint8Array;\n readonly signatures: readonly Uint8Array[];\n}\n\n/**\n * Split a signed Tron network `Transaction` frame (`{1: raw_data, 2: signature*}`)\n * from the reply's `rawTx` hex. Top-level fields must be length-delimited —\n * anything else is not a transaction frame.\n */\nexport function splitSignedTronTx(rawTxHex: string): SignedTronTx {\n let frame: Uint8Array;\n try {\n frame = hexToBytes(rawTxHex);\n } catch {\n throw new EraSdkError('malformed-reply', 'signed Tron transaction is not hex');\n }\n const fields = readFields(frame);\n let rawData: Uint8Array | null = null;\n const signatures: Uint8Array[] = [];\n for (const f of fields) {\n if (f.wireType !== 2) {\n throw new EraSdkError('malformed-reply', 'unexpected wire type in signed Tron transaction');\n }\n if (f.field === 1 && rawData === null) rawData = f.bytes;\n if (f.field === 2) signatures.push(f.bytes);\n }\n if (rawData === null) {\n throw new EraSdkError('malformed-reply', 'signed Tron transaction carries no raw_data');\n }\n return { rawData, signatures };\n}\n"],"mappings":";;;;;;;;;;;AAaA,IAAa,cAAb,MAAyB;;EACvB,KAAiB,QAAsB,CAAC;;CAExC,YAAY,OAAe,OAA8B;EACvD,KAAK,MAAM,KAAK,IAAI,OAAO,CAAC,GAAG,OAAO,KAAK,CAAC;EAC5C,OAAO;CACT;CAEA,YAAY,OAAe,OAAqB;EAC9C,MAAM,QAAQ,WAAW,KAAK;EAC9B,KAAK,MAAM,KAAK,IAAI,OAAO,CAAC,GAAG,OAAO,MAAM,MAAM,GAAG,KAAK;EAC1D,OAAO;CACT;CAEA,WAAW,OAAe,OAAyB;EACjD,KAAK,MAAM,KAAK,IAAI,OAAO,CAAC,GAAG,OAAO,MAAM,MAAM,GAAG,KAAK;EAC1D,OAAO;CACT;CAEA,aAAa,OAAe,SAA2B;EACrD,KAAK,MAAM,KAAK,IAAI,OAAO,CAAC,GAAG,OAAO,QAAQ,MAAM,GAAG,OAAO;EAC9D,OAAO;CACT;CAEA,SAAqB;EACnB,OAAO,YAAY,GAAG,KAAK,KAAK;CAClC;AACF;AAEA,SAAS,IAAI,OAAe,UAA8B;CACxD,OAAO,OAAQ,SAAS,IAAK,QAAQ;AACvC;AAEA,SAAgB,OAAO,OAAoC;CACzD,IAAI,IAAI,OAAO,UAAU,WAAW,OAAO,KAAK,IAAI;CACpD,IAAI,IAAI,IAAI,MAAM,IAAI,YAAY,kBAAkB,iBAAiB;CACrE,MAAM,MAAgB,CAAC;CACvB,GAAG;EACD,IAAI,OAAO,OAAO,IA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AAQ,CAAC,CAAC;EAChC,OAAO,KAAK,WAAW,QAAQ,CAAC,CAAC;CACnC;AACF;AAEA,SAAS,KAAK,OAAkC;CAC9C,IAAI,CAAC,OAAO,OAAO;CACnB,IAAI;EACF,OAAO,WAAW,KAAK;CACzB,QAAQ;EACN,MAAM,IAAI,YAAY,mBAAmB,0CAA0C;CACrF;AACF;;;;;;AAaA,SAAgB,kBAAkB,UAAgC;CAChE,IAAI;CACJ,IAAI;EACF,QAAQ,WAAW,QAAQ;CAC7B,QAAQ;EACN,MAAM,IAAI,YAAY,mBAAmB,oCAAoC;CAC/E;CACA,MAAM,SAAS,WAAW,KAAK;CAC/B,IAAI,UAA6B;CACjC,MAAM,aAA2B,CAAC;CAClC,KAAK,MAAM,KAAK,QAAQ;EACtB,IAAI,EAAE,aAAa,GACjB,MAAM,IAAI,YAAY,mBAAmB,iDAAiD;EAE5F,IAAI,EAAE,UAAU,KAAK,YAAY,MAAM,UAAU,EAAE;EACnD,IAAI,EAAE,UAAU,GAAG,WAAW,KAAK,EAAE,KAAK;CAC5C;CACA,IAAI,YAAY,MACd,MAAM,IAAI,YAAY,mBAAmB,6CAA6C;CAExF,OAAO;EAAE;EAAS;CAAW;AAC/B"}
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
const require_shared = require("./shared-nISrEktU.cjs");
|
|
2
|
+
//#region src/tron-proto/wire.ts
|
|
3
|
+
/**
|
|
4
|
+
* Minimal protobuf wire codec for the Tron signing envelope. Varint and
|
|
5
|
+
* length-delimited wire types only — the schema uses nothing else.
|
|
6
|
+
*
|
|
7
|
+
* Writer semantics mirror the reference implementation: EXPLICITLY SET fields
|
|
8
|
+
* are written even when they hold default values (a `timestamp` of 0 is
|
|
9
|
+
* `tag, 0x00` on the wire), and fields are emitted in ascending field-number
|
|
10
|
+
* order. Byte-exactness against the golden fixtures depends on both.
|
|
11
|
+
*/
|
|
12
|
+
var ProtoWriter = class {
|
|
13
|
+
constructor() {
|
|
14
|
+
this.parts = [];
|
|
15
|
+
}
|
|
16
|
+
varintField(field, value) {
|
|
17
|
+
this.parts.push(tag(field, 0), varint(value));
|
|
18
|
+
return this;
|
|
19
|
+
}
|
|
20
|
+
stringField(field, value) {
|
|
21
|
+
const bytes = require_shared.utf8Encode(value);
|
|
22
|
+
this.parts.push(tag(field, 2), varint(bytes.length), bytes);
|
|
23
|
+
return this;
|
|
24
|
+
}
|
|
25
|
+
bytesField(field, value) {
|
|
26
|
+
this.parts.push(tag(field, 2), varint(value.length), value);
|
|
27
|
+
return this;
|
|
28
|
+
}
|
|
29
|
+
messageField(field, encoded) {
|
|
30
|
+
this.parts.push(tag(field, 2), varint(encoded.length), encoded);
|
|
31
|
+
return this;
|
|
32
|
+
}
|
|
33
|
+
finish() {
|
|
34
|
+
return require_shared.concatBytes(...this.parts);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
function tag(field, wireType) {
|
|
38
|
+
return varint(field << 3 | wireType);
|
|
39
|
+
}
|
|
40
|
+
function varint(value) {
|
|
41
|
+
let v = typeof value === "number" ? BigInt(value) : value;
|
|
42
|
+
if (v < 0n) throw new require_shared.EraSdkError("protobuf-error", "negative varint");
|
|
43
|
+
const out = [];
|
|
44
|
+
do {
|
|
45
|
+
let byte = Number(v & 127n);
|
|
46
|
+
v >>= 7n;
|
|
47
|
+
if (v > 0n) byte |= 128;
|
|
48
|
+
out.push(byte);
|
|
49
|
+
} while (v > 0n);
|
|
50
|
+
return new Uint8Array(out);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Hardened field reader: varint shift capped, lengths bounds-checked before
|
|
54
|
+
* slicing, unknown fields skippable by wire type, group wire types refused.
|
|
55
|
+
*/
|
|
56
|
+
function readFields(bytes) {
|
|
57
|
+
const fields = [];
|
|
58
|
+
let offset = 0;
|
|
59
|
+
const readVarint = () => {
|
|
60
|
+
let result = 0n;
|
|
61
|
+
let shift = 0n;
|
|
62
|
+
for (;;) {
|
|
63
|
+
const byte = bytes[offset];
|
|
64
|
+
if (byte === void 0) throw new require_shared.EraSdkError("protobuf-error", "truncated varint");
|
|
65
|
+
offset += 1;
|
|
66
|
+
result |= BigInt(byte & 127) << shift;
|
|
67
|
+
if ((byte & 128) === 0) return result;
|
|
68
|
+
shift += 7n;
|
|
69
|
+
if (shift > 63n) throw new require_shared.EraSdkError("protobuf-error", "varint exceeds 64 bits");
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
while (offset < bytes.length) {
|
|
73
|
+
const key = readVarint();
|
|
74
|
+
const field = Number(key >> 3n);
|
|
75
|
+
const wireType = Number(key & 7n);
|
|
76
|
+
if (field === 0) throw new require_shared.EraSdkError("protobuf-error", "field number 0");
|
|
77
|
+
switch (wireType) {
|
|
78
|
+
case 0:
|
|
79
|
+
fields.push({
|
|
80
|
+
field,
|
|
81
|
+
wireType,
|
|
82
|
+
value: readVarint(),
|
|
83
|
+
bytes: EMPTY
|
|
84
|
+
});
|
|
85
|
+
break;
|
|
86
|
+
case 1:
|
|
87
|
+
if (offset + 8 > bytes.length) throw new require_shared.EraSdkError("protobuf-error", "truncated fixed64");
|
|
88
|
+
fields.push({
|
|
89
|
+
field,
|
|
90
|
+
wireType,
|
|
91
|
+
value: 0n,
|
|
92
|
+
bytes: bytes.slice(offset, offset + 8)
|
|
93
|
+
});
|
|
94
|
+
offset += 8;
|
|
95
|
+
break;
|
|
96
|
+
case 2: {
|
|
97
|
+
const length = readVarint();
|
|
98
|
+
if (length > BigInt(bytes.length - offset)) throw new require_shared.EraSdkError("protobuf-error", "length-delimited field exceeds input");
|
|
99
|
+
const len = Number(length);
|
|
100
|
+
fields.push({
|
|
101
|
+
field,
|
|
102
|
+
wireType,
|
|
103
|
+
value: 0n,
|
|
104
|
+
bytes: bytes.slice(offset, offset + len)
|
|
105
|
+
});
|
|
106
|
+
offset += len;
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
case 5:
|
|
110
|
+
if (offset + 4 > bytes.length) throw new require_shared.EraSdkError("protobuf-error", "truncated fixed32");
|
|
111
|
+
fields.push({
|
|
112
|
+
field,
|
|
113
|
+
wireType,
|
|
114
|
+
value: 0n,
|
|
115
|
+
bytes: bytes.slice(offset, offset + 4)
|
|
116
|
+
});
|
|
117
|
+
offset += 4;
|
|
118
|
+
break;
|
|
119
|
+
default: throw new require_shared.EraSdkError("protobuf-error", `unsupported wire type ${wireType}`);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return fields;
|
|
123
|
+
}
|
|
124
|
+
const EMPTY = /* @__PURE__ */ new Uint8Array(0);
|
|
125
|
+
/** First occurrence of a length-delimited field, or null. */
|
|
126
|
+
function firstBytes(fields, field) {
|
|
127
|
+
for (const f of fields) if (f.field === field && f.wireType === 2) return f.bytes;
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
/** First occurrence of a varint field, or null. */
|
|
131
|
+
function firstVarint(fields, field) {
|
|
132
|
+
for (const f of fields) if (f.field === field && f.wireType === 0) return f.value;
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
//#endregion
|
|
136
|
+
//#region src/tron-proto/messages.ts
|
|
137
|
+
const PAYLOAD_TYPE_SIGN_TX = 2;
|
|
138
|
+
function encodeSignRequestProto(req) {
|
|
139
|
+
if (req.fee !== void 0 && (req.fee < 0 || req.fee > 2147483647)) throw new require_shared.EraSdkError("invalid-props", "tron fee must fit a positive int32");
|
|
140
|
+
const latestBlock = new ProtoWriter().stringField(1, req.latestBlock.hash).varintField(2, req.latestBlock.number).varintField(3, req.latestBlock.timestamp).finish();
|
|
141
|
+
const tronTx = new ProtoWriter().stringField(1, req.token);
|
|
142
|
+
if (req.contractAddress !== void 0) tronTx.stringField(2, req.contractAddress);
|
|
143
|
+
if (req.from !== void 0) tronTx.stringField(3, req.from);
|
|
144
|
+
if (req.to !== void 0) tronTx.stringField(4, req.to);
|
|
145
|
+
if (req.memo !== void 0) tronTx.stringField(5, req.memo);
|
|
146
|
+
if (req.value !== void 0) tronTx.stringField(6, req.value);
|
|
147
|
+
tronTx.messageField(7, latestBlock);
|
|
148
|
+
if (req.fee !== void 0) tronTx.varintField(9, req.fee);
|
|
149
|
+
tronTx.bytesField(10, req.rawData);
|
|
150
|
+
const signTx = new ProtoWriter().stringField(1, "TRON").stringField(2, req.signId).stringField(3, req.hdPath).varintField(4, req.timestamp).varintField(5, req.decimals).messageField(8, tronTx.finish()).finish();
|
|
151
|
+
const payload = new ProtoWriter().varintField(1, PAYLOAD_TYPE_SIGN_TX).stringField(2, req.xfpHex).messageField(4, signTx).finish();
|
|
152
|
+
return new ProtoWriter().varintField(1, 2).stringField(2, "QrCode Protocol").messageField(3, payload).finish();
|
|
153
|
+
}
|
|
154
|
+
/** Parse a `keystone-sign-result` Base protobuf. Unknown fields are skipped. */
|
|
155
|
+
function decodeSignResultProto(bytes) {
|
|
156
|
+
const payloadBytes = firstBytes(readFields(bytes), 3);
|
|
157
|
+
if (!payloadBytes) throw new require_shared.EraSdkError("malformed-reply", "keystone-sign-result carries no payload");
|
|
158
|
+
const resultBytes = firstBytes(readFields(payloadBytes), 7);
|
|
159
|
+
if (!resultBytes) return {
|
|
160
|
+
signId: "",
|
|
161
|
+
txId: "",
|
|
162
|
+
rawTx: ""
|
|
163
|
+
};
|
|
164
|
+
const result = readFields(resultBytes);
|
|
165
|
+
return {
|
|
166
|
+
signId: text(firstBytes(result, 1)),
|
|
167
|
+
txId: text(firstBytes(result, 2)),
|
|
168
|
+
rawTx: text(firstBytes(result, 3))
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
function text(bytes) {
|
|
172
|
+
if (!bytes) return "";
|
|
173
|
+
try {
|
|
174
|
+
return require_shared.utf8Decode(bytes);
|
|
175
|
+
} catch {
|
|
176
|
+
throw new require_shared.EraSdkError("malformed-reply", "protobuf string field is not valid UTF-8");
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Split a signed Tron network `Transaction` frame (`{1: raw_data, 2: signature*}`)
|
|
181
|
+
* from the reply's `rawTx` hex. Top-level fields must be length-delimited —
|
|
182
|
+
* anything else is not a transaction frame.
|
|
183
|
+
*/
|
|
184
|
+
function splitSignedTronTx(rawTxHex) {
|
|
185
|
+
let frame;
|
|
186
|
+
try {
|
|
187
|
+
frame = require_shared.hexToBytes(rawTxHex);
|
|
188
|
+
} catch {
|
|
189
|
+
throw new require_shared.EraSdkError("malformed-reply", "signed Tron transaction is not hex");
|
|
190
|
+
}
|
|
191
|
+
const fields = readFields(frame);
|
|
192
|
+
let rawData = null;
|
|
193
|
+
const signatures = [];
|
|
194
|
+
for (const f of fields) {
|
|
195
|
+
if (f.wireType !== 2) throw new require_shared.EraSdkError("malformed-reply", "unexpected wire type in signed Tron transaction");
|
|
196
|
+
if (f.field === 1 && rawData === null) rawData = f.bytes;
|
|
197
|
+
if (f.field === 2) signatures.push(f.bytes);
|
|
198
|
+
}
|
|
199
|
+
if (rawData === null) throw new require_shared.EraSdkError("malformed-reply", "signed Tron transaction carries no raw_data");
|
|
200
|
+
return {
|
|
201
|
+
rawData,
|
|
202
|
+
signatures
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
//#endregion
|
|
206
|
+
Object.defineProperty(exports, "decodeSignResultProto", {
|
|
207
|
+
enumerable: true,
|
|
208
|
+
get: function() {
|
|
209
|
+
return decodeSignResultProto;
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
Object.defineProperty(exports, "encodeSignRequestProto", {
|
|
213
|
+
enumerable: true,
|
|
214
|
+
get: function() {
|
|
215
|
+
return encodeSignRequestProto;
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
Object.defineProperty(exports, "firstBytes", {
|
|
219
|
+
enumerable: true,
|
|
220
|
+
get: function() {
|
|
221
|
+
return firstBytes;
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
Object.defineProperty(exports, "firstVarint", {
|
|
225
|
+
enumerable: true,
|
|
226
|
+
get: function() {
|
|
227
|
+
return firstVarint;
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
Object.defineProperty(exports, "readFields", {
|
|
231
|
+
enumerable: true,
|
|
232
|
+
get: function() {
|
|
233
|
+
return readFields;
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
Object.defineProperty(exports, "splitSignedTronTx", {
|
|
237
|
+
enumerable: true,
|
|
238
|
+
get: function() {
|
|
239
|
+
return splitSignedTronTx;
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
//# sourceMappingURL=messages-BzcdWlg1.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages-BzcdWlg1.cjs","names":["utf8Encode","concatBytes","EraSdkError","EraSdkError","utf8Decode","hexToBytes"],"sources":["../src/tron-proto/wire.ts","../src/tron-proto/messages.ts"],"sourcesContent":["import { concatBytes, utf8Encode } from '../core/bytes';\nimport { EraSdkError } from '../core/errors';\n\n/**\n * Minimal protobuf wire codec for the Tron signing envelope. Varint and\n * length-delimited wire types only — the schema uses nothing else.\n *\n * Writer semantics mirror the reference implementation: EXPLICITLY SET fields\n * are written even when they hold default values (a `timestamp` of 0 is\n * `tag, 0x00` on the wire), and fields are emitted in ascending field-number\n * order. Byte-exactness against the golden fixtures depends on both.\n */\n\nexport class ProtoWriter {\n private readonly parts: Uint8Array[] = [];\n\n varintField(field: number, value: number | bigint): this {\n this.parts.push(tag(field, 0), varint(value));\n return this;\n }\n\n stringField(field: number, value: string): this {\n const bytes = utf8Encode(value);\n this.parts.push(tag(field, 2), varint(bytes.length), bytes);\n return this;\n }\n\n bytesField(field: number, value: Uint8Array): this {\n this.parts.push(tag(field, 2), varint(value.length), value);\n return this;\n }\n\n messageField(field: number, encoded: Uint8Array): this {\n this.parts.push(tag(field, 2), varint(encoded.length), encoded);\n return this;\n }\n\n finish(): Uint8Array {\n return concatBytes(...this.parts);\n }\n}\n\nfunction tag(field: number, wireType: number): Uint8Array {\n return varint((field << 3) | wireType);\n}\n\nexport function varint(value: number | bigint): Uint8Array {\n let v = typeof value === 'number' ? BigInt(value) : value;\n if (v < 0n) throw new EraSdkError('protobuf-error', 'negative varint');\n const out: number[] = [];\n do {\n let byte = Number(v & 0x7fn);\n v >>= 7n;\n if (v > 0n) byte |= 0x80;\n out.push(byte);\n } while (v > 0n);\n return new Uint8Array(out);\n}\n\nexport interface ProtoField {\n readonly field: number;\n readonly wireType: number;\n /** Set for wire type 0. */\n readonly value: bigint;\n /** Set for wire type 2 (verbatim slice of the input). */\n readonly bytes: Uint8Array;\n}\n\n/**\n * Hardened field reader: varint shift capped, lengths bounds-checked before\n * slicing, unknown fields skippable by wire type, group wire types refused.\n */\nexport function readFields(bytes: Uint8Array): ProtoField[] {\n const fields: ProtoField[] = [];\n let offset = 0;\n\n const readVarint = (): bigint => {\n let result = 0n;\n let shift = 0n;\n for (;;) {\n const byte = bytes[offset];\n if (byte === undefined) throw new EraSdkError('protobuf-error', 'truncated varint');\n offset += 1;\n result |= BigInt(byte & 0x7f) << shift;\n if ((byte & 0x80) === 0) return result;\n shift += 7n;\n if (shift > 63n) throw new EraSdkError('protobuf-error', 'varint exceeds 64 bits');\n }\n };\n\n while (offset < bytes.length) {\n const key = readVarint();\n const field = Number(key >> 3n);\n const wireType = Number(key & 7n);\n if (field === 0) throw new EraSdkError('protobuf-error', 'field number 0');\n switch (wireType) {\n case 0: {\n fields.push({ field, wireType, value: readVarint(), bytes: EMPTY });\n break;\n }\n case 1: {\n if (offset + 8 > bytes.length) throw new EraSdkError('protobuf-error', 'truncated fixed64');\n fields.push({ field, wireType, value: 0n, bytes: bytes.slice(offset, offset + 8) });\n offset += 8;\n break;\n }\n case 2: {\n const length = readVarint();\n if (length > BigInt(bytes.length - offset)) {\n throw new EraSdkError('protobuf-error', 'length-delimited field exceeds input');\n }\n const len = Number(length);\n fields.push({ field, wireType, value: 0n, bytes: bytes.slice(offset, offset + len) });\n offset += len;\n break;\n }\n case 5: {\n if (offset + 4 > bytes.length) throw new EraSdkError('protobuf-error', 'truncated fixed32');\n fields.push({ field, wireType, value: 0n, bytes: bytes.slice(offset, offset + 4) });\n offset += 4;\n break;\n }\n default:\n throw new EraSdkError('protobuf-error', `unsupported wire type ${wireType}`);\n }\n }\n return fields;\n}\n\nconst EMPTY = new Uint8Array(0);\n\n/** First occurrence of a length-delimited field, or null. */\nexport function firstBytes(fields: ProtoField[], field: number): Uint8Array | null {\n for (const f of fields) {\n if (f.field === field && f.wireType === 2) return f.bytes;\n }\n return null;\n}\n\n/** First occurrence of a varint field, or null. */\nexport function firstVarint(fields: ProtoField[], field: number): bigint | null {\n for (const f of fields) {\n if (f.field === field && f.wireType === 0) return f.value;\n }\n return null;\n}\n","import { hexToBytes, utf8Decode } from '../core/bytes';\nimport { EraSdkError } from '../core/errors';\nimport { firstBytes, ProtoWriter, readFields } from './wire';\n\n/**\n * The Tron signing envelope (\"QrCode Protocol\"):\n * `Base -> Payload -> SignTransaction -> TronTx`, gzip-compressed and wrapped\n * in a `keystone-sign-request` (6101) CBOR map. Schemas are vendored under\n * `proto/tron/`; this codec hand-writes the five messages the wallet side\n * speaks, with reference-exact field emission (explicitly-set defaults ARE\n * written; ascending field order).\n */\n\nexport interface TronLatestBlock {\n /** FULL 64-hex block id of a live now-block (the device slices ref_block_hash from it). */\n readonly hash: string;\n readonly number: number;\n readonly timestamp: number;\n}\n\nexport interface TronSignRequestProto {\n /** Lowercase, ZERO-PADDED 8-hex source fingerprint (the wire demands the string form). */\n readonly xfpHex: string;\n /** Hyphenated UUID string; echoed by the device as the only reply binding. */\n readonly signId: string;\n readonly hdPath: string;\n readonly timestamp: number;\n readonly decimals: number;\n readonly token: string;\n readonly contractAddress?: string | undefined;\n readonly from?: string | undefined;\n readonly to?: string | undefined;\n readonly memo?: string | undefined;\n readonly value?: string | undefined;\n readonly fee?: number | undefined;\n readonly latestBlock: TronLatestBlock;\n /** Serialized `Transaction.raw_data` — the signing source of truth. */\n readonly rawData: Uint8Array;\n}\n\nconst PAYLOAD_TYPE_SIGN_TX = 2;\n\nexport function encodeSignRequestProto(req: TronSignRequestProto): Uint8Array {\n if (req.fee !== undefined && (req.fee < 0 || req.fee > 0x7fffffff)) {\n throw new EraSdkError('invalid-props', 'tron fee must fit a positive int32');\n }\n const latestBlock = new ProtoWriter()\n .stringField(1, req.latestBlock.hash)\n .varintField(2, req.latestBlock.number)\n .varintField(3, req.latestBlock.timestamp)\n .finish();\n\n const tronTx = new ProtoWriter().stringField(1, req.token);\n if (req.contractAddress !== undefined) tronTx.stringField(2, req.contractAddress);\n if (req.from !== undefined) tronTx.stringField(3, req.from);\n if (req.to !== undefined) tronTx.stringField(4, req.to);\n if (req.memo !== undefined) tronTx.stringField(5, req.memo);\n if (req.value !== undefined) tronTx.stringField(6, req.value);\n tronTx.messageField(7, latestBlock);\n if (req.fee !== undefined) tronTx.varintField(9, req.fee);\n tronTx.bytesField(10, req.rawData);\n\n const signTx = new ProtoWriter()\n .stringField(1, 'TRON')\n .stringField(2, req.signId)\n .stringField(3, req.hdPath)\n .varintField(4, req.timestamp)\n .varintField(5, req.decimals)\n .messageField(8, tronTx.finish())\n .finish();\n\n const payload = new ProtoWriter()\n .varintField(1, PAYLOAD_TYPE_SIGN_TX)\n .stringField(2, req.xfpHex)\n .messageField(4, signTx)\n .finish();\n\n return new ProtoWriter()\n .varintField(1, 2) // Base.version\n .stringField(2, 'QrCode Protocol')\n .messageField(3, payload)\n .finish();\n}\n\nexport interface TronSignResultProto {\n readonly signId: string;\n readonly txId: string;\n readonly rawTx: string;\n}\n\n/** Parse a `keystone-sign-result` Base protobuf. Unknown fields are skipped. */\nexport function decodeSignResultProto(bytes: Uint8Array): TronSignResultProto {\n const base = readFields(bytes);\n const payloadBytes = firstBytes(base, 3);\n if (!payloadBytes) {\n throw new EraSdkError('malformed-reply', 'keystone-sign-result carries no payload');\n }\n const payload = readFields(payloadBytes);\n const resultBytes = firstBytes(payload, 7); // Payload.signTxResult\n if (!resultBytes) {\n return { signId: '', txId: '', rawTx: '' };\n }\n const result = readFields(resultBytes);\n return {\n signId: text(firstBytes(result, 1)),\n txId: text(firstBytes(result, 2)),\n rawTx: text(firstBytes(result, 3)),\n };\n}\n\nfunction text(bytes: Uint8Array | null): string {\n if (!bytes) return '';\n try {\n return utf8Decode(bytes);\n } catch {\n throw new EraSdkError('malformed-reply', 'protobuf string field is not valid UTF-8');\n }\n}\n\nexport interface SignedTronTx {\n /** Verbatim `raw_data` slice — the digest is sha256 over the device's own serialization. */\n readonly rawData: Uint8Array;\n readonly signatures: readonly Uint8Array[];\n}\n\n/**\n * Split a signed Tron network `Transaction` frame (`{1: raw_data, 2: signature*}`)\n * from the reply's `rawTx` hex. Top-level fields must be length-delimited —\n * anything else is not a transaction frame.\n */\nexport function splitSignedTronTx(rawTxHex: string): SignedTronTx {\n let frame: Uint8Array;\n try {\n frame = hexToBytes(rawTxHex);\n } catch {\n throw new EraSdkError('malformed-reply', 'signed Tron transaction is not hex');\n }\n const fields = readFields(frame);\n let rawData: Uint8Array | null = null;\n const signatures: Uint8Array[] = [];\n for (const f of fields) {\n if (f.wireType !== 2) {\n throw new EraSdkError('malformed-reply', 'unexpected wire type in signed Tron transaction');\n }\n if (f.field === 1 && rawData === null) rawData = f.bytes;\n if (f.field === 2) signatures.push(f.bytes);\n }\n if (rawData === null) {\n throw new EraSdkError('malformed-reply', 'signed Tron transaction carries no raw_data');\n }\n return { rawData, signatures };\n}\n"],"mappings":";;;;;;;;;;;AAaA,IAAa,cAAb,MAAyB;;EACvB,KAAiB,QAAsB,CAAC;;CAExC,YAAY,OAAe,OAA8B;EACvD,KAAK,MAAM,KAAK,IAAI,OAAO,CAAC,GAAG,OAAO,KAAK,CAAC;EAC5C,OAAO;CACT;CAEA,YAAY,OAAe,OAAqB;EAC9C,MAAM,QAAQA,eAAAA,WAAW,KAAK;EAC9B,KAAK,MAAM,KAAK,IAAI,OAAO,CAAC,GAAG,OAAO,MAAM,MAAM,GAAG,KAAK;EAC1D,OAAO;CACT;CAEA,WAAW,OAA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B,iDAAiD;EAE5F,IAAI,EAAE,UAAU,KAAK,YAAY,MAAM,UAAU,EAAE;EACnD,IAAI,EAAE,UAAU,GAAG,WAAW,KAAK,EAAE,KAAK;CAC5C;CACA,IAAI,YAAY,MACd,MAAM,IAAIA,eAAAA,YAAY,mBAAmB,6CAA6C;CAExF,OAAO;EAAE;EAAS;CAAW;AAC/B"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
//#region src/tron-proto/messages.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* The Tron signing envelope ("QrCode Protocol"):
|
|
4
|
+
* `Base -> Payload -> SignTransaction -> TronTx`, gzip-compressed and wrapped
|
|
5
|
+
* in a `keystone-sign-request` (6101) CBOR map. Schemas are vendored under
|
|
6
|
+
* `proto/tron/`; this codec hand-writes the five messages the wallet side
|
|
7
|
+
* speaks, with reference-exact field emission (explicitly-set defaults ARE
|
|
8
|
+
* written; ascending field order).
|
|
9
|
+
*/
|
|
10
|
+
interface TronLatestBlock {
|
|
11
|
+
/** FULL 64-hex block id of a live now-block (the device slices ref_block_hash from it). */
|
|
12
|
+
readonly hash: string;
|
|
13
|
+
readonly number: number;
|
|
14
|
+
readonly timestamp: number;
|
|
15
|
+
}
|
|
16
|
+
interface SignedTronTx {
|
|
17
|
+
/** Verbatim `raw_data` slice — the digest is sha256 over the device's own serialization. */
|
|
18
|
+
readonly rawData: Uint8Array;
|
|
19
|
+
readonly signatures: readonly Uint8Array[];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Split a signed Tron network `Transaction` frame (`{1: raw_data, 2: signature*}`)
|
|
23
|
+
* from the reply's `rawTx` hex. Top-level fields must be length-delimited —
|
|
24
|
+
* anything else is not a transaction frame.
|
|
25
|
+
*/
|
|
26
|
+
declare function splitSignedTronTx(rawTxHex: string): SignedTronTx;
|
|
27
|
+
//#endregion
|
|
28
|
+
export { TronLatestBlock as n, splitSignedTronTx as r, SignedTronTx as t };
|
|
29
|
+
//# sourceMappingURL=messages-DsPvW8Oi.d.cts.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
//#region src/tron-proto/messages.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* The Tron signing envelope ("QrCode Protocol"):
|
|
4
|
+
* `Base -> Payload -> SignTransaction -> TronTx`, gzip-compressed and wrapped
|
|
5
|
+
* in a `keystone-sign-request` (6101) CBOR map. Schemas are vendored under
|
|
6
|
+
* `proto/tron/`; this codec hand-writes the five messages the wallet side
|
|
7
|
+
* speaks, with reference-exact field emission (explicitly-set defaults ARE
|
|
8
|
+
* written; ascending field order).
|
|
9
|
+
*/
|
|
10
|
+
interface TronLatestBlock {
|
|
11
|
+
/** FULL 64-hex block id of a live now-block (the device slices ref_block_hash from it). */
|
|
12
|
+
readonly hash: string;
|
|
13
|
+
readonly number: number;
|
|
14
|
+
readonly timestamp: number;
|
|
15
|
+
}
|
|
16
|
+
interface SignedTronTx {
|
|
17
|
+
/** Verbatim `raw_data` slice — the digest is sha256 over the device's own serialization. */
|
|
18
|
+
readonly rawData: Uint8Array;
|
|
19
|
+
readonly signatures: readonly Uint8Array[];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Split a signed Tron network `Transaction` frame (`{1: raw_data, 2: signature*}`)
|
|
23
|
+
* from the reply's `rawTx` hex. Top-level fields must be length-delimited —
|
|
24
|
+
* anything else is not a transaction frame.
|
|
25
|
+
*/
|
|
26
|
+
declare function splitSignedTronTx(rawTxHex: string): SignedTronTx;
|
|
27
|
+
//#endregion
|
|
28
|
+
export { TronLatestBlock as n, splitSignedTronTx as r, SignedTronTx as t };
|
|
29
|
+
//# sourceMappingURL=messages-DsPvW8Oi.d.ts.map
|