@xyo-network/xl1-protocol-sdk 1.12.0 → 1.12.2
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/neutral/config/Api.d.ts +3 -3
- package/dist/neutral/config/Api.d.ts.map +1 -1
- package/dist/neutral/config/App.d.ts +3 -3
- package/dist/neutral/config/App.d.ts.map +1 -1
- package/dist/neutral/config/Chain.d.ts +2 -2
- package/dist/neutral/config/Chain.d.ts.map +1 -1
- package/dist/neutral/config/Config.d.ts +19 -19
- package/dist/neutral/config/Config.d.ts.map +1 -1
- package/dist/neutral/config/Evm.d.ts +6 -6
- package/dist/neutral/config/Evm.d.ts.map +1 -1
- package/dist/neutral/config/Log.d.ts +2 -2
- package/dist/neutral/config/Log.d.ts.map +1 -1
- package/dist/neutral/config/Producer.d.ts +5 -5
- package/dist/neutral/config/Producer.d.ts.map +1 -1
- package/dist/neutral/config/Telemetry.d.ts +4 -4
- package/dist/neutral/config/Telemetry.d.ts.map +1 -1
- package/dist/neutral/config/UsageMeta.d.ts +4 -4
- package/dist/neutral/config/UsageMeta.d.ts.map +1 -1
- package/dist/neutral/config/storage/Storage.d.ts +3 -3
- package/dist/neutral/config/storage/Storage.d.ts.map +1 -1
- package/dist/neutral/config/storage/driver/Mongo.d.ts +2 -2
- package/dist/neutral/config/storage/driver/Mongo.d.ts.map +1 -1
- package/dist/neutral/index.mjs +296 -157
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/neutral/transaction/signTransaction.d.ts +8 -1
- package/dist/neutral/transaction/signTransaction.d.ts.map +1 -1
- package/dist/neutral/transaction/spec/signTransaction.spec.d.ts +2 -0
- package/dist/neutral/transaction/spec/signTransaction.spec.d.ts.map +1 -0
- package/dist/neutral/validation/schema/Mnemonic.d.ts +1 -1
- package/dist/neutral/validation/schema/Mnemonic.d.ts.map +1 -1
- package/package.json +24 -22
- package/src/config/Api.ts +2 -1
- package/src/config/App.ts +2 -1
- package/src/config/Chain.ts +2 -1
- package/src/config/Config.ts +1 -1
- package/src/config/Evm.ts +2 -1
- package/src/config/Log.ts +2 -1
- package/src/config/Producer.ts +2 -1
- package/src/config/Telemetry.ts +2 -1
- package/src/config/UsageMeta.ts +1 -1
- package/src/config/storage/Storage.ts +2 -1
- package/src/config/storage/driver/Mongo.ts +2 -1
- package/src/transaction/signTransaction.ts +14 -2
- package/src/transaction/spec/signTransaction.spec.ts +46 -0
- package/src/validation/schema/Mnemonic.ts +1 -1
package/dist/neutral/index.mjs
CHANGED
|
@@ -1,69 +1,97 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
1
4
|
// src/block/hydrateBlock.ts
|
|
2
5
|
import { filterAs } from "@xylabs/array";
|
|
3
6
|
import { assertEx } from "@xylabs/assert";
|
|
4
|
-
import {
|
|
5
|
-
asTransactionBoundWitnessWithStorageMeta,
|
|
6
|
-
isBlockBoundWitnessWithStorageMeta,
|
|
7
|
-
isTransactionBoundWitnessWithStorageMeta
|
|
8
|
-
} from "@xyo-network/xl1-protocol";
|
|
7
|
+
import { asTransactionBoundWitnessWithStorageMeta, isBlockBoundWitnessWithStorageMeta, isTransactionBoundWitnessWithStorageMeta } from "@xyo-network/xl1-protocol";
|
|
9
8
|
function allHashesPresent(hashes, payloads) {
|
|
10
9
|
const payloadHashes = new Set(payloads.map((p) => p._hash));
|
|
11
10
|
return hashes.every((hash) => payloadHashes.has(hash));
|
|
12
11
|
}
|
|
13
|
-
|
|
12
|
+
__name(allHashesPresent, "allHashesPresent");
|
|
13
|
+
var tryHydrateBlock = /* @__PURE__ */ __name(async (archivist, hash, maxDepth = 1) => {
|
|
14
14
|
assertEx(maxDepth >= 0, () => "maxDepth must be greater than or equal to 0");
|
|
15
|
-
const bw = (await archivist.get([
|
|
15
|
+
const bw = (await archivist.get([
|
|
16
|
+
hash
|
|
17
|
+
])).find(isBlockBoundWitnessWithStorageMeta);
|
|
16
18
|
if (!bw) return void 0;
|
|
17
|
-
if (maxDepth === 0) return [
|
|
19
|
+
if (maxDepth === 0) return [
|
|
20
|
+
bw,
|
|
21
|
+
[]
|
|
22
|
+
];
|
|
18
23
|
const blkPayloads = await archivist.get(bw.payload_hashes);
|
|
19
|
-
if (maxDepth === 1) return [
|
|
24
|
+
if (maxDepth === 1) return [
|
|
25
|
+
bw,
|
|
26
|
+
blkPayloads
|
|
27
|
+
];
|
|
20
28
|
const transactions = blkPayloads.filter(isTransactionBoundWitnessWithStorageMeta);
|
|
21
29
|
const transactionsPayloadHashes = transactions.flatMap((tx) => tx.payload_hashes);
|
|
22
30
|
const transactionsPayloads = await archivist.get(transactionsPayloadHashes);
|
|
23
|
-
const allPayloadsHashes = new Set([
|
|
24
|
-
|
|
31
|
+
const allPayloadsHashes = new Set([
|
|
32
|
+
...blkPayloads,
|
|
33
|
+
...transactionsPayloads
|
|
34
|
+
].flatMap((p) => p._hash));
|
|
35
|
+
const allPayloads = await archivist.get([
|
|
36
|
+
...allPayloadsHashes
|
|
37
|
+
]);
|
|
25
38
|
const allPayloadsFiltered = allPayloads.filter((p) => allPayloadsHashes.has(p._hash));
|
|
26
|
-
return [
|
|
27
|
-
|
|
28
|
-
|
|
39
|
+
return [
|
|
40
|
+
bw,
|
|
41
|
+
allPayloadsFiltered
|
|
42
|
+
];
|
|
43
|
+
}, "tryHydrateBlock");
|
|
44
|
+
var hydrateBlock = /* @__PURE__ */ __name(async (archivist, hash, maxDepth = 1, minDepth = maxDepth) => {
|
|
29
45
|
assertEx(maxDepth >= 0, () => "maxDepth must be greater than or equal to 0");
|
|
30
46
|
assertEx(minDepth >= 0, () => "minDepth must be greater than or equal to 0");
|
|
31
47
|
assertEx(maxDepth >= minDepth, () => "maxDepth must be greater than or equal to minDepth");
|
|
32
|
-
const bw = assertEx(
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
)
|
|
36
|
-
|
|
48
|
+
const bw = assertEx((await archivist.get([
|
|
49
|
+
hash
|
|
50
|
+
])).find(isBlockBoundWitnessWithStorageMeta), () => `block ${hash} not found`);
|
|
51
|
+
if (maxDepth === 0) return [
|
|
52
|
+
bw,
|
|
53
|
+
[]
|
|
54
|
+
];
|
|
37
55
|
const blkPayloads = await archivist.get(bw.payload_hashes);
|
|
38
56
|
if (minDepth === 1) assertEx(allHashesPresent(bw.payload_hashes, blkPayloads), () => `Unable to find all payloads for block ${hash}`);
|
|
39
|
-
if (maxDepth === 1) return [
|
|
57
|
+
if (maxDepth === 1) return [
|
|
58
|
+
bw,
|
|
59
|
+
blkPayloads
|
|
60
|
+
];
|
|
40
61
|
const transactions = blkPayloads.filter(isTransactionBoundWitnessWithStorageMeta);
|
|
41
62
|
const transactionsPayloadHashes = transactions.flatMap((tx) => tx.payload_hashes);
|
|
42
63
|
const transactionsPayloads = await archivist.get(transactionsPayloadHashes);
|
|
43
64
|
assertEx(allHashesPresent(transactionsPayloadHashes, transactionsPayloads), () => `Unable to find all payloads for transactions in block ${hash}`);
|
|
44
|
-
const allPayloadsHashes = new Set([
|
|
45
|
-
|
|
65
|
+
const allPayloadsHashes = new Set([
|
|
66
|
+
...blkPayloads,
|
|
67
|
+
...transactionsPayloads
|
|
68
|
+
].flatMap((p) => p._hash));
|
|
69
|
+
const allPayloads = await archivist.get([
|
|
70
|
+
...allPayloadsHashes
|
|
71
|
+
]);
|
|
46
72
|
const allPayloadsFiltered = allPayloads.filter((p) => allPayloadsHashes.has(p._hash));
|
|
47
|
-
if (maxDepth === 2) assertEx(allHashesPresent(
|
|
48
|
-
|
|
73
|
+
if (maxDepth === 2) assertEx(allHashesPresent([
|
|
74
|
+
...allPayloadsHashes
|
|
75
|
+
], allPayloadsFiltered), () => `Unable to find all payloads for transactions in block ${hash}`);
|
|
76
|
+
return [
|
|
77
|
+
bw,
|
|
49
78
|
allPayloadsFiltered
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
var flattenHydratedBlock = (hydratedBlock) => {
|
|
79
|
+
];
|
|
80
|
+
}, "hydrateBlock");
|
|
81
|
+
var flattenHydratedBlock = /* @__PURE__ */ __name((hydratedBlock) => {
|
|
54
82
|
const [blk, blkPayloads] = hydratedBlock;
|
|
55
|
-
return [
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
83
|
+
return [
|
|
84
|
+
...blkPayloads,
|
|
85
|
+
blk
|
|
86
|
+
];
|
|
87
|
+
}, "flattenHydratedBlock");
|
|
88
|
+
var flattenHydratedBlocks = /* @__PURE__ */ __name((hydratedBlocks) => hydratedBlocks.flatMap((blk) => flattenHydratedBlock(blk)), "flattenHydratedBlocks");
|
|
89
|
+
var transactionsFromHydratedBlock = /* @__PURE__ */ __name((block) => {
|
|
59
90
|
return filterAs(block[1], asTransactionBoundWitnessWithStorageMeta);
|
|
60
|
-
};
|
|
61
|
-
var blockPayloadsFromHydratedBlock = (block) => {
|
|
62
|
-
return block[0].payload_hashes.map((hash) => assertEx(
|
|
63
|
-
|
|
64
|
-
() => `missing payload ${hash}`
|
|
65
|
-
)).filter((x) => !isTransactionBoundWitnessWithStorageMeta(x));
|
|
66
|
-
};
|
|
91
|
+
}, "transactionsFromHydratedBlock");
|
|
92
|
+
var blockPayloadsFromHydratedBlock = /* @__PURE__ */ __name((block) => {
|
|
93
|
+
return block[0].payload_hashes.map((hash) => assertEx(block[1].find((p) => p._hash === hash), () => `missing payload ${hash}`)).filter((x) => !isTransactionBoundWitnessWithStorageMeta(x));
|
|
94
|
+
}, "blockPayloadsFromHydratedBlock");
|
|
67
95
|
|
|
68
96
|
// src/block/primitives/balanceStepSummaryFromRange.ts
|
|
69
97
|
import { assertEx as assertEx2 } from "@xylabs/assert";
|
|
@@ -72,12 +100,9 @@ import { isAnyPayload } from "@xyo-network/payload-model";
|
|
|
72
100
|
import { StepSizes as StepSizes3 } from "@xyo-network/xl1-protocol";
|
|
73
101
|
|
|
74
102
|
// src/payload/netBalancesForPayloads.ts
|
|
75
|
-
import {
|
|
76
|
-
hexToBigInt,
|
|
77
|
-
toAddress
|
|
78
|
-
} from "@xylabs/hex";
|
|
103
|
+
import { hexToBigInt, toAddress } from "@xylabs/hex";
|
|
79
104
|
import { isTransfer } from "@xyo-network/xl1-protocol";
|
|
80
|
-
var netBalancesForPayloads = (payloads) => {
|
|
105
|
+
var netBalancesForPayloads = /* @__PURE__ */ __name((payloads) => {
|
|
81
106
|
const balances = {};
|
|
82
107
|
for (const payload of payloads) {
|
|
83
108
|
if (isTransfer(payload)) {
|
|
@@ -89,21 +114,18 @@ var netBalancesForPayloads = (payloads) => {
|
|
|
89
114
|
}
|
|
90
115
|
}
|
|
91
116
|
return balances;
|
|
92
|
-
};
|
|
117
|
+
}, "netBalancesForPayloads");
|
|
93
118
|
|
|
94
119
|
// src/SignedBigInt.ts
|
|
95
|
-
import {
|
|
96
|
-
hexToBigInt as hexToBigInt2,
|
|
97
|
-
toHex
|
|
98
|
-
} from "@xylabs/hex";
|
|
120
|
+
import { hexToBigInt as hexToBigInt2, toHex } from "@xylabs/hex";
|
|
99
121
|
import { isObject } from "@xylabs/object";
|
|
100
|
-
var isNegativeBigInt = (value) => {
|
|
122
|
+
var isNegativeBigInt = /* @__PURE__ */ __name((value) => {
|
|
101
123
|
return isObject(value) && "negative" in value && typeof value.negative === "string";
|
|
102
|
-
};
|
|
103
|
-
var isPositiveBigInt = (value) => {
|
|
124
|
+
}, "isNegativeBigInt");
|
|
125
|
+
var isPositiveBigInt = /* @__PURE__ */ __name((value) => {
|
|
104
126
|
return isObject(value) && "positive" in value && typeof value.positive === "string";
|
|
105
|
-
};
|
|
106
|
-
var parseSignedBigInt = (value) => {
|
|
127
|
+
}, "isPositiveBigInt");
|
|
128
|
+
var parseSignedBigInt = /* @__PURE__ */ __name((value) => {
|
|
107
129
|
if (isNegativeBigInt(value)) {
|
|
108
130
|
return -hexToBigInt2(value.negative);
|
|
109
131
|
} else if (isPositiveBigInt(value)) {
|
|
@@ -111,22 +133,32 @@ var parseSignedBigInt = (value) => {
|
|
|
111
133
|
} else {
|
|
112
134
|
throw new Error("Invalid balance type");
|
|
113
135
|
}
|
|
114
|
-
};
|
|
115
|
-
var toSignedBigInt = (value) => {
|
|
116
|
-
return value < 0n ? {
|
|
117
|
-
|
|
118
|
-
|
|
136
|
+
}, "parseSignedBigInt");
|
|
137
|
+
var toSignedBigInt = /* @__PURE__ */ __name((value) => {
|
|
138
|
+
return value < 0n ? {
|
|
139
|
+
negative: toHex(-value)
|
|
140
|
+
} : {
|
|
141
|
+
positive: toHex(value)
|
|
142
|
+
};
|
|
143
|
+
}, "toSignedBigInt");
|
|
144
|
+
var toPositiveBigInt = /* @__PURE__ */ __name((value) => {
|
|
119
145
|
if (isNegativeBigInt(value)) {
|
|
120
|
-
return {
|
|
146
|
+
return {
|
|
147
|
+
positive: toHex(0n)
|
|
148
|
+
};
|
|
121
149
|
}
|
|
122
150
|
if (isPositiveBigInt(value)) {
|
|
123
|
-
return {
|
|
151
|
+
return {
|
|
152
|
+
positive: value.positive
|
|
153
|
+
};
|
|
124
154
|
}
|
|
125
155
|
if (typeof value === "bigint") {
|
|
126
|
-
return {
|
|
156
|
+
return {
|
|
157
|
+
positive: toHex(value)
|
|
158
|
+
};
|
|
127
159
|
}
|
|
128
160
|
throw new Error("Invalid value for positive big int");
|
|
129
|
-
};
|
|
161
|
+
}, "toPositiveBigInt");
|
|
130
162
|
|
|
131
163
|
// src/block/primitives/frames/calculateFramesFromRange.ts
|
|
132
164
|
import { stepSize } from "@xyo-network/xl1-protocol";
|
|
@@ -137,23 +169,38 @@ function calculateFramesFromRange(range, step) {
|
|
|
137
169
|
const remaining = [];
|
|
138
170
|
if (start !== range[0]) {
|
|
139
171
|
start += size;
|
|
140
|
-
remaining.push([
|
|
172
|
+
remaining.push([
|
|
173
|
+
range[0],
|
|
174
|
+
Math.min(start - 1, range[1])
|
|
175
|
+
]);
|
|
141
176
|
}
|
|
142
177
|
for (let i = start; i <= range[1]; i += size) {
|
|
143
178
|
if (i + size - 1 <= range[1]) {
|
|
144
|
-
fitted.push([
|
|
179
|
+
fitted.push([
|
|
180
|
+
i,
|
|
181
|
+
Math.min(i + size - 1, range[1])
|
|
182
|
+
]);
|
|
145
183
|
} else {
|
|
146
|
-
remaining.push([
|
|
184
|
+
remaining.push([
|
|
185
|
+
i,
|
|
186
|
+
range[1]
|
|
187
|
+
]);
|
|
147
188
|
}
|
|
148
189
|
}
|
|
149
|
-
return [
|
|
190
|
+
return [
|
|
191
|
+
fitted,
|
|
192
|
+
remaining
|
|
193
|
+
];
|
|
150
194
|
}
|
|
195
|
+
__name(calculateFramesFromRange, "calculateFramesFromRange");
|
|
151
196
|
|
|
152
197
|
// src/block/primitives/frames/deepCalculateFramesFromRange.ts
|
|
153
198
|
import { StepSizes } from "@xyo-network/xl1-protocol";
|
|
154
199
|
function deepCalculateFramesFromRange(range, startingStep = StepSizes.length - 1) {
|
|
155
200
|
const fitted = [];
|
|
156
|
-
let remaining = [
|
|
201
|
+
let remaining = [
|
|
202
|
+
range
|
|
203
|
+
];
|
|
157
204
|
for (let step = startingStep; step >= 0; step--) {
|
|
158
205
|
const newRemaining = [];
|
|
159
206
|
for (const range2 of remaining) {
|
|
@@ -165,19 +212,27 @@ function deepCalculateFramesFromRange(range, startingStep = StepSizes.length - 1
|
|
|
165
212
|
}
|
|
166
213
|
for (const range2 of remaining) {
|
|
167
214
|
for (let i = range2[0]; i <= range2[1]; i++) {
|
|
168
|
-
fitted.push([
|
|
215
|
+
fitted.push([
|
|
216
|
+
i,
|
|
217
|
+
i
|
|
218
|
+
]);
|
|
169
219
|
}
|
|
170
220
|
}
|
|
171
221
|
return fitted.toSorted((a, b) => a[0] - b[0]);
|
|
172
222
|
}
|
|
223
|
+
__name(deepCalculateFramesFromRange, "deepCalculateFramesFromRange");
|
|
173
224
|
|
|
174
225
|
// src/block/primitives/hashFromBlockNumber.ts
|
|
175
226
|
import { asHash } from "@xylabs/hex";
|
|
176
227
|
import { toSafeJsonString } from "@xylabs/object";
|
|
177
228
|
import { asBlockBoundWitnessWithStorageMeta, StepSizes as StepSizes2 } from "@xyo-network/xl1-protocol";
|
|
178
229
|
async function hashFromBlockNumber(context, blockNumber) {
|
|
179
|
-
const result = await context.chainArchivist.get([
|
|
180
|
-
|
|
230
|
+
const result = await context.chainArchivist.get([
|
|
231
|
+
context.head
|
|
232
|
+
]);
|
|
233
|
+
let currentBlock = asBlockBoundWitnessWithStorageMeta(result.at(0), () => `Head block not found for hash: ${context.head}`, {
|
|
234
|
+
required: true
|
|
235
|
+
});
|
|
181
236
|
while (currentBlock.block > blockNumber) {
|
|
182
237
|
let jumpHash = currentBlock.previous;
|
|
183
238
|
let jumpBlockNumber = currentBlock.block - 1;
|
|
@@ -191,7 +246,9 @@ async function hashFromBlockNumber(context, blockNumber) {
|
|
|
191
246
|
const [newBlock] = await context.chainArchivist.get([
|
|
192
247
|
asHash(jumpHash, () => `Jump hash not found for block number [${blockNumber}]: ${jumpBlockNumber} ${toSafeJsonString(currentBlock, 10)}`)
|
|
193
248
|
]);
|
|
194
|
-
currentBlock = asBlockBoundWitnessWithStorageMeta(newBlock, () => `Block not found for hash: ${jumpHash}`, {
|
|
249
|
+
currentBlock = asBlockBoundWitnessWithStorageMeta(newBlock, () => `Block not found for hash: ${jumpHash}`, {
|
|
250
|
+
required: true
|
|
251
|
+
});
|
|
195
252
|
if (currentBlock.block === blockNumber) {
|
|
196
253
|
break;
|
|
197
254
|
}
|
|
@@ -201,6 +258,7 @@ async function hashFromBlockNumber(context, blockNumber) {
|
|
|
201
258
|
}
|
|
202
259
|
return currentBlock._hash;
|
|
203
260
|
}
|
|
261
|
+
__name(hashFromBlockNumber, "hashFromBlockNumber");
|
|
204
262
|
|
|
205
263
|
// src/block/primitives/payloads.ts
|
|
206
264
|
import { AsObjectFactory } from "@xylabs/object";
|
|
@@ -209,9 +267,9 @@ var StepSummarySchema = "network.xyo.step.summary";
|
|
|
209
267
|
var BalancesStepSummarySchema = "network.xyo.step.summary.balances";
|
|
210
268
|
var isBalancesStepSummary = isPayloadOfSchemaType(BalancesStepSummarySchema);
|
|
211
269
|
var asBalancesStepSummary = AsObjectFactory.create(isBalancesStepSummary);
|
|
212
|
-
var isBalancesStepSummaryWithStorageMeta = (value) => {
|
|
270
|
+
var isBalancesStepSummaryWithStorageMeta = /* @__PURE__ */ __name((value) => {
|
|
213
271
|
return isBalancesStepSummary(value) && isStorageMeta(value);
|
|
214
|
-
};
|
|
272
|
+
}, "isBalancesStepSummaryWithStorageMeta");
|
|
215
273
|
var asBalancesStepSummaryWithStorageMeta = AsObjectFactory.create(isBalancesStepSummaryWithStorageMeta);
|
|
216
274
|
|
|
217
275
|
// src/block/primitives/balanceStepSummaryFromRange.ts
|
|
@@ -235,15 +293,14 @@ async function balanceStepSummaryFromRange(context, range) {
|
|
|
235
293
|
} else {
|
|
236
294
|
const step = StepSizes3.indexOf(frameSize);
|
|
237
295
|
assertEx2(step !== -1, () => `Invalid step size: ${frameSize}. Must be one of ${StepSizes3.join(", ")}`);
|
|
238
|
-
const [summaryResult] = await context.summaryRepository.get([
|
|
296
|
+
const [summaryResult] = await context.summaryRepository.get([
|
|
297
|
+
frameHeadHash
|
|
298
|
+
]);
|
|
239
299
|
if (isAnyPayload(summaryResult)) {
|
|
240
300
|
result = summaryResult;
|
|
241
301
|
} else {
|
|
242
302
|
const subRanges = deepCalculateFramesFromRange(range, step - 1);
|
|
243
|
-
const promises = subRanges.map((subRange) => balanceStepSummaryFromRange(
|
|
244
|
-
context,
|
|
245
|
-
subRange
|
|
246
|
-
));
|
|
303
|
+
const promises = subRanges.map((subRange) => balanceStepSummaryFromRange(context, subRange));
|
|
247
304
|
const subResults = await Promise.all(promises);
|
|
248
305
|
const bigIntBalances = {};
|
|
249
306
|
for (const subResult of subResults) {
|
|
@@ -261,22 +318,32 @@ async function balanceStepSummaryFromRange(context, range) {
|
|
|
261
318
|
stepSize: frameSize,
|
|
262
319
|
balances
|
|
263
320
|
};
|
|
264
|
-
await context.summaryRepository.insert([
|
|
321
|
+
await context.summaryRepository.insert([
|
|
322
|
+
result
|
|
323
|
+
]);
|
|
265
324
|
}
|
|
266
325
|
}
|
|
267
326
|
const finalResult = await PayloadBuilder.addStorageMeta(result);
|
|
268
327
|
return finalResult;
|
|
269
328
|
}
|
|
329
|
+
__name(balanceStepSummaryFromRange, "balanceStepSummaryFromRange");
|
|
270
330
|
|
|
271
331
|
// src/block/primitives/balanceSummary.ts
|
|
272
332
|
import { asAddress } from "@xylabs/hex";
|
|
273
333
|
import { isDefined } from "@xylabs/typeof";
|
|
274
334
|
import { asBlockBoundWitnessWithStorageMeta as asBlockBoundWitnessWithStorageMeta2 } from "@xyo-network/xl1-protocol";
|
|
275
335
|
async function balanceSummary(context) {
|
|
276
|
-
const headResult = await context.chainArchivist.get([
|
|
277
|
-
|
|
336
|
+
const headResult = await context.chainArchivist.get([
|
|
337
|
+
context.head
|
|
338
|
+
]);
|
|
339
|
+
const headBoundWitness = asBlockBoundWitnessWithStorageMeta2(headResult.at(0), () => `Head block not found for hash: ${context.head}`, {
|
|
340
|
+
required: true
|
|
341
|
+
});
|
|
278
342
|
const rangeStart = isDefined(context.windowSize) ? Math.max(headBoundWitness.block - context.windowSize + 1, 0) : 0;
|
|
279
|
-
const ranges = deepCalculateFramesFromRange([
|
|
343
|
+
const ranges = deepCalculateFramesFromRange([
|
|
344
|
+
rangeStart,
|
|
345
|
+
headBoundWitness.block
|
|
346
|
+
]);
|
|
280
347
|
const summaries = await Promise.all(ranges.map((range) => balanceStepSummaryFromRange(context, range)));
|
|
281
348
|
const balances = {};
|
|
282
349
|
for (let summary of summaries) {
|
|
@@ -287,33 +354,40 @@ async function balanceSummary(context) {
|
|
|
287
354
|
}
|
|
288
355
|
return balances;
|
|
289
356
|
}
|
|
357
|
+
__name(balanceSummary, "balanceSummary");
|
|
290
358
|
|
|
291
359
|
// src/config/Config.ts
|
|
292
|
-
import z11 from "zod";
|
|
360
|
+
import * as z11 from "zod";
|
|
293
361
|
|
|
294
362
|
// src/config/Api.ts
|
|
295
|
-
import
|
|
363
|
+
import { globalRegistry } from "zod";
|
|
364
|
+
import * as z2 from "zod";
|
|
296
365
|
|
|
297
366
|
// src/validation/lib/isLocalhost.ts
|
|
298
|
-
var isLocalhost = (hostname) => {
|
|
367
|
+
var isLocalhost = /* @__PURE__ */ __name((hostname) => {
|
|
299
368
|
return hostname === "localhost" || hostname === "127.0.0.1" || hostname === "::1" || hostname.endsWith(".localhost");
|
|
300
|
-
};
|
|
369
|
+
}, "isLocalhost");
|
|
301
370
|
|
|
302
371
|
// src/validation/lib/getUrl.ts
|
|
303
|
-
var getUrl = (host, port) => {
|
|
372
|
+
var getUrl = /* @__PURE__ */ __name((host, port) => {
|
|
304
373
|
const scheme = isLocalhost(host) ? "http" : "https";
|
|
305
374
|
return `${scheme}://${host}:${port}`;
|
|
306
|
-
};
|
|
375
|
+
}, "getUrl");
|
|
307
376
|
|
|
308
377
|
// src/validation/schema/Address.ts
|
|
309
378
|
var TODO = true;
|
|
310
379
|
|
|
311
380
|
// src/validation/schema/Mnemonic.ts
|
|
312
|
-
import
|
|
313
|
-
var MnemonicStringZod = z.string().transform((s) => s.trim().replaceAll(/\s+/g, " ")).refine(
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
381
|
+
import * as z from "zod";
|
|
382
|
+
var MnemonicStringZod = z.string().transform((s) => s.trim().replaceAll(/\s+/g, " ")).refine((s) => [
|
|
383
|
+
12,
|
|
384
|
+
15,
|
|
385
|
+
18,
|
|
386
|
+
21,
|
|
387
|
+
24
|
|
388
|
+
].includes(s.split(" ").length), {
|
|
389
|
+
message: "Mnemonic must contain 12, 15, 18, 21, or 24 words."
|
|
390
|
+
}).describe("BIP-39 mnemonic string");
|
|
317
391
|
|
|
318
392
|
// src/config/Api.ts
|
|
319
393
|
var ApiConfigZod = z2.object({
|
|
@@ -337,7 +411,8 @@ var ApiConfigZod = z2.object({
|
|
|
337
411
|
});
|
|
338
412
|
|
|
339
413
|
// src/config/App.ts
|
|
340
|
-
import
|
|
414
|
+
import { globalRegistry as globalRegistry2 } from "zod";
|
|
415
|
+
import * as z3 from "zod";
|
|
341
416
|
var AppConfigZod = z3.object({
|
|
342
417
|
port: z3.coerce.number().default(3e3).register(globalRegistry2, {
|
|
343
418
|
default: 3e3,
|
|
@@ -348,7 +423,8 @@ var AppConfigZod = z3.object({
|
|
|
348
423
|
});
|
|
349
424
|
|
|
350
425
|
// src/config/Chain.ts
|
|
351
|
-
import
|
|
426
|
+
import { globalRegistry as globalRegistry3 } from "zod";
|
|
427
|
+
import * as z4 from "zod";
|
|
352
428
|
var ChainConfigZod = z4.object({
|
|
353
429
|
id: z4.string().optional().register(globalRegistry3, {
|
|
354
430
|
description: "The unique identifier for the chain. Should be the staking contract address for contract-backed chains.",
|
|
@@ -358,7 +434,8 @@ var ChainConfigZod = z4.object({
|
|
|
358
434
|
});
|
|
359
435
|
|
|
360
436
|
// src/config/Evm.ts
|
|
361
|
-
import
|
|
437
|
+
import { globalRegistry as globalRegistry4 } from "zod";
|
|
438
|
+
import * as z5 from "zod";
|
|
362
439
|
var EvmInfuraConfigZod = z5.object({
|
|
363
440
|
projectId: z5.string().optional().register(globalRegistry4, {
|
|
364
441
|
description: "Infura project ID",
|
|
@@ -390,7 +467,8 @@ var EvmConfigZod = z5.object({
|
|
|
390
467
|
|
|
391
468
|
// src/config/Log.ts
|
|
392
469
|
import { LogLevel } from "@xylabs/logger";
|
|
393
|
-
import
|
|
470
|
+
import { globalRegistry as globalRegistry5 } from "zod";
|
|
471
|
+
import * as z6 from "zod";
|
|
394
472
|
var LogLevels = Object.keys(LogLevel);
|
|
395
473
|
var LogConfigZod = z6.object({
|
|
396
474
|
logLevel: z6.enum(LogLevels).default("info").register(globalRegistry5, {
|
|
@@ -409,7 +487,8 @@ var LogConfigZod = z6.object({
|
|
|
409
487
|
});
|
|
410
488
|
|
|
411
489
|
// src/config/Producer.ts
|
|
412
|
-
import
|
|
490
|
+
import { globalRegistry as globalRegistry6 } from "zod";
|
|
491
|
+
import * as z7 from "zod";
|
|
413
492
|
var ProducerConfigZod = z7.object({
|
|
414
493
|
disableIntentRedeclaration: z7.boolean().optional().register(globalRegistry6, {
|
|
415
494
|
description: "Should the producer skip redeclaring their intent to continue producing blocks",
|
|
@@ -450,11 +529,12 @@ var ProducerConfigZod = z7.object({
|
|
|
450
529
|
|
|
451
530
|
// src/config/storage/driver/Mongo.ts
|
|
452
531
|
import { isDefined as isDefined2, isUndefined } from "@xylabs/typeof";
|
|
453
|
-
import
|
|
454
|
-
|
|
532
|
+
import { globalRegistry as globalRegistry7 } from "zod";
|
|
533
|
+
import * as z8 from "zod";
|
|
534
|
+
var hasMongoConfig = /* @__PURE__ */ __name((config) => {
|
|
455
535
|
if (isUndefined(config)) return false;
|
|
456
536
|
return isDefined2(config.connectionString) && isDefined2(config.database) && isDefined2(config.domain) && isDefined2(config.password) && isDefined2(config.username);
|
|
457
|
-
};
|
|
537
|
+
}, "hasMongoConfig");
|
|
458
538
|
var MongoConfigZod = z8.object({
|
|
459
539
|
// TODO: Create from other arguments
|
|
460
540
|
connectionString: z8.string().min(1).optional().register(globalRegistry7, {
|
|
@@ -485,7 +565,8 @@ var MongoConfigZod = z8.object({
|
|
|
485
565
|
});
|
|
486
566
|
|
|
487
567
|
// src/config/storage/Storage.ts
|
|
488
|
-
import
|
|
568
|
+
import { globalRegistry as globalRegistry8 } from "zod";
|
|
569
|
+
import * as z9 from "zod";
|
|
489
570
|
var StorageConfigZod = z9.object({
|
|
490
571
|
mongo: MongoConfigZod.optional().describe("Configuration for the MongoD storage driver"),
|
|
491
572
|
root: z9.string().optional().register(globalRegistry8, {
|
|
@@ -496,7 +577,8 @@ var StorageConfigZod = z9.object({
|
|
|
496
577
|
}).describe("Storage configuration options");
|
|
497
578
|
|
|
498
579
|
// src/config/Telemetry.ts
|
|
499
|
-
import
|
|
580
|
+
import { globalRegistry as globalRegistry9 } from "zod";
|
|
581
|
+
import * as z10 from "zod";
|
|
500
582
|
var OpenTelemetryConfigZod = z10.object({
|
|
501
583
|
// OpenTelemetry options
|
|
502
584
|
otlpEndpoint: z10.url().optional().register(globalRegistry9, {
|
|
@@ -511,7 +593,9 @@ var TelemetryConfigZod = z10.object({
|
|
|
511
593
|
}).describe("Telemetry configuration options");
|
|
512
594
|
|
|
513
595
|
// src/config/Config.ts
|
|
514
|
-
var Xl1CommonConfigSchema = z11.object({
|
|
596
|
+
var Xl1CommonConfigSchema = z11.object({
|
|
597
|
+
...LogConfigZod.shape
|
|
598
|
+
}).describe("XL1 common configuration options");
|
|
515
599
|
var ConfigZod = z11.object({
|
|
516
600
|
...Xl1CommonConfigSchema.shape,
|
|
517
601
|
api: ApiConfigZod.default(ApiConfigZod.parse({})).describe("Configuration for the API node"),
|
|
@@ -522,10 +606,10 @@ var ConfigZod = z11.object({
|
|
|
522
606
|
storage: StorageConfigZod.default(StorageConfigZod.parse({})).describe("Configuration for the storage"),
|
|
523
607
|
telemetry: TelemetryConfigZod.default(TelemetryConfigZod.parse({})).describe("Configuration for telemetry")
|
|
524
608
|
});
|
|
525
|
-
var getDefaultConfig = () => ConfigZod.parse({});
|
|
609
|
+
var getDefaultConfig = /* @__PURE__ */ __name(() => ConfigZod.parse({}), "getDefaultConfig");
|
|
526
610
|
|
|
527
611
|
// src/config/UsageMeta.ts
|
|
528
|
-
import z12 from "zod";
|
|
612
|
+
import * as z12 from "zod";
|
|
529
613
|
var DescriptionSchema = z12.string();
|
|
530
614
|
var TitleSchema = z12.string();
|
|
531
615
|
var JSONSchemaMetaSchema = z12.object({
|
|
@@ -535,7 +619,12 @@ var JSONSchemaMetaSchema = z12.object({
|
|
|
535
619
|
deprecated: z12.boolean().optional()
|
|
536
620
|
}).catchall(z12.unknown());
|
|
537
621
|
var GlobalMetaSchema = JSONSchemaMetaSchema.extend({});
|
|
538
|
-
var ChoicesSchema = z12.array(z12.union([
|
|
622
|
+
var ChoicesSchema = z12.array(z12.union([
|
|
623
|
+
z12.string(),
|
|
624
|
+
z12.number(),
|
|
625
|
+
z12.literal(true),
|
|
626
|
+
z12.undefined()
|
|
627
|
+
])).readonly();
|
|
539
628
|
var UsageMetaSchema = GlobalMetaSchema.extend({
|
|
540
629
|
choices: ChoicesSchema.optional(),
|
|
541
630
|
default: z12.unknown().optional(),
|
|
@@ -554,6 +643,7 @@ var UsageMetaSchema = GlobalMetaSchema.extend({
|
|
|
554
643
|
function isUsageMeta(v) {
|
|
555
644
|
return UsageMetaSchema.safeParse(v).success;
|
|
556
645
|
}
|
|
646
|
+
__name(isUsageMeta, "isUsageMeta");
|
|
557
647
|
|
|
558
648
|
// src/transaction/buildTransaction.ts
|
|
559
649
|
import { assertEx as assertEx3 } from "@xylabs/assert";
|
|
@@ -588,9 +678,20 @@ async function buildTransaction(chain, onChainPayloads, offChainPayloads, signer
|
|
|
588
678
|
if (script.length > 0) {
|
|
589
679
|
fields.script = script;
|
|
590
680
|
}
|
|
591
|
-
const [tx, txPayloads] = await new BoundWitnessBuilder().fields(fields).meta({
|
|
592
|
-
|
|
681
|
+
const [tx, txPayloads] = await new BoundWitnessBuilder().fields(fields).meta({
|
|
682
|
+
$signatures: []
|
|
683
|
+
}).payloads([
|
|
684
|
+
...onChainPayloads,
|
|
685
|
+
...offChainPayloads
|
|
686
|
+
]).signers(Array.isArray(signer) ? signer : [
|
|
687
|
+
signer
|
|
688
|
+
]).build();
|
|
689
|
+
return [
|
|
690
|
+
await PayloadBuilder2.addStorageMeta(tx),
|
|
691
|
+
await PayloadBuilder2.addStorageMeta(txPayloads)
|
|
692
|
+
];
|
|
593
693
|
}
|
|
694
|
+
__name(buildTransaction, "buildTransaction");
|
|
594
695
|
|
|
595
696
|
// src/transaction/buildUnsignedTransaction.ts
|
|
596
697
|
import { toHex as toHex3 } from "@xylabs/hex";
|
|
@@ -621,9 +722,18 @@ async function buildUnsignedTransaction(chain, onChainPayloads, offChainPayloads
|
|
|
621
722
|
if (script.length > 0) {
|
|
622
723
|
fields.script = script;
|
|
623
724
|
}
|
|
624
|
-
const [tx, txPayloads] = await new BoundWitnessBuilder2().fields(fields).meta({
|
|
625
|
-
|
|
725
|
+
const [tx, txPayloads] = await new BoundWitnessBuilder2().fields(fields).meta({
|
|
726
|
+
$signatures: []
|
|
727
|
+
}).payloads([
|
|
728
|
+
...onChainPayloads,
|
|
729
|
+
...offChainPayloads
|
|
730
|
+
]).build();
|
|
731
|
+
return [
|
|
732
|
+
await PayloadBuilder3.addStorageMeta(tx),
|
|
733
|
+
await PayloadBuilder3.addStorageMeta(txPayloads)
|
|
734
|
+
];
|
|
626
735
|
}
|
|
736
|
+
__name(buildUnsignedTransaction, "buildUnsignedTransaction");
|
|
627
737
|
|
|
628
738
|
// src/transaction/confirmSubmittedTransaction.ts
|
|
629
739
|
import { delay } from "@xylabs/delay";
|
|
@@ -631,7 +741,7 @@ import { isDefined as isDefined3 } from "@xylabs/typeof";
|
|
|
631
741
|
import { PayloadBuilder as PayloadBuilder4 } from "@xyo-network/payload-builder";
|
|
632
742
|
var DEFAULT_CONFIRMATION_ATTEMPTS = 20;
|
|
633
743
|
var DEFAULT_DELAY_BETWEEN_ATTEMPTS = 1e3;
|
|
634
|
-
var confirmSubmittedTransaction = async (viewer, transaction, options) => {
|
|
744
|
+
var confirmSubmittedTransaction = /* @__PURE__ */ __name(async (viewer, transaction, options) => {
|
|
635
745
|
const { attempts: maxAttempts = DEFAULT_CONFIRMATION_ATTEMPTS, delay: attemptDelay = DEFAULT_DELAY_BETWEEN_ATTEMPTS } = options || {};
|
|
636
746
|
const txBWHash = await PayloadBuilder4.hash(transaction);
|
|
637
747
|
options?.logger?.log("\u{1F680} confirming transaction:", txBWHash, "\n");
|
|
@@ -652,32 +762,27 @@ var confirmSubmittedTransaction = async (viewer, transaction, options) => {
|
|
|
652
762
|
}
|
|
653
763
|
}
|
|
654
764
|
}
|
|
655
|
-
};
|
|
765
|
+
}, "confirmSubmittedTransaction");
|
|
656
766
|
|
|
657
767
|
// src/transaction/hydrateTransaction.ts
|
|
658
768
|
import { assertEx as assertEx4 } from "@xylabs/assert";
|
|
659
769
|
import { hydrateTypedBoundWitness, tryHydrateTypedBoundWitness } from "@xyo-network/archivist-model";
|
|
660
770
|
import { isAllowedBlockPayload, isSignedTransactionBoundWitnessWithStorageMeta } from "@xyo-network/xl1-protocol";
|
|
661
|
-
var tryHydrateTransaction = async (archivist, hash) => {
|
|
662
|
-
return await tryHydrateTypedBoundWitness(
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
var hydrateTransaction = async (archivist, hash) => {
|
|
669
|
-
return await hydrateTypedBoundWitness(
|
|
670
|
-
archivist,
|
|
671
|
-
hash,
|
|
672
|
-
isSignedTransactionBoundWitnessWithStorageMeta
|
|
673
|
-
);
|
|
674
|
-
};
|
|
675
|
-
var flattenHydratedTransaction = (hydratedTransaction) => {
|
|
771
|
+
var tryHydrateTransaction = /* @__PURE__ */ __name(async (archivist, hash) => {
|
|
772
|
+
return await tryHydrateTypedBoundWitness(archivist, hash, isSignedTransactionBoundWitnessWithStorageMeta);
|
|
773
|
+
}, "tryHydrateTransaction");
|
|
774
|
+
var hydrateTransaction = /* @__PURE__ */ __name(async (archivist, hash) => {
|
|
775
|
+
return await hydrateTypedBoundWitness(archivist, hash, isSignedTransactionBoundWitnessWithStorageMeta);
|
|
776
|
+
}, "hydrateTransaction");
|
|
777
|
+
var flattenHydratedTransaction = /* @__PURE__ */ __name((hydratedTransaction) => {
|
|
676
778
|
const [tx, txPayloads] = hydratedTransaction;
|
|
677
|
-
return [
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
779
|
+
return [
|
|
780
|
+
...txPayloads,
|
|
781
|
+
tx
|
|
782
|
+
];
|
|
783
|
+
}, "flattenHydratedTransaction");
|
|
784
|
+
var flattenHydratedTransactions = /* @__PURE__ */ __name((hydratedTransactions) => hydratedTransactions.flatMap((tx) => flattenHydratedTransaction(tx)), "flattenHydratedTransactions");
|
|
785
|
+
var tryHydrateElevatedTransaction = /* @__PURE__ */ __name(async (archivist, hash) => {
|
|
681
786
|
const hydratedTransaction = await tryHydrateTransaction(archivist, hash);
|
|
682
787
|
if (!hydratedTransaction) {
|
|
683
788
|
return void 0;
|
|
@@ -695,13 +800,16 @@ var tryHydrateElevatedTransaction = async (archivist, hash) => {
|
|
|
695
800
|
}
|
|
696
801
|
}
|
|
697
802
|
if (opCodes.length === elevatedPayloads.length) {
|
|
698
|
-
return [
|
|
803
|
+
return [
|
|
804
|
+
transaction,
|
|
805
|
+
elevatedPayloads
|
|
806
|
+
];
|
|
699
807
|
}
|
|
700
808
|
return void 0;
|
|
701
|
-
};
|
|
702
|
-
var hydrateElevatedTransaction = async (archivist, hash) => {
|
|
809
|
+
}, "tryHydrateElevatedTransaction");
|
|
810
|
+
var hydrateElevatedTransaction = /* @__PURE__ */ __name(async (archivist, hash) => {
|
|
703
811
|
return assertEx4(await tryHydrateElevatedTransaction(archivist, hash), () => "Hydration failed");
|
|
704
|
-
};
|
|
812
|
+
}, "hydrateElevatedTransaction");
|
|
705
813
|
|
|
706
814
|
// src/transaction/primitives/transactionBlockByteCount.ts
|
|
707
815
|
import { PayloadBuilder as PayloadBuilder5 } from "@xyo-network/payload-builder";
|
|
@@ -711,6 +819,7 @@ function transactionBlockByteCount([transaction, payloads]) {
|
|
|
711
819
|
const cleanPayloads = PayloadBuilder5.omitStorageMeta(payloads);
|
|
712
820
|
return cleanPayloads.reduce((acc, payload) => acc + JSON.stringify(payload).length, 0) + transactionBytes;
|
|
713
821
|
}
|
|
822
|
+
__name(transactionBlockByteCount, "transactionBlockByteCount");
|
|
714
823
|
|
|
715
824
|
// src/transaction/primitives/transactionElevatedPayloads.ts
|
|
716
825
|
import { asHash as asHash2 } from "@xylabs/hex";
|
|
@@ -721,65 +830,77 @@ function crackOperation(operation) {
|
|
|
721
830
|
if (parts.length < 2) {
|
|
722
831
|
throw new Error(`Invalid operation format: ${operation}`);
|
|
723
832
|
}
|
|
724
|
-
return [
|
|
833
|
+
return [
|
|
834
|
+
parts[0],
|
|
835
|
+
parts.slice(1)
|
|
836
|
+
];
|
|
725
837
|
}
|
|
838
|
+
__name(crackOperation, "crackOperation");
|
|
726
839
|
function crackOperations(operations) {
|
|
727
840
|
return operations.map((op) => crackOperation(op));
|
|
728
841
|
}
|
|
842
|
+
__name(crackOperations, "crackOperations");
|
|
729
843
|
|
|
730
844
|
// src/transaction/primitives/transactionElevatedPayloads.ts
|
|
731
845
|
function transactionElevatedPayloadHashes(transaction) {
|
|
732
846
|
const elevateOperations = crackOperations(transaction.script ?? []).filter((op) => op[0] === "elevate");
|
|
733
847
|
return elevateOperations.map((op) => asHash2(op[1][0], true));
|
|
734
848
|
}
|
|
849
|
+
__name(transactionElevatedPayloadHashes, "transactionElevatedPayloadHashes");
|
|
735
850
|
function transactionElevatedPayloads([transaction, payloads]) {
|
|
736
851
|
const hashes = transactionElevatedPayloadHashes(transaction);
|
|
737
852
|
const elevatedPayloads = payloads.filter((payload) => hashes.includes(payload._hash));
|
|
738
853
|
return elevatedPayloads;
|
|
739
854
|
}
|
|
855
|
+
__name(transactionElevatedPayloads, "transactionElevatedPayloads");
|
|
740
856
|
|
|
741
857
|
// src/transaction/primitives/transactionRequiredGas.ts
|
|
742
858
|
import { AttoXL1, TransactionGasCosts } from "@xyo-network/xl1-protocol";
|
|
743
859
|
function transactionBytesRequiredGas([transaction, payloads]) {
|
|
744
|
-
const transactionBlockBytes = transactionBlockByteCount([
|
|
860
|
+
const transactionBlockBytes = transactionBlockByteCount([
|
|
861
|
+
transaction,
|
|
862
|
+
payloads
|
|
863
|
+
]);
|
|
745
864
|
return AttoXL1(TransactionGasCosts.characterStorage * BigInt(transactionBlockBytes));
|
|
746
865
|
}
|
|
866
|
+
__name(transactionBytesRequiredGas, "transactionBytesRequiredGas");
|
|
747
867
|
function transactionRequiredGas(hydratedTransaction) {
|
|
748
868
|
const elevatedPayloads = transactionElevatedPayloads(hydratedTransaction);
|
|
749
869
|
const hashes = elevatedPayloads.length + 1;
|
|
750
870
|
const signatures = hydratedTransaction[0].addresses.length;
|
|
751
871
|
return AttoXL1(transactionBytesRequiredGas(hydratedTransaction) + TransactionGasCosts.hashValidation * BigInt(hashes) + TransactionGasCosts.signatureValidation * BigInt(signatures) + TransactionGasCosts.payloadValidation * BigInt(elevatedPayloads.length));
|
|
752
872
|
}
|
|
873
|
+
__name(transactionRequiredGas, "transactionRequiredGas");
|
|
753
874
|
|
|
754
875
|
// src/transaction/script.ts
|
|
755
876
|
import { filterAs as filterAs2 } from "@xylabs/array";
|
|
756
877
|
import { assertEx as assertEx5 } from "@xylabs/assert";
|
|
757
878
|
import { asHash as asHash3 } from "@xylabs/hex";
|
|
758
879
|
import { isAllowedBlockPayloadWithHashStorageMeta } from "@xyo-network/xl1-protocol";
|
|
759
|
-
var tryExtractElevatedHashesFromScript = (strings) => {
|
|
880
|
+
var tryExtractElevatedHashesFromScript = /* @__PURE__ */ __name((strings) => {
|
|
760
881
|
const hashes = strings.filter((str) => str.startsWith("elevate|")).map((str) => str.split("|")[1]);
|
|
761
882
|
return filterAs2(hashes, (h) => asHash3(h));
|
|
762
|
-
};
|
|
763
|
-
var extractElevatedHashesFromScript = (strings) => {
|
|
883
|
+
}, "tryExtractElevatedHashesFromScript");
|
|
884
|
+
var extractElevatedHashesFromScript = /* @__PURE__ */ __name((strings) => {
|
|
764
885
|
const hashes = strings.filter((str) => str.startsWith("elevate|")).map((str) => str.split("|")[1]);
|
|
765
886
|
const filtered = filterAs2(hashes, (h) => asHash3(h));
|
|
766
887
|
assertEx5(filtered.length === hashes.length, () => "Invalid elevated hashes");
|
|
767
888
|
return filtered;
|
|
768
|
-
};
|
|
769
|
-
var tryExtractElevatedHashes = (tx) => {
|
|
889
|
+
}, "extractElevatedHashesFromScript");
|
|
890
|
+
var tryExtractElevatedHashes = /* @__PURE__ */ __name((tx) => {
|
|
770
891
|
const [bw, payloads] = tx;
|
|
771
892
|
const { script } = bw;
|
|
772
893
|
const hashes = script ? tryExtractElevatedHashesFromScript(script) : [];
|
|
773
894
|
return payloads.filter((p) => hashes.includes(p._hash)).filter(isAllowedBlockPayloadWithHashStorageMeta);
|
|
774
|
-
};
|
|
775
|
-
var extractElevatedHashes = (tx) => {
|
|
895
|
+
}, "tryExtractElevatedHashes");
|
|
896
|
+
var extractElevatedHashes = /* @__PURE__ */ __name((tx) => {
|
|
776
897
|
const [bw, payloads] = tx;
|
|
777
898
|
const { script } = bw;
|
|
778
899
|
const hashes = script ? tryExtractElevatedHashesFromScript(script) : [];
|
|
779
900
|
const filtered = payloads.filter((p) => hashes.includes(p._hash)).filter(isAllowedBlockPayloadWithHashStorageMeta);
|
|
780
901
|
assertEx5(filtered.length === hashes.length, () => "Invalid elevated hashes");
|
|
781
902
|
return filtered;
|
|
782
|
-
};
|
|
903
|
+
}, "extractElevatedHashes");
|
|
783
904
|
|
|
784
905
|
// src/transaction/signTransaction.ts
|
|
785
906
|
import { toArrayBuffer } from "@xylabs/arraybuffer";
|
|
@@ -789,31 +910,49 @@ import { PayloadBuilder as PayloadBuilder6 } from "@xyo-network/payload-builder"
|
|
|
789
910
|
async function signTransaction(tx, account) {
|
|
790
911
|
assertEx6(tx.from === account.address, () => "Signer address does not match transaction from address");
|
|
791
912
|
const signedTx = structuredClone(tx);
|
|
792
|
-
signedTx.addresses = [
|
|
793
|
-
|
|
794
|
-
|
|
913
|
+
signedTx.addresses = [
|
|
914
|
+
account.address
|
|
915
|
+
];
|
|
916
|
+
signedTx.previous_hashes = [
|
|
917
|
+
account.previousHash ?? null
|
|
918
|
+
];
|
|
919
|
+
const hash = await PayloadBuilder6.dataHash(signedTx);
|
|
795
920
|
const hashBytes = toArrayBuffer(hash);
|
|
796
921
|
const [signature] = await account.sign(hashBytes);
|
|
797
|
-
signedTx.$signatures = [
|
|
922
|
+
signedTx.$signatures = [
|
|
923
|
+
hexFromArrayBuffer(signature)
|
|
924
|
+
];
|
|
798
925
|
return signedTx;
|
|
799
926
|
}
|
|
927
|
+
__name(signTransaction, "signTransaction");
|
|
800
928
|
|
|
801
929
|
// src/wallet/generateXyoBaseWalletFromPhrase.ts
|
|
802
930
|
import { HDWallet } from "@xyo-network/wallet";
|
|
803
931
|
|
|
804
932
|
// src/wallet/paths.ts
|
|
805
933
|
var WALLET_COMPLIANCE = "44'";
|
|
806
|
-
var COIN_TYPES = {
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
var
|
|
934
|
+
var COIN_TYPES = {
|
|
935
|
+
Ethereum: "60'"
|
|
936
|
+
};
|
|
937
|
+
var ACCOUNT_TYPE = {
|
|
938
|
+
GANACHE: "0'",
|
|
939
|
+
XYO: "0'"
|
|
940
|
+
};
|
|
941
|
+
var CHANGE_ADDRESS = {
|
|
942
|
+
META_MASK: "0",
|
|
943
|
+
XYO: "0"
|
|
944
|
+
};
|
|
945
|
+
var ADDRESS_INDEX = {
|
|
946
|
+
META_MASK: "0",
|
|
947
|
+
XYO: "0"
|
|
948
|
+
};
|
|
810
949
|
var DEFAULT_WALLET_PATH = `m/${WALLET_COMPLIANCE}/${COIN_TYPES.Ethereum}/${ACCOUNT_TYPE.XYO}/${CHANGE_ADDRESS.XYO}`;
|
|
811
950
|
|
|
812
951
|
// src/wallet/generateXyoBaseWalletFromPhrase.ts
|
|
813
|
-
var generateXyoBaseWalletFromPhrase = (walletPhrase) => {
|
|
952
|
+
var generateXyoBaseWalletFromPhrase = /* @__PURE__ */ __name((walletPhrase) => {
|
|
814
953
|
const wallet = HDWallet.fromPhrase(walletPhrase, DEFAULT_WALLET_PATH);
|
|
815
954
|
return wallet;
|
|
816
|
-
};
|
|
955
|
+
}, "generateXyoBaseWalletFromPhrase");
|
|
817
956
|
export {
|
|
818
957
|
ACCOUNT_TYPE,
|
|
819
958
|
ADDRESS_INDEX,
|