ox 0.14.17 → 0.14.19
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/CHANGELOG.md +12 -0
- package/_cjs/tempo/TxEnvelopeTempo.js.map +1 -1
- package/_cjs/tempo/VirtualAddress.js +70 -0
- package/_cjs/tempo/VirtualAddress.js.map +1 -0
- package/_cjs/tempo/VirtualMaster.js +278 -0
- package/_cjs/tempo/VirtualMaster.js.map +1 -0
- package/_cjs/tempo/index.js +3 -1
- package/_cjs/tempo/index.js.map +1 -1
- package/_cjs/tempo/internal/mine.wasm.js +6 -0
- package/_cjs/tempo/internal/mine.wasm.js.map +1 -0
- package/_cjs/tempo/internal/virtualMasterPool.js +186 -0
- package/_cjs/tempo/internal/virtualMasterPool.js.map +1 -0
- package/_cjs/version.js +1 -1
- package/_esm/tempo/TxEnvelopeTempo.js +6 -3
- package/_esm/tempo/TxEnvelopeTempo.js.map +1 -1
- package/_esm/tempo/VirtualAddress.js +154 -0
- package/_esm/tempo/VirtualAddress.js.map +1 -0
- package/_esm/tempo/VirtualMaster.js +483 -0
- package/_esm/tempo/VirtualMaster.js.map +1 -0
- package/_esm/tempo/index.js +54 -0
- package/_esm/tempo/index.js.map +1 -1
- package/_esm/tempo/internal/mine.wasm.js +15 -0
- package/_esm/tempo/internal/mine.wasm.js.map +1 -0
- package/_esm/tempo/internal/virtualMasterPool.js +216 -0
- package/_esm/tempo/internal/virtualMasterPool.js.map +1 -0
- package/_esm/version.js +1 -1
- package/_types/core/RpcSchema.d.ts +0 -2
- package/_types/core/RpcSchema.d.ts.map +1 -1
- package/_types/tempo/TxEnvelopeTempo.d.ts +6 -3
- package/_types/tempo/TxEnvelopeTempo.d.ts.map +1 -1
- package/_types/tempo/VirtualAddress.d.ts +129 -0
- package/_types/tempo/VirtualAddress.d.ts.map +1 -0
- package/_types/tempo/VirtualMaster.d.ts +237 -0
- package/_types/tempo/VirtualMaster.d.ts.map +1 -0
- package/_types/tempo/index.d.ts +54 -0
- package/_types/tempo/index.d.ts.map +1 -1
- package/_types/tempo/internal/mine.wasm.d.ts +5 -0
- package/_types/tempo/internal/mine.wasm.d.ts.map +1 -0
- package/_types/tempo/internal/virtualMasterPool.d.ts +46 -0
- package/_types/tempo/internal/virtualMasterPool.d.ts.map +1 -0
- package/_types/version.d.ts +1 -1
- package/core/RpcSchema.ts +0 -2
- package/package.json +11 -1
- package/tempo/TxEnvelopeTempo.ts +6 -3
- package/tempo/VirtualAddress/package.json +6 -0
- package/tempo/VirtualAddress.test.ts +88 -0
- package/tempo/VirtualAddress.ts +201 -0
- package/tempo/VirtualMaster/package.json +6 -0
- package/tempo/VirtualMaster.test.ts +204 -0
- package/tempo/VirtualMaster.ts +711 -0
- package/tempo/e2e.test.ts +0 -2
- package/tempo/index.ts +55 -0
- package/tempo/internal/mine.c +182 -0
- package/tempo/internal/mine.wasm.ts +17 -0
- package/tempo/internal/virtualMasterPool.ts +254 -0
- package/version.ts +1 -1
|
@@ -0,0 +1,483 @@
|
|
|
1
|
+
import { keccak_256 } from '@noble/hashes/sha3';
|
|
2
|
+
import * as Address from '../core/Address.js';
|
|
3
|
+
import * as Bytes from '../core/Bytes.js';
|
|
4
|
+
import * as Errors from '../core/Errors.js';
|
|
5
|
+
import * as Hash from '../core/Hash.js';
|
|
6
|
+
import * as Hex from '../core/Hex.js';
|
|
7
|
+
import * as VirtualMasterPool from './internal/virtualMasterPool.js';
|
|
8
|
+
import * as TempoAddress from './TempoAddress.js';
|
|
9
|
+
import * as VirtualAddress from './VirtualAddress.js';
|
|
10
|
+
const tip20Prefix = '0x20c000000000000000000000';
|
|
11
|
+
const zeroAddress = '0x0000000000000000000000000000000000000000';
|
|
12
|
+
/**
|
|
13
|
+
* Computes the TIP-1022 registration hash for a master address and salt.
|
|
14
|
+
*
|
|
15
|
+
* [TIP-1022](https://docs.tempo.xyz/protocol/tips/tip-1022)
|
|
16
|
+
*
|
|
17
|
+
* The registration hash is `keccak256(masterAddress || salt)` where `salt`
|
|
18
|
+
* is encoded as a 32-byte value.
|
|
19
|
+
*
|
|
20
|
+
* Master addresses must satisfy TIP-1022 registration constraints: they cannot
|
|
21
|
+
* be the zero address, another virtual address, or a TIP-20 token address.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts twoslash
|
|
25
|
+
* import { Address, Hex } from 'ox'
|
|
26
|
+
* import { VirtualMaster } from 'ox/tempo'
|
|
27
|
+
*
|
|
28
|
+
* const hash = VirtualMaster.getRegistrationHash({
|
|
29
|
+
* address: Address.from('0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266'),
|
|
30
|
+
* salt: Hex.from('0x00000000000000000000000000000000000000000000000000000000abf52baf'),
|
|
31
|
+
* })
|
|
32
|
+
*
|
|
33
|
+
* hash
|
|
34
|
+
* // @log: '0x0000000058e21090d8f4bee424b90cddc2378aefa1bbbfa1443631a929ae966d'
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* @param value - Master address and salt.
|
|
38
|
+
* @returns The registration hash.
|
|
39
|
+
*/
|
|
40
|
+
export function getRegistrationHash(value) {
|
|
41
|
+
return Hash.keccak256(Hex.concat(resolveAddress(value.address), toFixedHex(value.salt, 32)));
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Derives the 4-byte TIP-1022 `masterId` from a master address and salt.
|
|
45
|
+
*
|
|
46
|
+
* [TIP-1022](https://docs.tempo.xyz/protocol/tips/tip-1022)
|
|
47
|
+
*
|
|
48
|
+
* This returns bytes `[4:8]` of the registration hash, regardless of whether the
|
|
49
|
+
* salt satisfies the proof-of-work requirement.
|
|
50
|
+
*
|
|
51
|
+
* Master addresses must satisfy TIP-1022 registration constraints: they cannot
|
|
52
|
+
* be the zero address, another virtual address, or a TIP-20 token address.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts twoslash
|
|
56
|
+
* import { Address, Hex } from 'ox'
|
|
57
|
+
* import { VirtualMaster } from 'ox/tempo'
|
|
58
|
+
*
|
|
59
|
+
* const masterId = VirtualMaster.getMasterId({
|
|
60
|
+
* address: Address.from('0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266'),
|
|
61
|
+
* salt: Hex.from('0x00000000000000000000000000000000000000000000000000000000abf52baf'),
|
|
62
|
+
* })
|
|
63
|
+
*
|
|
64
|
+
* masterId
|
|
65
|
+
* // @log: '0x58e21090'
|
|
66
|
+
* ```
|
|
67
|
+
*
|
|
68
|
+
* @param value - Master address and salt.
|
|
69
|
+
* @returns The derived master identifier.
|
|
70
|
+
*/
|
|
71
|
+
export function getMasterId(value) {
|
|
72
|
+
return Hex.slice(getRegistrationHash(value), 4, 8);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Validates that a salt satisfies the TIP-1022 32-bit proof-of-work requirement.
|
|
76
|
+
*
|
|
77
|
+
* [TIP-1022](https://docs.tempo.xyz/protocol/tips/tip-1022)
|
|
78
|
+
*
|
|
79
|
+
* Returns `false` for invalid master addresses, including the zero address,
|
|
80
|
+
* virtual addresses, and TIP-20 token addresses.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```ts twoslash
|
|
84
|
+
* import { Address, Hex } from 'ox'
|
|
85
|
+
* import { VirtualMaster } from 'ox/tempo'
|
|
86
|
+
*
|
|
87
|
+
* const valid = VirtualMaster.validateSalt({
|
|
88
|
+
* address: Address.from('0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266'),
|
|
89
|
+
* salt: Hex.from('0x00000000000000000000000000000000000000000000000000000000abf52baf'),
|
|
90
|
+
* })
|
|
91
|
+
*
|
|
92
|
+
* valid
|
|
93
|
+
* // @log: true
|
|
94
|
+
* ```
|
|
95
|
+
*
|
|
96
|
+
* @param value - Master address and salt.
|
|
97
|
+
* @returns `true` if the first 4 bytes of the registration hash are zero.
|
|
98
|
+
*/
|
|
99
|
+
export function validateSalt(value) {
|
|
100
|
+
try {
|
|
101
|
+
return hasProofOfWork(Hash.keccak256(Hex.concat(resolveAddress(value.address), toFixedHex(value.salt, 32)), { as: 'Bytes' }));
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Searches a bounded range of salts for the first value that satisfies TIP-1022 PoW.
|
|
109
|
+
*
|
|
110
|
+
* [TIP-1022](https://tips.sh/1022)
|
|
111
|
+
*
|
|
112
|
+
* This is intentionally a small, deterministic primitive. It does not coordinate
|
|
113
|
+
* workers or async execution. Callers that need large searches can shard ranges
|
|
114
|
+
* externally.
|
|
115
|
+
*
|
|
116
|
+
* Master addresses must satisfy TIP-1022 registration constraints: they cannot
|
|
117
|
+
* be the zero address, another virtual address, or a TIP-20 token address.
|
|
118
|
+
*
|
|
119
|
+
* :::warning
|
|
120
|
+
*
|
|
121
|
+
* It is strongly recommended to use {@link ox#VirtualMaster.(mineSaltAsync:function)} instead of this
|
|
122
|
+
* function. `mineSaltAsync` uses WASM-accelerated keccak256 with parallel
|
|
123
|
+
* workers and is a lot faster than the pure JS implementation used here.
|
|
124
|
+
*
|
|
125
|
+
* :::
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```ts twoslash
|
|
129
|
+
* import { Address } from 'ox'
|
|
130
|
+
* import { VirtualMaster } from 'ox/tempo'
|
|
131
|
+
*
|
|
132
|
+
* const result = VirtualMaster.mineSalt({
|
|
133
|
+
* address: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
|
|
134
|
+
* })
|
|
135
|
+
*
|
|
136
|
+
* result?.salt
|
|
137
|
+
* // @log: '0x00000000000000000000000000000000000000000000000000000000abf52baf'
|
|
138
|
+
* ```
|
|
139
|
+
*
|
|
140
|
+
* @param value - Search range parameters.
|
|
141
|
+
* @returns The first matching salt in the range, if any.
|
|
142
|
+
*/
|
|
143
|
+
export function mineSalt(value) {
|
|
144
|
+
const count = value.count ?? 2 ** 32;
|
|
145
|
+
assertCount(count);
|
|
146
|
+
const addressBytes = Bytes.fromHex(resolveAddress(value.address));
|
|
147
|
+
const input = new Uint8Array(addressBytes.length + 32);
|
|
148
|
+
input.set(addressBytes);
|
|
149
|
+
// Salt is a view into input — increment mutates input directly, no copy.
|
|
150
|
+
const saltView = input.subarray(addressBytes.length);
|
|
151
|
+
saltView.set(toFixedBytes(value.start ?? 0n, 32));
|
|
152
|
+
for (let i = 0; i < count; i++) {
|
|
153
|
+
const hash = keccak_256(input);
|
|
154
|
+
if (hash[0] === 0 && hash[1] === 0 && hash[2] === 0 && hash[3] === 0) {
|
|
155
|
+
return {
|
|
156
|
+
masterId: Hex.fromBytes(hash.subarray(4, 8)),
|
|
157
|
+
registrationHash: Hex.fromBytes(hash),
|
|
158
|
+
salt: Hex.fromBytes(saltView),
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
if (i < count - 1 && !increment(saltView))
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
return undefined;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Searches for a salt that satisfies TIP-1022 PoW using parallel workers and
|
|
168
|
+
* WASM-accelerated keccak256.
|
|
169
|
+
*
|
|
170
|
+
* [TIP-1022](https://tips.sh/1022)
|
|
171
|
+
*
|
|
172
|
+
* Uses WASM-accelerated keccak256 with parallel
|
|
173
|
+
* workers when available. Falls back to chunked single-threaded mining in
|
|
174
|
+
* environments without worker support.
|
|
175
|
+
*
|
|
176
|
+
* - **Node.js / Bun / Deno**: Spawns `worker_threads` with inline WASM keccak256.
|
|
177
|
+
* - **Browsers**: Spawns Web Workers via Blob URLs with inline WASM keccak256.
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* ```ts twoslash
|
|
181
|
+
* import { Address } from 'ox'
|
|
182
|
+
* import { VirtualMaster } from 'ox/tempo'
|
|
183
|
+
*
|
|
184
|
+
* const result = await VirtualMaster.mineSaltAsync({
|
|
185
|
+
* address: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
|
|
186
|
+
* })
|
|
187
|
+
* ```
|
|
188
|
+
*
|
|
189
|
+
* @param parameters - Search parameters.
|
|
190
|
+
* @returns The first matching salt, if any.
|
|
191
|
+
*/
|
|
192
|
+
export async function mineSaltAsync(parameters) {
|
|
193
|
+
const { chunkSize = 100_000, count = 2 ** 32, onProgress, signal, start: start_ = 0n, workers = getDefaultWorkerCount(), } = parameters;
|
|
194
|
+
const address = resolveAddress(parameters.address);
|
|
195
|
+
const start = toFixedHex(start_, 32);
|
|
196
|
+
assertCount(count);
|
|
197
|
+
if (workers !== undefined)
|
|
198
|
+
assertWorkers(workers);
|
|
199
|
+
throwIfAborted(signal);
|
|
200
|
+
const workerCount = Math.max(1, Math.min(workers, Math.ceil(count / chunkSize)));
|
|
201
|
+
if (workerCount <= 1)
|
|
202
|
+
return mineSaltAsyncFallback({
|
|
203
|
+
address,
|
|
204
|
+
chunkSize,
|
|
205
|
+
count,
|
|
206
|
+
onProgress,
|
|
207
|
+
signal,
|
|
208
|
+
start,
|
|
209
|
+
});
|
|
210
|
+
const pool = await VirtualMasterPool.resolve();
|
|
211
|
+
if (!pool)
|
|
212
|
+
return mineSaltAsyncFallback({
|
|
213
|
+
address,
|
|
214
|
+
chunkSize,
|
|
215
|
+
count,
|
|
216
|
+
onProgress,
|
|
217
|
+
signal,
|
|
218
|
+
start,
|
|
219
|
+
});
|
|
220
|
+
return mineSaltWithWorkerPool({
|
|
221
|
+
address,
|
|
222
|
+
chunkSize,
|
|
223
|
+
count,
|
|
224
|
+
onProgress,
|
|
225
|
+
pool,
|
|
226
|
+
signal,
|
|
227
|
+
start,
|
|
228
|
+
workerCount,
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Runs parallel salt mining across a worker pool.
|
|
233
|
+
*
|
|
234
|
+
* @internal
|
|
235
|
+
*/
|
|
236
|
+
// biome-ignore lint/correctness/noUnusedVariables: _
|
|
237
|
+
function mineSaltWithWorkerPool(value) {
|
|
238
|
+
const startedAt = Date.now();
|
|
239
|
+
return new Promise((resolve, reject) => {
|
|
240
|
+
let settled = false;
|
|
241
|
+
let attempts = 0;
|
|
242
|
+
let completedWorkers = 0;
|
|
243
|
+
const handles = [];
|
|
244
|
+
const emitProgress = () => {
|
|
245
|
+
if (!value.onProgress)
|
|
246
|
+
return;
|
|
247
|
+
const elapsed = Date.now() - startedAt;
|
|
248
|
+
const seconds = elapsed / 1000;
|
|
249
|
+
value.onProgress({
|
|
250
|
+
attempts,
|
|
251
|
+
chunkSize: value.chunkSize,
|
|
252
|
+
count: value.count,
|
|
253
|
+
elapsed,
|
|
254
|
+
progress: Math.min(1, attempts / value.count),
|
|
255
|
+
rate: seconds === 0 ? 0 : attempts / seconds,
|
|
256
|
+
workers: value.workerCount,
|
|
257
|
+
});
|
|
258
|
+
};
|
|
259
|
+
const terminateAll = () => {
|
|
260
|
+
for (const h of handles)
|
|
261
|
+
h.terminate();
|
|
262
|
+
};
|
|
263
|
+
const succeed = (result) => {
|
|
264
|
+
if (settled)
|
|
265
|
+
return;
|
|
266
|
+
settled = true;
|
|
267
|
+
value.signal?.removeEventListener('abort', onAbort);
|
|
268
|
+
terminateAll();
|
|
269
|
+
resolve(result);
|
|
270
|
+
};
|
|
271
|
+
const fail = (error) => {
|
|
272
|
+
if (settled)
|
|
273
|
+
return;
|
|
274
|
+
settled = true;
|
|
275
|
+
value.signal?.removeEventListener('abort', onAbort);
|
|
276
|
+
terminateAll();
|
|
277
|
+
reject(error instanceof Error
|
|
278
|
+
? error
|
|
279
|
+
: new Errors.BaseError('Failed to mine virtual master salt.'));
|
|
280
|
+
};
|
|
281
|
+
const onMessage = (msg) => {
|
|
282
|
+
if (settled)
|
|
283
|
+
return;
|
|
284
|
+
switch (msg.type) {
|
|
285
|
+
case 'found':
|
|
286
|
+
succeed(msg.result);
|
|
287
|
+
return;
|
|
288
|
+
case 'progress':
|
|
289
|
+
attempts += msg.attempts;
|
|
290
|
+
emitProgress();
|
|
291
|
+
return;
|
|
292
|
+
case 'done':
|
|
293
|
+
completedWorkers++;
|
|
294
|
+
if (completedWorkers === value.workerCount)
|
|
295
|
+
succeed(undefined);
|
|
296
|
+
return;
|
|
297
|
+
case 'error':
|
|
298
|
+
fail(new Errors.BaseError(msg.message));
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
const onAbort = () => fail(getAbortError(value.signal));
|
|
303
|
+
value.signal?.addEventListener('abort', onAbort, { once: true });
|
|
304
|
+
for (let i = 0; i < value.workerCount; i++) {
|
|
305
|
+
const handle = value.pool.spawn(i, onMessage, fail);
|
|
306
|
+
handles.push(handle);
|
|
307
|
+
handle.postMessage({
|
|
308
|
+
type: 'start',
|
|
309
|
+
address: value.address,
|
|
310
|
+
chunkSize: value.chunkSize,
|
|
311
|
+
count: value.count,
|
|
312
|
+
start: value.start,
|
|
313
|
+
workerCount: value.workerCount,
|
|
314
|
+
workerIndex: i,
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Single-threaded chunked fallback when no worker pool is available.
|
|
321
|
+
*
|
|
322
|
+
* @internal
|
|
323
|
+
*/
|
|
324
|
+
// biome-ignore lint/correctness/noUnusedVariables: _
|
|
325
|
+
async function mineSaltAsyncFallback(value) {
|
|
326
|
+
const startedAt = Date.now();
|
|
327
|
+
const startBigInt = BigInt(value.start);
|
|
328
|
+
for (let offset = 0; offset < value.count; offset += value.chunkSize) {
|
|
329
|
+
throwIfAborted(value.signal);
|
|
330
|
+
const count = Math.min(value.chunkSize, value.count - offset);
|
|
331
|
+
const result = mineSalt({
|
|
332
|
+
address: value.address,
|
|
333
|
+
count,
|
|
334
|
+
start: startBigInt + BigInt(offset),
|
|
335
|
+
});
|
|
336
|
+
if (value.onProgress) {
|
|
337
|
+
const attempts = Math.min(value.count, offset + count);
|
|
338
|
+
const elapsed = Date.now() - startedAt;
|
|
339
|
+
const seconds = elapsed / 1000;
|
|
340
|
+
value.onProgress({
|
|
341
|
+
attempts,
|
|
342
|
+
chunkSize: value.chunkSize,
|
|
343
|
+
count: value.count,
|
|
344
|
+
elapsed,
|
|
345
|
+
progress: Math.min(1, attempts / value.count),
|
|
346
|
+
rate: seconds === 0 ? 0 : attempts / seconds,
|
|
347
|
+
workers: 1,
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
if (result)
|
|
351
|
+
return result;
|
|
352
|
+
// Yield to the event loop between chunks.
|
|
353
|
+
await new Promise((r) => setTimeout(r, 0));
|
|
354
|
+
}
|
|
355
|
+
return undefined;
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Asserts that `workers` is a non-negative safe integer.
|
|
359
|
+
*
|
|
360
|
+
* @internal
|
|
361
|
+
*/
|
|
362
|
+
function assertWorkers(workers) {
|
|
363
|
+
if (Number.isSafeInteger(workers) && workers >= 0)
|
|
364
|
+
return;
|
|
365
|
+
throw new Errors.BaseError(`Workers "${workers}" is invalid. Expected a non-negative safe integer.`);
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Extracts or creates an error from an `AbortSignal`.
|
|
369
|
+
*
|
|
370
|
+
* @internal
|
|
371
|
+
*/
|
|
372
|
+
function getAbortError(signal) {
|
|
373
|
+
const reason = signal?.reason;
|
|
374
|
+
if (reason instanceof Error)
|
|
375
|
+
return reason;
|
|
376
|
+
return new Errors.BaseError('The operation was aborted.');
|
|
377
|
+
}
|
|
378
|
+
/**
|
|
379
|
+
* Returns the default number of workers for the current platform.
|
|
380
|
+
*
|
|
381
|
+
* @internal
|
|
382
|
+
*/
|
|
383
|
+
function getDefaultWorkerCount() {
|
|
384
|
+
if (typeof navigator !== 'undefined') {
|
|
385
|
+
const c = navigator.hardwareConcurrency;
|
|
386
|
+
if (c && c > 1)
|
|
387
|
+
return c - 1;
|
|
388
|
+
}
|
|
389
|
+
return 1;
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* Throws the signal's abort reason if the signal is aborted.
|
|
393
|
+
*
|
|
394
|
+
* @internal
|
|
395
|
+
*/
|
|
396
|
+
function throwIfAborted(signal) {
|
|
397
|
+
if (!signal?.aborted)
|
|
398
|
+
return;
|
|
399
|
+
throw getAbortError(signal);
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* Returns `true` if the first 4 bytes of a hash are zero.
|
|
403
|
+
*
|
|
404
|
+
* @internal
|
|
405
|
+
*/
|
|
406
|
+
function hasProofOfWork(hash) {
|
|
407
|
+
return hash[0] === 0 && hash[1] === 0 && hash[2] === 0 && hash[3] === 0;
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* Asserts that `count` is a positive safe integer.
|
|
411
|
+
*
|
|
412
|
+
* @internal
|
|
413
|
+
*/
|
|
414
|
+
function assertCount(count) {
|
|
415
|
+
if (Number.isSafeInteger(count) && count > 0)
|
|
416
|
+
return;
|
|
417
|
+
throw new Errors.BaseError(`Count "${count}" is invalid. Expected a positive safe integer.`);
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* Increments a big-endian byte array by one. Returns `false` on overflow.
|
|
421
|
+
*
|
|
422
|
+
* @internal
|
|
423
|
+
*/
|
|
424
|
+
function increment(bytes) {
|
|
425
|
+
for (let i = bytes.length - 1; i >= 0; i--) {
|
|
426
|
+
const value = bytes[i];
|
|
427
|
+
if (value === 0xff) {
|
|
428
|
+
bytes[i] = 0;
|
|
429
|
+
continue;
|
|
430
|
+
}
|
|
431
|
+
bytes[i] = value + 1;
|
|
432
|
+
return true;
|
|
433
|
+
}
|
|
434
|
+
return false;
|
|
435
|
+
}
|
|
436
|
+
/**
|
|
437
|
+
* Resolves a Tempo or hex address, validates it as a valid master.
|
|
438
|
+
*
|
|
439
|
+
* @internal
|
|
440
|
+
*/
|
|
441
|
+
function resolveAddress(address) {
|
|
442
|
+
const resolved = TempoAddress.resolve(address);
|
|
443
|
+
Address.assert(resolved, { strict: false });
|
|
444
|
+
assertValidMasterAddress(resolved);
|
|
445
|
+
return resolved;
|
|
446
|
+
}
|
|
447
|
+
/**
|
|
448
|
+
* Throws if the address is zero, virtual, or a TIP-20 token.
|
|
449
|
+
*
|
|
450
|
+
* @internal
|
|
451
|
+
*/
|
|
452
|
+
function assertValidMasterAddress(address) {
|
|
453
|
+
const normalized = address.toLowerCase();
|
|
454
|
+
if (normalized === zeroAddress)
|
|
455
|
+
throw new Errors.BaseError('Virtual master address cannot be the zero address.');
|
|
456
|
+
if (VirtualAddress.isVirtual(address))
|
|
457
|
+
throw new Errors.BaseError('Virtual master address cannot itself be a virtual address.');
|
|
458
|
+
if (normalized.startsWith(tip20Prefix))
|
|
459
|
+
throw new Errors.BaseError('Virtual master address cannot be a TIP-20 token address.');
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
* Converts a salt to a fixed-size byte array.
|
|
463
|
+
*
|
|
464
|
+
* @internal
|
|
465
|
+
*/
|
|
466
|
+
function toFixedBytes(value, size) {
|
|
467
|
+
return Bytes.fromHex(toFixedHex(value, size));
|
|
468
|
+
}
|
|
469
|
+
/**
|
|
470
|
+
* Converts a salt to a zero-padded hex string of the given size.
|
|
471
|
+
*
|
|
472
|
+
* @internal
|
|
473
|
+
*/
|
|
474
|
+
function toFixedHex(value, size) {
|
|
475
|
+
if (typeof value === 'number' || typeof value === 'bigint')
|
|
476
|
+
return Hex.fromNumber(value, { size });
|
|
477
|
+
if (typeof value === 'string') {
|
|
478
|
+
Hex.assert(value, { strict: true });
|
|
479
|
+
return Hex.padLeft(value, size);
|
|
480
|
+
}
|
|
481
|
+
return Hex.fromBytes(Bytes.padLeft(value, size));
|
|
482
|
+
}
|
|
483
|
+
//# sourceMappingURL=VirtualMaster.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VirtualMaster.js","sourceRoot":"","sources":["../../tempo/VirtualMaster.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAC/C,OAA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,QAAQ,IAAI,OAAO,KAAK,KAAK,QAAQ;QACxD,OAAO,GAAG,CAAC,UAAU,CAAC,KAAK,EAAE,EAAE,IAAI,EAAE,CAAC,CAAA;IACxC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,GAAG,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAA;QACnC,OAAO,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;IACjC,CAAC;IACD,OAAO,GAAG,CAAC,SAAS,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAA;AAClD,CAAC"}
|
package/_esm/tempo/index.js
CHANGED
|
@@ -126,6 +126,7 @@ export * as PoolId from './PoolId.js';
|
|
|
126
126
|
*
|
|
127
127
|
* @example
|
|
128
128
|
* ```ts twoslash
|
|
129
|
+
* import 'ox/window'
|
|
129
130
|
* import { Provider, RpcSchema } from 'ox'
|
|
130
131
|
* import { RpcSchemaTempo } from 'ox/tempo'
|
|
131
132
|
*
|
|
@@ -363,6 +364,59 @@ export * as TransactionRequest from './TransactionRequest.js';
|
|
|
363
364
|
* @category Reference
|
|
364
365
|
*/
|
|
365
366
|
export * as TxEnvelopeTempo from './TxEnvelopeTempo.js';
|
|
367
|
+
/**
|
|
368
|
+
* TIP-1022 virtual address encoding and parsing utilities.
|
|
369
|
+
*
|
|
370
|
+
* [TIP-1022](https://docs.tempo.xyz/protocol/tips/tip-1022)
|
|
371
|
+
*
|
|
372
|
+
* Virtual addresses reserve the following 20-byte layout:
|
|
373
|
+
* `[4-byte masterId][10-byte VIRTUAL_MAGIC][6-byte userTag]`.
|
|
374
|
+
* These helpers only operate on the reserved byte layout and do not query
|
|
375
|
+
* onchain registration state.
|
|
376
|
+
*
|
|
377
|
+
* @example
|
|
378
|
+
* ```ts twoslash
|
|
379
|
+
* import { TempoAddress, VirtualAddress } from 'ox/tempo'
|
|
380
|
+
*
|
|
381
|
+
* const masterId = '0x58e21090' // derived when the master registers
|
|
382
|
+
* const userTag = '0x010203040506' // operator-defined deposit identifier
|
|
383
|
+
*
|
|
384
|
+
* const address = VirtualAddress.from({
|
|
385
|
+
* masterId,
|
|
386
|
+
* userTag,
|
|
387
|
+
* })
|
|
388
|
+
*
|
|
389
|
+
* const tempoAddress = TempoAddress.format(address) // optional display format
|
|
390
|
+
* ```
|
|
391
|
+
*
|
|
392
|
+
* @category Reference
|
|
393
|
+
*/
|
|
394
|
+
export * as VirtualAddress from './VirtualAddress.js';
|
|
395
|
+
/**
|
|
396
|
+
* TIP-1022 master registration utilities.
|
|
397
|
+
*
|
|
398
|
+
* [TIP-1022](https://docs.tempo.xyz/protocol/tips/tip-1022)
|
|
399
|
+
*
|
|
400
|
+
* These utilities expose deterministic hashing and bounded salt mining helpers for
|
|
401
|
+
* `registerVirtualMaster(bytes32 salt)` without introducing any extra hashing dependency.
|
|
402
|
+
*
|
|
403
|
+
* @example
|
|
404
|
+
* ```ts twoslash
|
|
405
|
+
* import { Address, Hex } from 'ox'
|
|
406
|
+
* import { VirtualMaster } from 'ox/tempo'
|
|
407
|
+
*
|
|
408
|
+
* const registration = {
|
|
409
|
+
* address: Address.from('0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266'),
|
|
410
|
+
* salt: Hex.from('0x00000000000000000000000000000000000000000000000000000000abf52baf'),
|
|
411
|
+
* }
|
|
412
|
+
*
|
|
413
|
+
* const registrationHash = VirtualMaster.getRegistrationHash(registration) // keccak256(address || salt)
|
|
414
|
+
* const masterId = VirtualMaster.getMasterId(registration) // bytes [4:8] of the hash
|
|
415
|
+
* ```
|
|
416
|
+
*
|
|
417
|
+
* @category Reference
|
|
418
|
+
*/
|
|
419
|
+
export * as VirtualMaster from './VirtualMaster.js';
|
|
366
420
|
/**
|
|
367
421
|
* Zone ID utilities for converting between zone IDs and zone chain IDs.
|
|
368
422
|
*
|
package/_esm/tempo/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../tempo/index.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,OAAO,KAAK,kBAAkB,MAAM,yBAAyB,CAAA;AAC7D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,OAAO,KAAK,gBAAgB,MAAM,uBAAuB,CAAA;AACzD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AAErC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AACrC
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../tempo/index.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,OAAO,KAAK,kBAAkB,MAAM,yBAAyB,CAAA;AAC7D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,OAAO,KAAK,gBAAgB,MAAM,uBAAuB,CAAA;AACzD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AAErC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AACrC;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,KAAK,cAAc,MAAM,qBAAqB,CAAA;AAErD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,KAAK,iBAAiB,MAAM,wBAAwB,CAAA;AAC3D;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,KAAK,YAAY,MAAM,mBAAmB,CAAA;AACjD;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AACjC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AACvC;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAA;AAC3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAA;AAC/C;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,KAAK,kBAAkB,MAAM,yBAAyB,CAAA;AAC7D;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,KAAK,kBAAkB,MAAM,yBAAyB,CAAA;AAC7D;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,OAAO,KAAK,eAAe,MAAM,sBAAsB,CAAA;AACvD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,OAAO,KAAK,cAAc,MAAM,qBAAqB,CAAA;AACrD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAA;AAEnD;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AACrC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,OAAO,KAAK,qBAAqB,MAAM,4BAA4B,CAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Embedded TIP-1022 WASM keccak256 salt miner (compiled from mine.c).
|
|
2
|
+
//
|
|
3
|
+
// Memory layout at offset 1024:
|
|
4
|
+
// [0..19] address (20 bytes, set by JS)
|
|
5
|
+
// [20..51] salt (32 bytes, set/read by JS, incremented in-place)
|
|
6
|
+
// [52..83] hash out (32 bytes, written on match)
|
|
7
|
+
//
|
|
8
|
+
// Exported: mine(count: i32) -> i32 — returns 1 if found, 0 if not.
|
|
9
|
+
//
|
|
10
|
+
// Generated by: pnpm tsx scripts/build-mine-wasm.ts
|
|
11
|
+
/** Base64-encoded WAS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J5KwhzaWduLWV4dCsPcmVmZXJlbmNlLXR5cGVzKwptdWx0aXZhbHVlKw9idWxrLW1lbW9yeS1vcHQrFmNhbGwtaW5kaXJlY3Qtb3Zlcmxvbmc=';
|
|
13
|
+
/** Byte offset in WASM linear memory where mining I/O begins. */
|
|
14
|
+
export const dataOffset = 1024;
|
|
15
|
+
//# sourceMappingURL=mine.wasm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mine.wasm.js","sourceRoot":"","sources":["../../../tempo/internal/mine.wasm.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,EAAE;AACF,gCAAgC;AAChC,8CAA8C;AAC9C,yEAAyE;AACzE,qDAAqD;AACrD,EAAE;AACF,oEAAoE;AACpE,EAAE;AACF,oDAAoD;AAEpD,8DAA8D;AAC9D,MAAM,CAAC,MAAM,UAAU,GACrB,8tGAA8tG,CAAA;AAEhuG,iEAAiE;AACjE,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,CAAA"}
|