@hashgraphonline/standards-sdk 0.1.141-canary.40 → 0.1.141-canary.41
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/dist/cjs/hcs-21/types.d.ts +10 -10
- package/dist/cjs/standards-sdk.cjs +1 -1
- package/dist/cjs/standards-sdk.cjs.map +1 -1
- package/dist/es/hcs-21/types.d.ts +10 -10
- package/dist/es/standards-sdk.es100.js +1 -1
- package/dist/es/standards-sdk.es102.js +1 -1
- package/dist/es/standards-sdk.es104.js +1 -1
- package/dist/es/standards-sdk.es110.js +1 -1
- package/dist/es/standards-sdk.es111.js +5 -5
- package/dist/es/standards-sdk.es12.js +1 -1
- package/dist/es/standards-sdk.es121.js +1 -1
- package/dist/es/standards-sdk.es122.js +1 -1
- package/dist/es/standards-sdk.es123.js +5 -5
- package/dist/es/standards-sdk.es125.js +1 -1
- package/dist/es/standards-sdk.es126.js +1 -1
- package/dist/es/standards-sdk.es128.js +2 -2
- package/dist/es/standards-sdk.es129.js +1 -1
- package/dist/es/standards-sdk.es13.js +1 -1
- package/dist/es/standards-sdk.es136.js +13 -134
- package/dist/es/standards-sdk.es136.js.map +1 -1
- package/dist/es/standards-sdk.es137.js +133 -37
- package/dist/es/standards-sdk.es137.js.map +1 -1
- package/dist/es/standards-sdk.es138.js +746 -12254
- package/dist/es/standards-sdk.es138.js.map +1 -1
- package/dist/es/standards-sdk.es139.js +42 -766
- package/dist/es/standards-sdk.es139.js.map +1 -1
- package/dist/es/standards-sdk.es140.js +12235 -133
- package/dist/es/standards-sdk.es140.js.map +1 -1
- package/dist/es/standards-sdk.es141.js +55 -321
- package/dist/es/standards-sdk.es141.js.map +1 -1
- package/dist/es/standards-sdk.es142.js +67 -331
- package/dist/es/standards-sdk.es142.js.map +1 -1
- package/dist/es/standards-sdk.es143.js +129 -410
- package/dist/es/standards-sdk.es143.js.map +1 -1
- package/dist/es/standards-sdk.es144.js +200 -209
- package/dist/es/standards-sdk.es144.js.map +1 -1
- package/dist/es/standards-sdk.es145.js +334 -64
- package/dist/es/standards-sdk.es145.js.map +1 -1
- package/dist/es/standards-sdk.es146.js +449 -13
- package/dist/es/standards-sdk.es146.js.map +1 -1
- package/dist/es/standards-sdk.es147.js +330 -55
- package/dist/es/standards-sdk.es147.js.map +1 -1
- package/dist/es/standards-sdk.es148.js +60 -66
- package/dist/es/standards-sdk.es148.js.map +1 -1
- package/dist/es/standards-sdk.es17.js +1 -1
- package/dist/es/standards-sdk.es19.js +4 -4
- package/dist/es/standards-sdk.es20.js +2 -2
- package/dist/es/standards-sdk.es23.js +1 -1
- package/dist/es/standards-sdk.es28.js +3 -3
- package/dist/es/standards-sdk.es31.js +1 -1
- package/dist/es/standards-sdk.es32.js +1 -1
- package/dist/es/standards-sdk.es36.js +2 -2
- package/dist/es/standards-sdk.es37.js +3 -3
- package/dist/es/standards-sdk.es38.js +1 -1
- package/dist/es/standards-sdk.es5.js +1 -1
- package/dist/es/standards-sdk.es54.js +1 -1
- package/dist/es/standards-sdk.es57.js +1 -1
- package/dist/es/standards-sdk.es59.js +1 -1
- package/dist/es/standards-sdk.es60.js +1 -1
- package/dist/es/standards-sdk.es61.js +2 -2
- package/dist/es/standards-sdk.es63.js +1 -1
- package/dist/es/standards-sdk.es65.js +1 -1
- package/dist/es/standards-sdk.es66.js +2 -2
- package/dist/es/standards-sdk.es69.js +2 -2
- package/dist/es/standards-sdk.es70.js +1 -1
- package/dist/es/standards-sdk.es72.js +1 -1
- package/dist/es/standards-sdk.es77.js +1 -1
- package/dist/es/standards-sdk.es78.js +1 -1
- package/dist/es/standards-sdk.es79.js +1 -1
- package/dist/es/standards-sdk.es8.js +1 -1
- package/dist/es/standards-sdk.es80.js +1 -1
- package/dist/es/standards-sdk.es80.js.map +1 -1
- package/dist/es/standards-sdk.es82.js +1 -1
- package/dist/es/standards-sdk.es84.js +1 -1
- package/dist/es/standards-sdk.es88.js +1 -1
- package/dist/es/standards-sdk.es92.js +1 -1
- package/dist/es/standards-sdk.es93.js +1 -1
- package/dist/es/standards-sdk.es98.js +1 -1
- package/package.json +61 -63
|
@@ -1,325 +1,59 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
type: "FILECREATE",
|
|
54
|
-
humanReadableType: "File Create",
|
|
55
|
-
fileCreate
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
if (txBody.fileAppend) {
|
|
60
|
-
const fileAppend = this.parseFileAppend(txBody.fileAppend);
|
|
61
|
-
if (fileAppend) {
|
|
62
|
-
return {
|
|
63
|
-
type: "FILEAPPEND",
|
|
64
|
-
humanReadableType: "File Append",
|
|
65
|
-
fileAppend
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
if (txBody.fileUpdate) {
|
|
70
|
-
const fileUpdate = this.parseFileUpdate(txBody.fileUpdate);
|
|
71
|
-
if (fileUpdate) {
|
|
72
|
-
return {
|
|
73
|
-
type: "FILEUPDATE",
|
|
74
|
-
humanReadableType: "File Update",
|
|
75
|
-
fileUpdate
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
if (txBody.fileDelete) {
|
|
80
|
-
const fileDelete = this.parseFileDelete(txBody.fileDelete);
|
|
81
|
-
if (fileDelete) {
|
|
82
|
-
return {
|
|
83
|
-
type: "FILEDELETE",
|
|
84
|
-
humanReadableType: "File Delete",
|
|
85
|
-
fileDelete
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return {};
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Extract file data from Transaction internal fields
|
|
93
|
-
* This handles cases where data is stored in Transaction object internals
|
|
94
|
-
*/
|
|
95
|
-
static parseFromTransactionInternals(transaction) {
|
|
96
|
-
try {
|
|
97
|
-
const tx = transaction;
|
|
98
|
-
if (hasTransactionType(transaction, "fileCreate")) {
|
|
99
|
-
const fileCreate = {};
|
|
100
|
-
if (tx._contents) {
|
|
101
|
-
const contentInfo = this.analyzeContent(tx._contents);
|
|
102
|
-
fileCreate.contents = contentInfo.encoded;
|
|
103
|
-
if (contentInfo.contentType) {
|
|
104
|
-
fileCreate.contentType = contentInfo.contentType;
|
|
105
|
-
}
|
|
106
|
-
if (contentInfo.size) {
|
|
107
|
-
fileCreate.contentSize = contentInfo.size;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
if (tx._keys && tx._keys.length > 0) {
|
|
111
|
-
const keyList = {
|
|
112
|
-
keys: tx._keys
|
|
113
|
-
};
|
|
114
|
-
fileCreate.keys = parseKey({ keyList });
|
|
115
|
-
}
|
|
116
|
-
if (tx._expirationTime) {
|
|
117
|
-
fileCreate.expirationTime = tx._expirationTime.toString();
|
|
118
|
-
}
|
|
119
|
-
if (tx._memo) {
|
|
120
|
-
fileCreate.memo = tx._memo;
|
|
121
|
-
}
|
|
122
|
-
return {
|
|
123
|
-
type: "FILECREATE",
|
|
124
|
-
humanReadableType: "File Create",
|
|
125
|
-
fileCreate
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
if (hasTransactionType(transaction, "fileAppend")) {
|
|
129
|
-
const fileAppend = {
|
|
130
|
-
fileId: tx._fileId.toString()
|
|
131
|
-
};
|
|
132
|
-
if (tx._contents) {
|
|
133
|
-
const contentInfo = this.analyzeContent(tx._contents);
|
|
134
|
-
fileAppend.contents = contentInfo.encoded;
|
|
135
|
-
if (contentInfo.size) {
|
|
136
|
-
fileAppend.contentSize = contentInfo.size;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
return {
|
|
140
|
-
type: "FILEAPPEND",
|
|
141
|
-
humanReadableType: "File Append",
|
|
142
|
-
fileAppend
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
if (hasTransactionType(transaction, "fileUpdate")) {
|
|
146
|
-
const fileUpdate = {
|
|
147
|
-
fileId: tx._fileId.toString()
|
|
148
|
-
};
|
|
149
|
-
if (tx._contents) {
|
|
150
|
-
const contentInfo = this.analyzeContent(tx._contents);
|
|
151
|
-
fileUpdate.contents = contentInfo.encoded;
|
|
152
|
-
if (contentInfo.size) {
|
|
153
|
-
fileUpdate.contentSize = contentInfo.size;
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
if (tx._keys && tx._keys.length > 0) {
|
|
157
|
-
const keyList = {
|
|
158
|
-
keys: tx._keys
|
|
159
|
-
};
|
|
160
|
-
fileUpdate.keys = parseKey({ keyList });
|
|
161
|
-
}
|
|
162
|
-
if (tx._expirationTime) {
|
|
163
|
-
fileUpdate.expirationTime = tx._expirationTime.toString();
|
|
164
|
-
}
|
|
165
|
-
if (tx._memo) {
|
|
166
|
-
fileUpdate.memo = tx._memo;
|
|
167
|
-
}
|
|
168
|
-
return {
|
|
169
|
-
type: "FILEUPDATE",
|
|
170
|
-
humanReadableType: "File Update",
|
|
171
|
-
fileUpdate
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
if (hasTransactionType(transaction, "fileDelete")) {
|
|
175
|
-
const fileDelete = {
|
|
176
|
-
fileId: tx._fileId.toString()
|
|
177
|
-
};
|
|
178
|
-
return {
|
|
179
|
-
type: "FILEDELETE",
|
|
180
|
-
humanReadableType: "File Delete",
|
|
181
|
-
fileDelete
|
|
182
|
-
};
|
|
183
|
-
}
|
|
184
|
-
return {};
|
|
185
|
-
} catch (error) {
|
|
186
|
-
return {};
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
/**
|
|
190
|
-
* Enhanced content analysis with type detection and metadata
|
|
191
|
-
*/
|
|
192
|
-
static analyzeContent(contents) {
|
|
193
|
-
const size = contents.length;
|
|
194
|
-
const contentBuffer = Buffer.from(contents);
|
|
195
|
-
let contentType;
|
|
196
|
-
if (size >= 4) {
|
|
197
|
-
const header = contentBuffer.subarray(0, 4);
|
|
198
|
-
const headerHex = header.toString("hex");
|
|
199
|
-
const signatures = {
|
|
200
|
-
"89504e47": "image/png",
|
|
201
|
-
ffd8ffe0: "image/jpeg",
|
|
202
|
-
ffd8ffe1: "image/jpeg",
|
|
203
|
-
"47494638": "image/gif",
|
|
204
|
-
"25504446": "application/pdf",
|
|
205
|
-
"504b0304": "application/zip",
|
|
206
|
-
"7f454c46": "application/x-executable",
|
|
207
|
-
d0cf11e0: "application/msoffice"
|
|
208
|
-
};
|
|
209
|
-
contentType = signatures[headerHex.toLowerCase()];
|
|
210
|
-
}
|
|
211
|
-
if (!contentType) {
|
|
212
|
-
try {
|
|
213
|
-
const textContent = contentBuffer.toString("utf8");
|
|
214
|
-
const hasControlChars = /[\x00-\x08\x0B\x0E-\x1F\x7F]/.test(
|
|
215
|
-
textContent
|
|
216
|
-
);
|
|
217
|
-
const hasReplacementChars = textContent.includes("�");
|
|
218
|
-
if (!hasControlChars && !hasReplacementChars) {
|
|
219
|
-
if (textContent.trim().startsWith("{") && textContent.trim().endsWith("}")) {
|
|
220
|
-
contentType = "application/json";
|
|
221
|
-
} else if (textContent.includes("<?xml") || textContent.includes("<html")) {
|
|
222
|
-
contentType = "text/xml";
|
|
223
|
-
} else if (textContent.includes("<!DOCTYPE html")) {
|
|
224
|
-
contentType = "text/html";
|
|
225
|
-
} else {
|
|
226
|
-
contentType = "text/plain";
|
|
227
|
-
}
|
|
228
|
-
} else {
|
|
229
|
-
contentType = "application/octet-stream";
|
|
230
|
-
}
|
|
231
|
-
} catch {
|
|
232
|
-
contentType = "application/octet-stream";
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
let encoded;
|
|
236
|
-
if (contentType?.startsWith("text/") || contentType === "application/json") {
|
|
237
|
-
try {
|
|
238
|
-
encoded = contentBuffer.toString("utf8");
|
|
239
|
-
if (encoded.includes("�") || /[\x00-\x08\x0B\x0E-\x1F\x7F]/.test(encoded)) {
|
|
240
|
-
encoded = contentBuffer.toString("base64");
|
|
241
|
-
}
|
|
242
|
-
} catch {
|
|
243
|
-
encoded = contentBuffer.toString("base64");
|
|
244
|
-
}
|
|
245
|
-
} else {
|
|
246
|
-
encoded = contentBuffer.toString("base64");
|
|
247
|
-
}
|
|
248
|
-
return {
|
|
249
|
-
encoded,
|
|
250
|
-
contentType,
|
|
251
|
-
size
|
|
252
|
-
};
|
|
253
|
-
}
|
|
254
|
-
static parseFileCreate(body) {
|
|
255
|
-
if (!body) return void 0;
|
|
256
|
-
const data = {};
|
|
257
|
-
if (body.expirationTime?.seconds) {
|
|
258
|
-
data.expirationTime = `${Long.fromValue(
|
|
259
|
-
body.expirationTime.seconds
|
|
260
|
-
).toString()}.${body.expirationTime.nanos}`;
|
|
261
|
-
}
|
|
262
|
-
if (body.keys) {
|
|
263
|
-
data.keys = parseKey({ keyList: body.keys });
|
|
264
|
-
}
|
|
265
|
-
if (body.contents) {
|
|
266
|
-
data.contents = Buffer.from(body.contents).toString("base64");
|
|
267
|
-
}
|
|
268
|
-
if (body.memo) {
|
|
269
|
-
data.memo = body.memo;
|
|
270
|
-
}
|
|
271
|
-
return data;
|
|
272
|
-
}
|
|
273
|
-
static parseFileAppend(body) {
|
|
274
|
-
if (!body) return void 0;
|
|
275
|
-
const data = {};
|
|
276
|
-
if (body.fileID) {
|
|
277
|
-
data.fileId = `${body.fileID.shardNum ?? 0}.${body.fileID.realmNum ?? 0}.${body.fileID.fileNum ?? 0}`;
|
|
278
|
-
}
|
|
279
|
-
if (body.contents) {
|
|
280
|
-
data.contents = Buffer.from(body.contents).toString("base64");
|
|
281
|
-
}
|
|
282
|
-
return data;
|
|
283
|
-
}
|
|
284
|
-
static parseFileUpdate(body) {
|
|
285
|
-
if (!body) return void 0;
|
|
286
|
-
const data = {};
|
|
287
|
-
if (body.fileID) {
|
|
288
|
-
data.fileId = `${body.fileID.shardNum ?? 0}.${body.fileID.realmNum ?? 0}.${body.fileID.fileNum ?? 0}`;
|
|
289
|
-
}
|
|
290
|
-
if (body.expirationTime?.seconds) {
|
|
291
|
-
data.expirationTime = `${Long.fromValue(
|
|
292
|
-
body.expirationTime.seconds
|
|
293
|
-
).toString()}.${body.expirationTime.nanos}`;
|
|
294
|
-
}
|
|
295
|
-
if (body.keys) {
|
|
296
|
-
data.keys = parseKey({ keyList: body.keys });
|
|
297
|
-
}
|
|
298
|
-
if (body.contents) {
|
|
299
|
-
data.contents = Buffer.from(body.contents).toString("base64");
|
|
300
|
-
}
|
|
301
|
-
if (body.memo?.value !== void 0) {
|
|
302
|
-
data.memo = body.memo.value;
|
|
303
|
-
}
|
|
304
|
-
return data;
|
|
305
|
-
}
|
|
306
|
-
static parseFileDelete(body) {
|
|
307
|
-
if (!body) return void 0;
|
|
308
|
-
const data = {};
|
|
309
|
-
if (body.fileID) {
|
|
310
|
-
data.fileId = `${body.fileID.shardNum ?? 0}.${body.fileID.realmNum ?? 0}.${body.fileID.fileNum ?? 0}`;
|
|
311
|
-
}
|
|
312
|
-
return data;
|
|
313
|
-
}
|
|
314
|
-
/**
|
|
315
|
-
* Parse File Service transaction from Transaction object
|
|
316
|
-
* This is the unified entry point that delegates to the comprehensive parsing logic
|
|
317
|
-
*/
|
|
318
|
-
static parseFromTransactionObject(transaction) {
|
|
319
|
-
return this.parseFileTransaction(transaction);
|
|
320
|
-
}
|
|
1
|
+
const ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
2
|
+
const BASE = 58;
|
|
3
|
+
function base58Encode(bytes) {
|
|
4
|
+
if (bytes.length === 0) return "";
|
|
5
|
+
let zeros = 0;
|
|
6
|
+
while (zeros < bytes.length && bytes[zeros] === 0) zeros++;
|
|
7
|
+
if (zeros === bytes.length) return "1".repeat(zeros);
|
|
8
|
+
const digits = [0];
|
|
9
|
+
for (let i = zeros; i < bytes.length; i++) {
|
|
10
|
+
let carry = bytes[i];
|
|
11
|
+
for (let j = 0; j < digits.length; j++) {
|
|
12
|
+
const val = (digits[j] << 8) + carry;
|
|
13
|
+
digits[j] = val % BASE;
|
|
14
|
+
carry = val / BASE | 0;
|
|
15
|
+
}
|
|
16
|
+
while (carry > 0) {
|
|
17
|
+
digits.push(carry % BASE);
|
|
18
|
+
carry = carry / BASE | 0;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
let result = "";
|
|
22
|
+
for (let i = 0; i < zeros; i++) result += "1";
|
|
23
|
+
for (let i = digits.length - 1; i >= 0; i--) result += ALPHABET[digits[i]];
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
26
|
+
function base58Decode(text) {
|
|
27
|
+
if (text.length === 0) return new Uint8Array(0);
|
|
28
|
+
let zeros = 0;
|
|
29
|
+
while (zeros < text.length && text[zeros] === "1") zeros++;
|
|
30
|
+
const b256 = [];
|
|
31
|
+
for (let i = zeros; i < text.length; i++) {
|
|
32
|
+
const ch = text[i];
|
|
33
|
+
const val = ALPHABET.indexOf(ch);
|
|
34
|
+
if (val === -1) throw new Error("Invalid Base58 character");
|
|
35
|
+
let carry = val;
|
|
36
|
+
for (let j = 0; j < b256.length; j++) {
|
|
37
|
+
const x = b256[j] * BASE + carry;
|
|
38
|
+
b256[j] = x & 255;
|
|
39
|
+
carry = x >> 8;
|
|
40
|
+
}
|
|
41
|
+
while (carry > 0) {
|
|
42
|
+
b256.push(carry & 255);
|
|
43
|
+
carry >>= 8;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
for (let i = 0; i < zeros; i++) b256.push(0);
|
|
47
|
+
b256.reverse();
|
|
48
|
+
return Uint8Array.from(b256);
|
|
49
|
+
}
|
|
50
|
+
function multibaseB58btcDecode(zText) {
|
|
51
|
+
if (!zText.startsWith("z")) throw new Error("Invalid multibase base58btc");
|
|
52
|
+
return base58Decode(zText.slice(1));
|
|
321
53
|
}
|
|
322
54
|
export {
|
|
323
|
-
|
|
55
|
+
base58Decode,
|
|
56
|
+
base58Encode,
|
|
57
|
+
multibaseB58btcDecode
|
|
324
58
|
};
|
|
325
59
|
//# sourceMappingURL=standards-sdk.es141.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standards-sdk.es141.js","sources":["../../src/utils/parsers/file-parser.ts"],"sourcesContent":["import { proto } from '@hashgraph/proto';\nimport { Long, Transaction } from '@hashgraph/sdk';\nimport {\n FileCreateData,\n FileAppendData,\n FileUpdateData,\n FileDeleteData,\n} from '../transaction-parser-types';\nimport {\n parseKey,\n extractTransactionBody,\n hasTransactionType,\n} from './parser-utils';\nimport { Buffer } from 'buffer';\nimport { FileId } from '@hashgraph/sdk';\n\n/**\n * File Service Parser\n *\n * Handles parsing for all file-related transaction types including:\n * - File creation, updates, append, and deletion\n * - Proper dual-branch parsing (regular vs signed transactions)\n * - Comprehensive protobuf extraction\n * - Enhanced content handling with type detection\n */\nexport class FileParser {\n /**\n * Parse File Service transaction using unified dual-branch approach\n * This handles both regular transactions and signed transaction variants\n */\n static parseFileTransaction(\n transaction: Transaction,\n originalBytes?: Uint8Array,\n ): {\n type?: string;\n humanReadableType?: string;\n fileCreate?: FileCreateData;\n fileAppend?: FileAppendData;\n fileUpdate?: FileUpdateData;\n fileDelete?: FileDeleteData;\n [key: string]: unknown;\n } {\n try {\n if (originalBytes || transaction.toBytes) {\n try {\n const bytesToParse = originalBytes || transaction.toBytes();\n const decoded = proto.TransactionList.decode(bytesToParse);\n\n if (decoded.transactionList && decoded.transactionList.length > 0) {\n const tx = decoded.transactionList[0];\n let txBody: proto.ITransactionBody | null = null;\n\n if (tx.bodyBytes && tx.bodyBytes.length > 0) {\n txBody = proto.TransactionBody.decode(tx.bodyBytes);\n } else if (\n tx.signedTransactionBytes &&\n tx.signedTransactionBytes.length > 0\n ) {\n const signedTx = proto.SignedTransaction.decode(\n tx.signedTransactionBytes,\n );\n if (signedTx.bodyBytes) {\n txBody = proto.TransactionBody.decode(signedTx.bodyBytes);\n }\n }\n\n if (txBody) {\n const protoResult = this.parseFromProtobufTxBody(txBody);\n if (protoResult.type && protoResult.type !== 'UNKNOWN') {\n return protoResult;\n }\n }\n }\n } catch (protoError) {}\n }\n\n return this.parseFromTransactionInternals(transaction);\n } catch (error) {\n return { type: 'UNKNOWN', humanReadableType: 'Unknown File Transaction' };\n }\n }\n\n /**\n * Parse file transaction from protobuf TransactionBody\n * Handles all file operations from decoded protobuf data\n */\n private static parseFromProtobufTxBody(txBody: proto.ITransactionBody): {\n type?: string;\n humanReadableType?: string;\n [key: string]: unknown;\n } {\n if (txBody.fileCreate) {\n const fileCreate = this.parseFileCreate(txBody.fileCreate);\n if (fileCreate) {\n return {\n type: 'FILECREATE',\n humanReadableType: 'File Create',\n fileCreate,\n };\n }\n }\n\n if (txBody.fileAppend) {\n const fileAppend = this.parseFileAppend(txBody.fileAppend);\n if (fileAppend) {\n return {\n type: 'FILEAPPEND',\n humanReadableType: 'File Append',\n fileAppend,\n };\n }\n }\n\n if (txBody.fileUpdate) {\n const fileUpdate = this.parseFileUpdate(txBody.fileUpdate);\n if (fileUpdate) {\n return {\n type: 'FILEUPDATE',\n humanReadableType: 'File Update',\n fileUpdate,\n };\n }\n }\n\n if (txBody.fileDelete) {\n const fileDelete = this.parseFileDelete(txBody.fileDelete);\n if (fileDelete) {\n return {\n type: 'FILEDELETE',\n humanReadableType: 'File Delete',\n fileDelete,\n };\n }\n }\n\n return {};\n }\n\n /**\n * Extract file data from Transaction internal fields\n * This handles cases where data is stored in Transaction object internals\n */\n private static parseFromTransactionInternals(transaction: Transaction): {\n type?: string;\n humanReadableType?: string;\n [key: string]: unknown;\n } {\n try {\n const tx = transaction as unknown as {\n _fileId?: { toString(): string };\n _contents?: Uint8Array;\n _keys?: unknown[];\n _expirationTime?: { toString(): string };\n _memo?: string;\n constructor?: { name?: string };\n };\n\n if (hasTransactionType(transaction, 'fileCreate')) {\n const fileCreate: FileCreateData = {};\n\n if (tx._contents) {\n const contentInfo = this.analyzeContent(tx._contents);\n fileCreate.contents = contentInfo.encoded;\n if (contentInfo.contentType) {\n fileCreate.contentType = contentInfo.contentType;\n }\n if (contentInfo.size) {\n fileCreate.contentSize = contentInfo.size;\n }\n }\n\n if (tx._keys && tx._keys.length > 0) {\n const keyList: proto.IKeyList = {\n keys: tx._keys as unknown as proto.IKey[],\n };\n fileCreate.keys = parseKey({ keyList });\n }\n\n if (tx._expirationTime) {\n fileCreate.expirationTime = tx._expirationTime.toString();\n }\n\n if (tx._memo) {\n fileCreate.memo = tx._memo;\n }\n\n return {\n type: 'FILECREATE',\n humanReadableType: 'File Create',\n fileCreate,\n };\n }\n\n if (hasTransactionType(transaction, 'fileAppend')) {\n const fileAppend: FileAppendData = {\n fileId: tx._fileId.toString(),\n };\n\n if (tx._contents) {\n const contentInfo = this.analyzeContent(tx._contents);\n fileAppend.contents = contentInfo.encoded;\n if (contentInfo.size) {\n fileAppend.contentSize = contentInfo.size;\n }\n }\n\n return {\n type: 'FILEAPPEND',\n humanReadableType: 'File Append',\n fileAppend,\n };\n }\n\n if (hasTransactionType(transaction, 'fileUpdate')) {\n const fileUpdate: FileUpdateData = {\n fileId: tx._fileId.toString(),\n };\n\n if (tx._contents) {\n const contentInfo = this.analyzeContent(tx._contents);\n fileUpdate.contents = contentInfo.encoded;\n if (contentInfo.size) {\n fileUpdate.contentSize = contentInfo.size;\n }\n }\n\n if (tx._keys && tx._keys.length > 0) {\n const keyList: proto.IKeyList = {\n keys: tx._keys as unknown as proto.IKey[],\n };\n fileUpdate.keys = parseKey({ keyList });\n }\n\n if (tx._expirationTime) {\n fileUpdate.expirationTime = tx._expirationTime.toString();\n }\n\n if (tx._memo) {\n fileUpdate.memo = tx._memo;\n }\n\n return {\n type: 'FILEUPDATE',\n humanReadableType: 'File Update',\n fileUpdate,\n };\n }\n\n if (hasTransactionType(transaction, 'fileDelete')) {\n const fileDelete: FileDeleteData = {\n fileId: tx._fileId.toString(),\n };\n\n return {\n type: 'FILEDELETE',\n humanReadableType: 'File Delete',\n fileDelete,\n };\n }\n\n return {};\n } catch (error) {\n return {};\n }\n }\n\n /**\n * Enhanced content analysis with type detection and metadata\n */\n private static analyzeContent(contents: Uint8Array): {\n encoded: string;\n contentType?: string;\n size: number;\n } {\n const size = contents.length;\n const contentBuffer = Buffer.from(contents);\n\n let contentType: string | undefined;\n\n if (size >= 4) {\n const header = contentBuffer.subarray(0, 4);\n const headerHex = header.toString('hex');\n\n const signatures: Record<string, string> = {\n '89504e47': 'image/png',\n ffd8ffe0: 'image/jpeg',\n ffd8ffe1: 'image/jpeg',\n '47494638': 'image/gif',\n '25504446': 'application/pdf',\n '504b0304': 'application/zip',\n '7f454c46': 'application/x-executable',\n d0cf11e0: 'application/msoffice',\n };\n\n contentType = signatures[headerHex.toLowerCase()];\n }\n\n if (!contentType) {\n try {\n const textContent = contentBuffer.toString('utf8');\n const hasControlChars = /[\\x00-\\x08\\x0B\\x0E-\\x1F\\x7F]/.test(\n textContent,\n );\n const hasReplacementChars = textContent.includes('\\uFFFD');\n\n if (!hasControlChars && !hasReplacementChars) {\n if (\n textContent.trim().startsWith('{') &&\n textContent.trim().endsWith('}')\n ) {\n contentType = 'application/json';\n } else if (\n textContent.includes('<?xml') ||\n textContent.includes('<html')\n ) {\n contentType = 'text/xml';\n } else if (textContent.includes('<!DOCTYPE html')) {\n contentType = 'text/html';\n } else {\n contentType = 'text/plain';\n }\n } else {\n contentType = 'application/octet-stream';\n }\n } catch {\n contentType = 'application/octet-stream';\n }\n }\n\n let encoded: string;\n if (\n contentType?.startsWith('text/') ||\n contentType === 'application/json'\n ) {\n try {\n encoded = contentBuffer.toString('utf8');\n if (\n encoded.includes('\\uFFFD') ||\n /[\\x00-\\x08\\x0B\\x0E-\\x1F\\x7F]/.test(encoded)\n ) {\n encoded = contentBuffer.toString('base64');\n }\n } catch {\n encoded = contentBuffer.toString('base64');\n }\n } else {\n encoded = contentBuffer.toString('base64');\n }\n\n return {\n encoded,\n contentType,\n size,\n };\n }\n static parseFileCreate(\n body: proto.IFileCreateTransactionBody,\n ): FileCreateData | undefined {\n if (!body) return undefined;\n const data: FileCreateData = {};\n if (body.expirationTime?.seconds) {\n data.expirationTime = `${Long.fromValue(\n body.expirationTime.seconds,\n ).toString()}.${body.expirationTime.nanos}`;\n }\n if (body.keys) {\n data.keys = parseKey({ keyList: body.keys });\n }\n if (body.contents) {\n data.contents = Buffer.from(body.contents).toString('base64');\n }\n if (body.memo) {\n data.memo = body.memo;\n }\n return data;\n }\n\n static parseFileAppend(\n body: proto.IFileAppendTransactionBody,\n ): FileAppendData | undefined {\n if (!body) return undefined;\n const data: FileAppendData = {};\n if (body.fileID) {\n data.fileId = `${body.fileID.shardNum ?? 0}.${\n body.fileID.realmNum ?? 0\n }.${body.fileID.fileNum ?? 0}`;\n }\n if (body.contents) {\n data.contents = Buffer.from(body.contents).toString('base64');\n }\n return data;\n }\n\n static parseFileUpdate(\n body: proto.IFileUpdateTransactionBody,\n ): FileUpdateData | undefined {\n if (!body) return undefined;\n const data: FileUpdateData = {};\n if (body.fileID) {\n data.fileId = `${body.fileID.shardNum ?? 0}.${\n body.fileID.realmNum ?? 0\n }.${body.fileID.fileNum ?? 0}`;\n }\n if (body.expirationTime?.seconds) {\n data.expirationTime = `${Long.fromValue(\n body.expirationTime.seconds,\n ).toString()}.${body.expirationTime.nanos}`;\n }\n if (body.keys) {\n data.keys = parseKey({ keyList: body.keys });\n }\n if (body.contents) {\n data.contents = Buffer.from(body.contents).toString('base64');\n }\n if (body.memo?.value !== undefined) {\n data.memo = body.memo.value;\n }\n return data;\n }\n\n static parseFileDelete(\n body: proto.IFileDeleteTransactionBody,\n ): FileDeleteData | undefined {\n if (!body) return undefined;\n const data: FileDeleteData = {};\n if (body.fileID) {\n data.fileId = `${body.fileID.shardNum ?? 0}.${\n body.fileID.realmNum ?? 0\n }.${body.fileID.fileNum ?? 0}`;\n }\n return data;\n }\n\n /**\n * Parse File Service transaction from Transaction object\n * This is the unified entry point that delegates to the comprehensive parsing logic\n */\n static parseFromTransactionObject(transaction: Transaction): {\n type?: string;\n humanReadableType?: string;\n [key: string]: unknown;\n } {\n return this.parseFileTransaction(transaction);\n }\n}\n"],"names":[],"mappings":";;;;AAyBO,MAAM,WAAW;AAAA;AAAA;AAAA;AAAA;AAAA,EAKtB,OAAO,qBACL,aACA,eASA;AACA,QAAI;AACF,UAAI,iBAAiB,YAAY,SAAS;AACxC,YAAI;AACF,gBAAM,eAAe,iBAAiB,YAAY,QAAA;AAClD,gBAAM,UAAU,MAAM,gBAAgB,OAAO,YAAY;AAEzD,cAAI,QAAQ,mBAAmB,QAAQ,gBAAgB,SAAS,GAAG;AACjE,kBAAM,KAAK,QAAQ,gBAAgB,CAAC;AACpC,gBAAI,SAAwC;AAE5C,gBAAI,GAAG,aAAa,GAAG,UAAU,SAAS,GAAG;AAC3C,uBAAS,MAAM,gBAAgB,OAAO,GAAG,SAAS;AAAA,YACpD,WACE,GAAG,0BACH,GAAG,uBAAuB,SAAS,GACnC;AACA,oBAAM,WAAW,MAAM,kBAAkB;AAAA,gBACvC,GAAG;AAAA,cAAA;AAEL,kBAAI,SAAS,WAAW;AACtB,yBAAS,MAAM,gBAAgB,OAAO,SAAS,SAAS;AAAA,cAC1D;AAAA,YACF;AAEA,gBAAI,QAAQ;AACV,oBAAM,cAAc,KAAK,wBA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AAM,QAAO;AAClB,UAAM,OAAuB,CAAA;AAC7B,QAAI,KAAK,QAAQ;AACf,WAAK,SAAS,GAAG,KAAK,OAAO,YAAY,CAAC,IACxC,KAAK,OAAO,YAAY,CAC1B,IAAI,KAAK,OAAO,WAAW,CAAC;AAAA,IAC9B;AACA,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,OAAO,2BAA2B,aAIhC;AACA,WAAO,KAAK,qBAAqB,WAAW;AAAA,EAC9C;AACF;"}
|
|
1
|
+
{"version":3,"file":"standards-sdk.es141.js","sources":["../../src/hcs-14/base58.ts"],"sourcesContent":["/**\n * Minimal Base58 encoder/decoder (Bitcoin alphabet) with no external dependencies.\n */\n\nconst ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';\nconst BASE = 58;\n\nfunction countLeadingZeros(bytes: Uint8Array): number {\n let zeros = 0;\n for (let i = 0; i < bytes.length && bytes[i] === 0; i++) {\n zeros++;\n }\n return zeros;\n}\n\nexport function base58Encode(bytes: Uint8Array): string {\n if (bytes.length === 0) return '';\n\n let zeros = 0;\n while (zeros < bytes.length && bytes[zeros] === 0) zeros++;\n\n if (zeros === bytes.length) return '1'.repeat(zeros);\n\n const digits: number[] = [0];\n for (let i = zeros; i < bytes.length; i++) {\n let carry = bytes[i];\n for (let j = 0; j < digits.length; j++) {\n const val = (digits[j] << 8) + carry;\n digits[j] = val % BASE;\n carry = (val / BASE) | 0;\n }\n while (carry > 0) {\n digits.push(carry % BASE);\n carry = (carry / BASE) | 0;\n }\n }\n\n let result = '';\n for (let i = 0; i < zeros; i++) result += '1';\n for (let i = digits.length - 1; i >= 0; i--) result += ALPHABET[digits[i]];\n return result;\n}\n\nexport function base58Decode(text: string): Uint8Array {\n if (text.length === 0) return new Uint8Array(0);\n\n let zeros = 0;\n while (zeros < text.length && text[zeros] === '1') zeros++;\n\n const b256: number[] = [];\n for (let i = zeros; i < text.length; i++) {\n const ch = text[i];\n const val = ALPHABET.indexOf(ch);\n if (val === -1) throw new Error('Invalid Base58 character');\n\n let carry = val;\n for (let j = 0; j < b256.length; j++) {\n const x = b256[j] * BASE + carry;\n b256[j] = x & 0xff;\n carry = x >> 8;\n }\n while (carry > 0) {\n b256.push(carry & 0xff);\n carry >>= 8;\n }\n }\n\n for (let i = 0; i < zeros; i++) b256.push(0);\n b256.reverse();\n return Uint8Array.from(b256);\n}\n\nexport function multibaseB58btcDecode(zText: string): Uint8Array {\n if (!zText.startsWith('z')) throw new Error('Invalid multibase base58btc');\n return base58Decode(zText.slice(1));\n}\n"],"names":[],"mappings":"AAIA,MAAM,WAAW;AACjB,MAAM,OAAO;AAUN,SAAS,aAAa,OAA2B;AACtD,MAAI,MAAM,WAAW,EAAG,QAAO;AAE/B,MAAI,QAAQ;AACZ,SAAO,QAAQ,MAAM,UAAU,MAAM,KAAK,MAAM,EAAG;AAEnD,MAAI,UAAU,MAAM,OAAQ,QAAO,IAAI,OAAO,KAAK;AAEnD,QAAM,SAAmB,CAAC,CAAC;AAC3B,WAAS,IAAI,OAAO,IAAI,MAAM,QAAQ,KAAK;AACzC,QAAI,QAAQ,MAAM,CAAC;AACnB,aAAS,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK;AACtC,YAAM,OAAO,OAAO,CAAC,KAAK,KAAK;AAC/B,aAAO,CAAC,IAAI,MAAM;AAClB,cAAS,MAAM,OAAQ;AAAA,IACzB;AACA,WAAO,QAAQ,GAAG;AAChB,aAAO,KAAK,QAAQ,IAAI;AACxB,cAAS,QAAQ,OAAQ;AAAA,IAC3B;AAAA,EACF;AAEA,MAAI,SAAS;AACb,WAAS,IAAI,GAAG,IAAI,OAAO,IAAK,WAAU;AAC1C,WAAS,IAAI,OAAO,SAAS,GAAG,KAAK,GAAG,IAAK,WAAU,SAAS,OAAO,CAAC,CAAC;AACzE,SAAO;AACT;AAEO,SAAS,aAAa,MAA0B;AACrD,MAAI,KAAK,WAAW,EAAG,QAAO,IAAI,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