ox 0.14.16 → 0.14.18
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 +16 -0
- package/_cjs/tempo/TransactionRequest.js +10 -1
- package/_cjs/tempo/TransactionRequest.js.map +1 -1
- package/_cjs/tempo/VirtualAddress.js +70 -0
- package/_cjs/tempo/VirtualAddress.js.map +1 -0
- package/_cjs/tempo/VirtualMaster.js +99 -0
- package/_cjs/tempo/VirtualMaster.js.map +1 -0
- package/_cjs/tempo/ZoneId.js +13 -0
- package/_cjs/tempo/ZoneId.js.map +1 -0
- package/_cjs/tempo/ZoneRpcAuthentication.js +101 -0
- package/_cjs/tempo/ZoneRpcAuthentication.js.map +1 -0
- package/_cjs/tempo/index.js +5 -1
- package/_cjs/tempo/index.js.map +1 -1
- package/_cjs/version.js +1 -1
- package/_esm/tempo/TransactionRequest.js +10 -1
- package/_esm/tempo/TransactionRequest.js.map +1 -1
- package/_esm/tempo/VirtualAddress.js +154 -0
- package/_esm/tempo/VirtualAddress.js.map +1 -0
- package/_esm/tempo/VirtualMaster.js +200 -0
- package/_esm/tempo/VirtualMaster.js.map +1 -0
- package/_esm/tempo/ZoneId.js +47 -0
- package/_esm/tempo/ZoneId.js.map +1 -0
- package/_esm/tempo/ZoneRpcAuthentication.js +256 -0
- package/_esm/tempo/ZoneRpcAuthentication.js.map +1 -0
- package/_esm/tempo/index.js +107 -0
- package/_esm/tempo/index.js.map +1 -1
- 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/TransactionRequest.d.ts +6 -4
- package/_types/tempo/TransactionRequest.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 +155 -0
- package/_types/tempo/VirtualMaster.d.ts.map +1 -0
- package/_types/tempo/ZoneId.d.ts +50 -0
- package/_types/tempo/ZoneId.d.ts.map +1 -0
- package/_types/tempo/ZoneRpcAuthentication.d.ts +268 -0
- package/_types/tempo/ZoneRpcAuthentication.d.ts.map +1 -0
- package/_types/tempo/index.d.ts +107 -0
- package/_types/tempo/index.d.ts.map +1 -1
- package/_types/version.d.ts +1 -1
- package/core/RpcSchema.ts +0 -2
- package/package.json +21 -1
- package/tempo/TransactionRequest.test.ts +26 -2
- package/tempo/TransactionRequest.ts +17 -7
- 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 +127 -0
- package/tempo/VirtualMaster.ts +303 -0
- package/tempo/ZoneId/package.json +6 -0
- package/tempo/ZoneId.test.ts +42 -0
- package/tempo/ZoneId.ts +58 -0
- package/tempo/ZoneRpcAuthentication/package.json +6 -0
- package/tempo/ZoneRpcAuthentication.test.ts +226 -0
- package/tempo/ZoneRpcAuthentication.ts +423 -0
- package/tempo/index.ts +107 -8
- package/version.ts +1 -1
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import * as Address from '../core/Address.js';
|
|
2
|
+
import * as Bytes from '../core/Bytes.js';
|
|
3
|
+
import * as Errors from '../core/Errors.js';
|
|
4
|
+
import * as Hash from '../core/Hash.js';
|
|
5
|
+
import * as Hex from '../core/Hex.js';
|
|
6
|
+
import * as TempoAddress from './TempoAddress.js';
|
|
7
|
+
import * as VirtualAddress from './VirtualAddress.js';
|
|
8
|
+
const tip20Prefix = '0x20c000000000000000000000';
|
|
9
|
+
const zeroAddress = '0x0000000000000000000000000000000000000000';
|
|
10
|
+
/**
|
|
11
|
+
* Computes the TIP-1022 registration hash for a master address and salt.
|
|
12
|
+
*
|
|
13
|
+
* [TIP-1022](https://docs.tempo.xyz/protocol/tips/tip-1022)
|
|
14
|
+
*
|
|
15
|
+
* The registration hash is `keccak256(masterAddress || salt)` where `salt`
|
|
16
|
+
* is encoded as a 32-byte value.
|
|
17
|
+
*
|
|
18
|
+
* Master addresses must satisfy TIP-1022 registration constraints: they cannot
|
|
19
|
+
* be the zero address, another virtual address, or a TIP-20 token address.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts twoslash
|
|
23
|
+
* import { VirtualMaster } from 'ox/tempo'
|
|
24
|
+
*
|
|
25
|
+
* const hash = VirtualMaster.getRegistrationHash({
|
|
26
|
+
* address: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
|
|
27
|
+
* salt: '0x00000000000000000000000000000000000000000000000000000000abf52baf',
|
|
28
|
+
* })
|
|
29
|
+
*
|
|
30
|
+
* hash
|
|
31
|
+
* // @log: '0x0000000058e21090d8f4bee424b90cddc2378aefa1bbbfa1443631a929ae966d'
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @param value - Master address and salt.
|
|
35
|
+
* @returns The registration hash.
|
|
36
|
+
*/
|
|
37
|
+
export function getRegistrationHash(value) {
|
|
38
|
+
return Hash.keccak256(Hex.concat(resolveAddress(value.address), toFixedHex(value.salt, 32)));
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Derives the 4-byte TIP-1022 `masterId` from a master address and salt.
|
|
42
|
+
*
|
|
43
|
+
* [TIP-1022](https://docs.tempo.xyz/protocol/tips/tip-1022)
|
|
44
|
+
*
|
|
45
|
+
* This returns bytes `[4:8]` of the registration hash, regardless of whether the
|
|
46
|
+
* salt satisfies the proof-of-work requirement.
|
|
47
|
+
*
|
|
48
|
+
* Master addresses must satisfy TIP-1022 registration constraints: they cannot
|
|
49
|
+
* be the zero address, another virtual address, or a TIP-20 token address.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```ts twoslash
|
|
53
|
+
* import { VirtualMaster } from 'ox/tempo'
|
|
54
|
+
*
|
|
55
|
+
* const masterId = VirtualMaster.getMasterId({
|
|
56
|
+
* address: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
|
|
57
|
+
* salt: '0x00000000000000000000000000000000000000000000000000000000abf52baf',
|
|
58
|
+
* })
|
|
59
|
+
*
|
|
60
|
+
* masterId
|
|
61
|
+
* // @log: '0x58e21090'
|
|
62
|
+
* ```
|
|
63
|
+
*
|
|
64
|
+
* @param value - Master address and salt.
|
|
65
|
+
* @returns The derived master identifier.
|
|
66
|
+
*/
|
|
67
|
+
export function getMasterId(value) {
|
|
68
|
+
return Hex.slice(getRegistrationHash(value), 4, 8);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Validates that a salt satisfies the TIP-1022 32-bit proof-of-work requirement.
|
|
72
|
+
*
|
|
73
|
+
* [TIP-1022](https://docs.tempo.xyz/protocol/tips/tip-1022)
|
|
74
|
+
*
|
|
75
|
+
* Returns `false` for invalid master addresses, including the zero address,
|
|
76
|
+
* virtual addresses, and TIP-20 token addresses.
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```ts twoslash
|
|
80
|
+
* import { VirtualMaster } from 'ox/tempo'
|
|
81
|
+
*
|
|
82
|
+
* const valid = VirtualMaster.validateSalt({
|
|
83
|
+
* address: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
|
|
84
|
+
* salt: '0x00000000000000000000000000000000000000000000000000000000abf52baf',
|
|
85
|
+
* })
|
|
86
|
+
*
|
|
87
|
+
* valid
|
|
88
|
+
* // @log: true
|
|
89
|
+
* ```
|
|
90
|
+
*
|
|
91
|
+
* @param value - Master address and salt.
|
|
92
|
+
* @returns `true` if the first 4 bytes of the registration hash are zero.
|
|
93
|
+
*/
|
|
94
|
+
export function validateSalt(value) {
|
|
95
|
+
try {
|
|
96
|
+
return hasProofOfWork(Hash.keccak256(Hex.concat(resolveAddress(value.address), toFixedHex(value.salt, 32)), { as: 'Bytes' }));
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Searches a bounded range of salts for the first value that satisfies TIP-1022 PoW.
|
|
104
|
+
*
|
|
105
|
+
* [TIP-1022](https://docs.tempo.xyz/protocol/tips/tip-1022)
|
|
106
|
+
*
|
|
107
|
+
* This is intentionally a small, deterministic primitive. It does not coordinate
|
|
108
|
+
* workers or async execution. Callers that need large searches can shard ranges
|
|
109
|
+
* externally.
|
|
110
|
+
*
|
|
111
|
+
* Master addresses must satisfy TIP-1022 registration constraints: they cannot
|
|
112
|
+
* be the zero address, another virtual address, or a TIP-20 token address.
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```ts twoslash
|
|
116
|
+
* import { VirtualMaster } from 'ox/tempo'
|
|
117
|
+
*
|
|
118
|
+
* const result = VirtualMaster.mineSalt({
|
|
119
|
+
* address: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
|
|
120
|
+
* start: 0xabf52ba0n,
|
|
121
|
+
* count: 16,
|
|
122
|
+
* })
|
|
123
|
+
*
|
|
124
|
+
* result?.salt
|
|
125
|
+
* // @log: '0x00000000000000000000000000000000000000000000000000000000abf52baf'
|
|
126
|
+
* ```
|
|
127
|
+
*
|
|
128
|
+
* @param value - Search range parameters.
|
|
129
|
+
* @returns The first matching salt in the range, if any.
|
|
130
|
+
*/
|
|
131
|
+
export function mineSalt(value) {
|
|
132
|
+
assertCount(value.count);
|
|
133
|
+
const address = resolveAddress(value.address);
|
|
134
|
+
const addressBytes = Bytes.fromHex(address);
|
|
135
|
+
const saltBytes = toFixedBytes(value.start ?? 0n, 32);
|
|
136
|
+
const input = new Uint8Array(addressBytes.length + saltBytes.length);
|
|
137
|
+
input.set(addressBytes);
|
|
138
|
+
for (let i = 0; i < value.count; i++) {
|
|
139
|
+
input.set(saltBytes, addressBytes.length);
|
|
140
|
+
const registrationHash = Hash.keccak256(input, { as: 'Bytes' });
|
|
141
|
+
if (hasProofOfWork(registrationHash)) {
|
|
142
|
+
return {
|
|
143
|
+
masterId: Hex.fromBytes(registrationHash.subarray(4, 8)),
|
|
144
|
+
registrationHash: Hex.fromBytes(registrationHash),
|
|
145
|
+
salt: Hex.fromBytes(saltBytes),
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
if (i < value.count - 1 && !increment(saltBytes))
|
|
149
|
+
break;
|
|
150
|
+
}
|
|
151
|
+
return undefined;
|
|
152
|
+
}
|
|
153
|
+
function hasProofOfWork(hash) {
|
|
154
|
+
return hash[0] === 0 && hash[1] === 0 && hash[2] === 0 && hash[3] === 0;
|
|
155
|
+
}
|
|
156
|
+
function assertCount(count) {
|
|
157
|
+
if (Number.isSafeInteger(count) && count > 0)
|
|
158
|
+
return;
|
|
159
|
+
throw new Errors.BaseError(`Count "${count}" is invalid. Expected a positive safe integer.`);
|
|
160
|
+
}
|
|
161
|
+
function increment(bytes) {
|
|
162
|
+
for (let i = bytes.length - 1; i >= 0; i--) {
|
|
163
|
+
const value = bytes[i];
|
|
164
|
+
if (value === 0xff) {
|
|
165
|
+
bytes[i] = 0;
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
bytes[i] = value + 1;
|
|
169
|
+
return true;
|
|
170
|
+
}
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
function resolveAddress(address) {
|
|
174
|
+
const resolved = TempoAddress.resolve(address);
|
|
175
|
+
Address.assert(resolved, { strict: false });
|
|
176
|
+
assertValidMasterAddress(resolved);
|
|
177
|
+
return resolved;
|
|
178
|
+
}
|
|
179
|
+
function assertValidMasterAddress(address) {
|
|
180
|
+
const normalized = address.toLowerCase();
|
|
181
|
+
if (normalized === zeroAddress)
|
|
182
|
+
throw new Errors.BaseError('Virtual master address cannot be the zero address.');
|
|
183
|
+
if (VirtualAddress.isVirtual(address))
|
|
184
|
+
throw new Errors.BaseError('Virtual master address cannot itself be a virtual address.');
|
|
185
|
+
if (normalized.startsWith(tip20Prefix))
|
|
186
|
+
throw new Errors.BaseError('Virtual master address cannot be a TIP-20 token address.');
|
|
187
|
+
}
|
|
188
|
+
function toFixedBytes(value, size) {
|
|
189
|
+
return Bytes.fromHex(toFixedHex(value, size));
|
|
190
|
+
}
|
|
191
|
+
function toFixedHex(value, size) {
|
|
192
|
+
if (typeof value === 'number' || typeof value === 'bigint')
|
|
193
|
+
return Hex.fromNumber(value, { size });
|
|
194
|
+
if (typeof value === 'string') {
|
|
195
|
+
Hex.assert(value, { strict: true });
|
|
196
|
+
return Hex.padLeft(value, size);
|
|
197
|
+
}
|
|
198
|
+
return Hex.fromBytes(Bytes.padLeft(value, size));
|
|
199
|
+
}
|
|
200
|
+
//# sourceMappingURL=VirtualMaster.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VirtualMaster.js","sourceRoot":"","sources":["../../tempo/VirtualMaster.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,oBAAoB,CAAA;AAC7C,OAAO,KAAK,KAAK,MAAM,kBAAkB,CAAA;AACzC,OAAO,KAAK,MAAM,MAAM,mBAAmB,CAAA;AAC3C,OAAO,KAAK,IAAI,MAAM,iBAAiB,CAAA;AACvC,OAAO,KAAK,GAAG,MAAM,gBAAgB,CAAA;AACrC,OAAO,KAAK,YAAY,MAAM,mBAAmB,CAAA;AACjD,OAAO,KAAK,cAAc,MAAM,qBAAqB,CAAA;AAErD,MAAM,WAAW,GAAG,4BAA4B,CAAA;AAChD,MAAM,WAAW,GAAG,4CAA4C,CAAA;AAKhE;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAAgC;IAClE,OAAO,IAAI,CAAC,SAAS,CACnB,GAAG,CAAC,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,UAAU,CAAC,KAAK,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CACtE,CAAA;AACH,CAAC;AAuBD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,UAAU,WAA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AC,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"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base offset for deriving zone chain IDs.
|
|
3
|
+
*
|
|
4
|
+
* Zone chain IDs are computed as `chainIdBase + zoneId`.
|
|
5
|
+
*/
|
|
6
|
+
export const chainIdBase = 4_217_000_000;
|
|
7
|
+
/**
|
|
8
|
+
* Derives a zone ID from a zone chain ID.
|
|
9
|
+
*
|
|
10
|
+
* Zone chain IDs follow the formula `4_217_000_000 + zoneId`, so a chain ID
|
|
11
|
+
* of `4217000006` corresponds to zone ID `6`.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts twoslash
|
|
15
|
+
* import { ZoneId } from 'ox/tempo'
|
|
16
|
+
*
|
|
17
|
+
* const zoneId = ZoneId.fromChainId(4_217_000_006)
|
|
18
|
+
* // @log: 6
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @param chainId - The zone chain ID.
|
|
22
|
+
* @returns The zone ID.
|
|
23
|
+
*/
|
|
24
|
+
export function fromChainId(chainId) {
|
|
25
|
+
return chainId - chainIdBase;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Derives a zone chain ID from a zone ID.
|
|
29
|
+
*
|
|
30
|
+
* Zone chain IDs follow the formula `4_217_000_000 + zoneId`, so zone ID
|
|
31
|
+
* `6` corresponds to chain ID `4217000006`.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts twoslash
|
|
35
|
+
* import { ZoneId } from 'ox/tempo'
|
|
36
|
+
*
|
|
37
|
+
* const chainId = ZoneId.toChainId(6)
|
|
38
|
+
* // @log: 4217000006
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* @param zoneId - The zone ID.
|
|
42
|
+
* @returns The zone chain ID.
|
|
43
|
+
*/
|
|
44
|
+
export function toChainId(zoneId) {
|
|
45
|
+
return chainIdBase + zoneId;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=ZoneId.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ZoneId.js","sourceRoot":"","sources":["../../tempo/ZoneId.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,aAAsB,CAAA;AAEjD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,WAAW,CAAC,OAAe;IACzC,OAAO,OAAO,GAAG,WAAW,CAAA;AAC9B,CAAC;AAMD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,SAAS,CAAC,MAAc;IACtC,OAAO,WAAW,GAAG,MAAM,CAAA;AAC7B,CAAC"}
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import * as Errors from '../core/Errors.js';
|
|
2
|
+
import * as Hash from '../core/Hash.js';
|
|
3
|
+
import * as Hex from '../core/Hex.js';
|
|
4
|
+
import * as SignatureEnvelope from './SignatureEnvelope.js';
|
|
5
|
+
import * as TempoAddress from './TempoAddress.js';
|
|
6
|
+
/**
|
|
7
|
+
* Header name used to transport Zone RPC authentication tokens.
|
|
8
|
+
*/
|
|
9
|
+
export const headerName = 'X-Authorization-Token';
|
|
10
|
+
/**
|
|
11
|
+
* 32-byte domain separator used when hashing Zone RPC authentication tokens.
|
|
12
|
+
*/
|
|
13
|
+
export const magicBytes = '0x54656d706f5a6f6e655250430000000000000000000000000000000000000000';
|
|
14
|
+
/**
|
|
15
|
+
* Size, in bytes, of the fixed Zone RPC authentication fields.
|
|
16
|
+
*/
|
|
17
|
+
export const fieldsSize = 29;
|
|
18
|
+
/** Current Zone RPC authentication version. */
|
|
19
|
+
export const version = 0;
|
|
20
|
+
/**
|
|
21
|
+
* Instantiates a typed Zone RPC authentication token.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts twoslash
|
|
25
|
+
* import { ZoneRpcAuthentication } from 'ox/tempo'
|
|
26
|
+
*
|
|
27
|
+
* const authentication = ZoneRpcAuthentication.from({
|
|
28
|
+
* chainId: 4217000026,
|
|
29
|
+
* expiresAt: 1711235160,
|
|
30
|
+
* issuedAt: 1711234560,
|
|
31
|
+
* zoneId: 26,
|
|
32
|
+
* })
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ### Attaching Signatures
|
|
37
|
+
*
|
|
38
|
+
* ```ts twoslash
|
|
39
|
+
* import { Secp256k1 } from 'ox'
|
|
40
|
+
* import { ZoneRpcAuthentication } from 'ox/tempo'
|
|
41
|
+
*
|
|
42
|
+
* const authentication = ZoneRpcAuthentication.from({
|
|
43
|
+
* chainId: 4217000026,
|
|
44
|
+
* expiresAt: 1711235160,
|
|
45
|
+
* issuedAt: 1711234560,
|
|
46
|
+
* zoneId: 26,
|
|
47
|
+
* })
|
|
48
|
+
*
|
|
49
|
+
* const signature = Secp256k1.sign({
|
|
50
|
+
* payload: ZoneRpcAuthentication.getSignPayload(authentication),
|
|
51
|
+
* privateKey: '0x...',
|
|
52
|
+
* })
|
|
53
|
+
*
|
|
54
|
+
* const authentication_signed = ZoneRpcAuthentication.from(authentication, {
|
|
55
|
+
* signature,
|
|
56
|
+
* })
|
|
57
|
+
* ```
|
|
58
|
+
*
|
|
59
|
+
* @param authentication - Zone RPC authentication token fields.
|
|
60
|
+
* @param options - Zone RPC authentication options.
|
|
61
|
+
* @returns The instantiated Zone RPC authentication token.
|
|
62
|
+
*/
|
|
63
|
+
export function from(authentication, options = {}) {
|
|
64
|
+
const auth = authentication;
|
|
65
|
+
const resolved = {
|
|
66
|
+
...auth,
|
|
67
|
+
version,
|
|
68
|
+
};
|
|
69
|
+
if (options.signature)
|
|
70
|
+
return {
|
|
71
|
+
...resolved,
|
|
72
|
+
signature: SignatureEnvelope.from(options.signature),
|
|
73
|
+
};
|
|
74
|
+
return resolved;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Parses a serialized Zone RPC authentication token.
|
|
78
|
+
*
|
|
79
|
+
* The serialized format is `<signature><29-byte fields>`. The signature is parsed
|
|
80
|
+
* from the prefix and the fixed-length fields are parsed from the suffix.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```ts twoslash
|
|
84
|
+
* import { ZoneRpcAuthentication } from 'ox/tempo'
|
|
85
|
+
*
|
|
86
|
+
* const authentication = ZoneRpcAuthentication.deserialize('0x...')
|
|
87
|
+
* ```
|
|
88
|
+
*
|
|
89
|
+
* @param serialized - The serialized Zone RPC authentication token.
|
|
90
|
+
* @returns The parsed Zone RPC authentication token.
|
|
91
|
+
*/
|
|
92
|
+
export function deserialize(serialized) {
|
|
93
|
+
const size = Hex.size(serialized);
|
|
94
|
+
if (size <= fieldsSize)
|
|
95
|
+
throw new InvalidSerializedError({
|
|
96
|
+
reason: `Serialized authentication must be longer than ${fieldsSize} bytes.`,
|
|
97
|
+
serialized,
|
|
98
|
+
});
|
|
99
|
+
const fieldsOffset = size - fieldsSize;
|
|
100
|
+
const signature = Hex.slice(serialized, 0, fieldsOffset);
|
|
101
|
+
const fields = Hex.slice(serialized, fieldsOffset);
|
|
102
|
+
const parsedVersion = Hex.toNumber(Hex.slice(fields, 0, 1), { size: 1 });
|
|
103
|
+
if (parsedVersion !== version)
|
|
104
|
+
throw new InvalidSerializedError({
|
|
105
|
+
reason: `Unsupported authentication version "${parsedVersion}". Expected "${version}".`,
|
|
106
|
+
serialized,
|
|
107
|
+
});
|
|
108
|
+
return {
|
|
109
|
+
chainId: Hex.toNumber(Hex.slice(fields, 5, 13), { size: 8 }),
|
|
110
|
+
expiresAt: Hex.toNumber(Hex.slice(fields, 21, 29), { size: 8 }),
|
|
111
|
+
issuedAt: Hex.toNumber(Hex.slice(fields, 13, 21), { size: 8 }),
|
|
112
|
+
signature: SignatureEnvelope.deserialize(signature),
|
|
113
|
+
version,
|
|
114
|
+
zoneId: Hex.toNumber(Hex.slice(fields, 1, 5), { size: 4 }),
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Returns the 29-byte fixed field suffix for a Zone RPC authentication token.
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* ```ts twoslash
|
|
122
|
+
* import { ZoneRpcAuthentication } from 'ox/tempo'
|
|
123
|
+
*
|
|
124
|
+
* const fields = ZoneRpcAuthentication.getFields({
|
|
125
|
+
* chainId: 4217000026,
|
|
126
|
+
* expiresAt: 1711235160,
|
|
127
|
+
* issuedAt: 1711234560,
|
|
128
|
+
* zoneId: 26,
|
|
129
|
+
* })
|
|
130
|
+
* ```
|
|
131
|
+
*
|
|
132
|
+
* @param authentication - The Zone RPC authentication token.
|
|
133
|
+
* @returns The fixed 29-byte field suffix.
|
|
134
|
+
*/
|
|
135
|
+
export function getFields(authentication) {
|
|
136
|
+
return Hex.concat(Hex.fromNumber(version, { size: 1 }), Hex.fromNumber(authentication.zoneId, { size: 4 }), Hex.fromNumber(authentication.chainId, { size: 8 }), Hex.fromNumber(authentication.issuedAt, { size: 8 }), Hex.fromNumber(authentication.expiresAt, { size: 8 }));
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Computes the sign payload for a Zone RPC authentication token.
|
|
140
|
+
*
|
|
141
|
+
* When `userAddress` is provided, the payload is wrapped as
|
|
142
|
+
* `keccak256(0x04 || authHash || userAddress)` to match V2 keychain signing.
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```ts twoslash
|
|
146
|
+
* import { ZoneRpcAuthentication } from 'ox/tempo'
|
|
147
|
+
*
|
|
148
|
+
* const authentication = ZoneRpcAuthentication.from({
|
|
149
|
+
* chainId: 4217000026,
|
|
150
|
+
* expiresAt: 1711235160,
|
|
151
|
+
* issuedAt: 1711234560,
|
|
152
|
+
* zoneId: 26,
|
|
153
|
+
* })
|
|
154
|
+
*
|
|
155
|
+
* const payload = ZoneRpcAuthentication.getSignPayload(authentication)
|
|
156
|
+
* ```
|
|
157
|
+
*
|
|
158
|
+
* @param authentication - The Zone RPC authentication token.
|
|
159
|
+
* @param options - Options.
|
|
160
|
+
* @returns The sign payload.
|
|
161
|
+
*/
|
|
162
|
+
export function getSignPayload(authentication, options = {}) {
|
|
163
|
+
const authHash = hash(authentication);
|
|
164
|
+
if (options.userAddress)
|
|
165
|
+
return Hash.keccak256(Hex.concat('0x04', authHash, TempoAddress.resolve(options.userAddress)));
|
|
166
|
+
return authHash;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Computes the raw authorization hash for a Zone RPC authentication token.
|
|
170
|
+
*
|
|
171
|
+
* The hash is `keccak256(magicBytes || fields)`.
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* ```ts twoslash
|
|
175
|
+
* import { ZoneRpcAuthentication } from 'ox/tempo'
|
|
176
|
+
*
|
|
177
|
+
* const authentication = ZoneRpcAuthentication.from({
|
|
178
|
+
* chainId: 4217000026,
|
|
179
|
+
* expiresAt: 1711235160,
|
|
180
|
+
* issuedAt: 1711234560,
|
|
181
|
+
* zoneId: 26,
|
|
182
|
+
* })
|
|
183
|
+
*
|
|
184
|
+
* const hash = ZoneRpcAuthentication.hash(authentication)
|
|
185
|
+
* ```
|
|
186
|
+
*
|
|
187
|
+
* @param authentication - The Zone RPC authentication token.
|
|
188
|
+
* @returns The authorization hash.
|
|
189
|
+
*/
|
|
190
|
+
export function hash(authentication) {
|
|
191
|
+
return Hash.keccak256(Hex.concat(magicBytes, getFields(authentication)));
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Serializes a Zone RPC authentication token to hex.
|
|
195
|
+
*
|
|
196
|
+
* The serialized format is `<signature><29-byte fields>`.
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* ```ts twoslash
|
|
200
|
+
* import { Secp256k1 } from 'ox'
|
|
201
|
+
* import { ZoneRpcAuthentication } from 'ox/tempo'
|
|
202
|
+
*
|
|
203
|
+
* const authentication = ZoneRpcAuthentication.from({
|
|
204
|
+
* chainId: 4217000026,
|
|
205
|
+
* expiresAt: 1711235160,
|
|
206
|
+
* issuedAt: 1711234560,
|
|
207
|
+
* zoneId: 26,
|
|
208
|
+
* })
|
|
209
|
+
*
|
|
210
|
+
* const signature = Secp256k1.sign({
|
|
211
|
+
* payload: ZoneRpcAuthentication.getSignPayload(authentication),
|
|
212
|
+
* privateKey: '0x...',
|
|
213
|
+
* })
|
|
214
|
+
*
|
|
215
|
+
* const serialized = ZoneRpcAuthentication.serialize(authentication, {
|
|
216
|
+
* signature,
|
|
217
|
+
* })
|
|
218
|
+
* ```
|
|
219
|
+
*
|
|
220
|
+
* @param authentication - The Zone RPC authentication token.
|
|
221
|
+
* @param options - Serialization options.
|
|
222
|
+
* @returns The serialized authentication token.
|
|
223
|
+
*/
|
|
224
|
+
export function serialize(authentication, options = {}) {
|
|
225
|
+
const signature = options.signature || authentication.signature;
|
|
226
|
+
if (!signature)
|
|
227
|
+
throw new MissingSignatureError();
|
|
228
|
+
return Hex.concat(SignatureEnvelope.serialize(SignatureEnvelope.from(signature)), getFields(authentication));
|
|
229
|
+
}
|
|
230
|
+
/** Error thrown when a serialized authentication token cannot be deserialized. */
|
|
231
|
+
export class InvalidSerializedError extends Errors.BaseError {
|
|
232
|
+
constructor({ reason, serialized }) {
|
|
233
|
+
super(`Unable to deserialize Zone RPC authentication: ${reason}`, {
|
|
234
|
+
metaMessages: [`Serialized: ${serialized}`],
|
|
235
|
+
});
|
|
236
|
+
Object.defineProperty(this, "name", {
|
|
237
|
+
enumerable: true,
|
|
238
|
+
configurable: true,
|
|
239
|
+
writable: true,
|
|
240
|
+
value: 'ZoneRpcAuthentication.InvalidSerializedError'
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
/** Error thrown when serializing an authentication token without a signature. */
|
|
245
|
+
export class MissingSignatureError extends Errors.BaseError {
|
|
246
|
+
constructor() {
|
|
247
|
+
super('Zone RPC authentication is missing a signature.');
|
|
248
|
+
Object.defineProperty(this, "name", {
|
|
249
|
+
enumerable: true,
|
|
250
|
+
configurable: true,
|
|
251
|
+
writable: true,
|
|
252
|
+
value: 'ZoneRpcAuthentication.MissingSignatureError'
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
//# sourceMappingURL=ZoneRpcAuthentication.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ZoneRpcAuthentication.js","sourceRoot":"","sources":["../../tempo/ZoneRpcAuthentication.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,mBAAmB,CAAA;AAC3C,OAAO,KAAK,IAAI,MAAM,iBAAiB,CAAA;AACvC,OAAO,KAAK,GAAG,MAAM,gBAAgB,CAAA;AAErC,OAAO,KAAK,iBAAiB,MAAM,wBAAwB,CAAA;AAC3D,OAAO,KAAK,YAAY,MAAM,mBAAmB,CAAA;AAEjD;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,uBAAgC,CAAA;AAE1D;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GACrB,oEAA6E,CAAA;AAE/E;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,EAAW,CAAA;AAErC,+CAA+C;AAC/C,MAAM,CAAC,MAAM,OAAO,GAAG,CAAU,CAAA;AAqDjC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,MAAM,UAAU,IAAI,CAIlB,cAAsD,EACtD,UAAmC,EAAE;IAErC,MAAM,IAAI,GAAG,cAAuC,CAAA;IACpD,MAAM,QAAQ,GAAG;QACf,GAAG,IAAI;QACP,OAAO;KACR,CAAA;IACD,IAAI,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
|
363
363
|
* @category Reference
|
|
364
364
|
*/
|
|
365
365
|
export * as TxEnvelopeTempo from './TxEnvelopeTempo.js';
|
|
366
|
+
/**
|
|
367
|
+
* TIP-1022 virtual address encoding and parsing utilities.
|
|
368
|
+
*
|
|
369
|
+
* [TIP-1022](https://docs.tempo.xyz/protocol/tips/tip-1022)
|
|
370
|
+
*
|
|
371
|
+
* Virtual addresses reserve the following 20-byte layout:
|
|
372
|
+
* `[4-byte masterId][10-byte VIRTUAL_MAGIC][6-byte userTag]`.
|
|
373
|
+
* These helpers only operate on the reserved byte layout and do not query
|
|
374
|
+
* onchain registration state.
|
|
375
|
+
*
|
|
376
|
+
* @example
|
|
377
|
+
* ```ts twoslash
|
|
378
|
+
* import { TempoAddress, VirtualAddress } from 'ox/tempo'
|
|
379
|
+
*
|
|
380
|
+
* const masterId = '0x58e21090' // derived when the master registers
|
|
381
|
+
* const userTag = '0x010203040506' // operator-defined deposit identifier
|
|
382
|
+
*
|
|
383
|
+
* const address = VirtualAddress.from({
|
|
384
|
+
* masterId,
|
|
385
|
+
* userTag,
|
|
386
|
+
* })
|
|
387
|
+
*
|
|
388
|
+
* const tempoAddress = TempoAddress.format(address) // optional display format
|
|
389
|
+
* ```
|
|
390
|
+
*
|
|
391
|
+
* @category Reference
|
|
392
|
+
*/
|
|
393
|
+
export * as VirtualAddress from './VirtualAddress.js';
|
|
394
|
+
/**
|
|
395
|
+
* TIP-1022 master registration utilities.
|
|
396
|
+
*
|
|
397
|
+
* [TIP-1022](https://docs.tempo.xyz/protocol/tips/tip-1022)
|
|
398
|
+
*
|
|
399
|
+
* These utilities expose deterministic hashing and bounded salt mining helpers for
|
|
400
|
+
* `registerVirtualMaster(bytes32 salt)` without introducing any extra hashing dependency.
|
|
401
|
+
*
|
|
402
|
+
* @example
|
|
403
|
+
* ```ts twoslash
|
|
404
|
+
* import { VirtualMaster } from 'ox/tempo'
|
|
405
|
+
*
|
|
406
|
+
* const registration = {
|
|
407
|
+
* address: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
|
|
408
|
+
* salt: '0x00000000000000000000000000000000000000000000000000000000abf52baf',
|
|
409
|
+
* }
|
|
410
|
+
*
|
|
411
|
+
* const registrationHash = VirtualMaster.getRegistrationHash(registration) // keccak256(address || salt)
|
|
412
|
+
* const masterId = VirtualMaster.getMasterId(registration) // bytes [4:8] of the hash
|
|
413
|
+
* ```
|
|
414
|
+
*
|
|
415
|
+
* @category Reference
|
|
416
|
+
*/
|
|
417
|
+
export * as VirtualMaster from './VirtualMaster.js';
|
|
418
|
+
/**
|
|
419
|
+
* Zone ID utilities for converting between zone IDs and zone chain IDs.
|
|
420
|
+
*
|
|
421
|
+
* Zone chain IDs are deterministically derived from zone IDs using the formula
|
|
422
|
+
* `421_700_000 + zoneId`. This module provides helpers to convert between them.
|
|
423
|
+
*
|
|
424
|
+
* @example
|
|
425
|
+
* ```ts twoslash
|
|
426
|
+
* import { ZoneId } from 'ox/tempo'
|
|
427
|
+
*
|
|
428
|
+
* const zoneId = ZoneId.fromChainId(421_700_026)
|
|
429
|
+
* // @log: 26
|
|
430
|
+
*
|
|
431
|
+
* const chainId = ZoneId.toChainId(26)
|
|
432
|
+
* // @log: 421700026
|
|
433
|
+
* ```
|
|
434
|
+
*
|
|
435
|
+
* @category Reference
|
|
436
|
+
*/
|
|
437
|
+
export * as ZoneId from './ZoneId.js';
|
|
438
|
+
/**
|
|
439
|
+
* Zone RPC authentication token utilities for private zone RPC access.
|
|
440
|
+
*
|
|
441
|
+
* Zone RPC authentication tokens are short-lived, read-only credentials used in
|
|
442
|
+
* the `X-Authorization-Token` header when talking to private zone RPC endpoints.
|
|
443
|
+
* They reuse Tempo's multi-signature model, so secp256k1, P256, WebAuthn, and
|
|
444
|
+
* keychain access-key signatures all share the same wire format as Tempo
|
|
445
|
+
* transaction signatures.
|
|
446
|
+
*
|
|
447
|
+
* [Zone RPC Specification](https://docs.tempo.xyz/protocol/privacy/rpc#authorization-tokens)
|
|
448
|
+
*
|
|
449
|
+
* @example
|
|
450
|
+
* ```ts twoslash
|
|
451
|
+
* import { Secp256k1 } from 'ox'
|
|
452
|
+
* import { ZoneRpcAuthentication } from 'ox/tempo'
|
|
453
|
+
*
|
|
454
|
+
* const authentication = ZoneRpcAuthentication.from({
|
|
455
|
+
* chainId: 4217000026,
|
|
456
|
+
* expiresAt: 1711235160,
|
|
457
|
+
* issuedAt: 1711234560,
|
|
458
|
+
* zoneId: 26,
|
|
459
|
+
* zonePortal: 'tempox0x0f1b0cedd7e8226e39ecb161f522c8b1ac45e9c8',
|
|
460
|
+
* })
|
|
461
|
+
*
|
|
462
|
+
* const signature = Secp256k1.sign({
|
|
463
|
+
* payload: ZoneRpcAuthentication.getSignPayload(authentication),
|
|
464
|
+
* privateKey: '0x...',
|
|
465
|
+
* })
|
|
466
|
+
*
|
|
467
|
+
* const token = ZoneRpcAuthentication.serialize(authentication, { signature })
|
|
468
|
+
* ```
|
|
469
|
+
*
|
|
470
|
+
* @category Reference
|
|
471
|
+
*/
|
|
472
|
+
export * as ZoneRpcAuthentication from './ZoneRpcAuthentication.js';
|
|
366
473
|
//# sourceMappingURL=index.js.map
|
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;
|
|
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;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;GAiCG;AACH,OAAO,KAAK,qBAAqB,MAAM,4BAA4B,CAAA"}
|
package/_esm/version.js
CHANGED
|
@@ -263,7 +263,6 @@ export type MethodNameGeneric<schema extends Generic = Generic> = schema['Reques
|
|
|
263
263
|
* ReturnType: `0x${string}`
|
|
264
264
|
* }
|
|
265
265
|
* >
|
|
266
|
-
* // ^? [{ Method: 'eth_blockNumber'; Parameters?: undefined; ReturnType: `0x${string}` }, ...]
|
|
267
266
|
* ```
|
|
268
267
|
*/
|
|
269
268
|
export type ToViem<schema extends Generic> = UnionToTuple<schema extends schema ? {
|
|
@@ -285,7 +284,6 @@ export type ToViem<schema extends Generic> = UnionToTuple<schema extends schema
|
|
|
285
284
|
* { Method: 'eth_blockNumber'; Parameters?: undefined; ReturnType: `0x${string}` },
|
|
286
285
|
* { Method: 'eth_chainId'; Parameters?: undefined; ReturnType: `0x${string}` },
|
|
287
286
|
* ]>
|
|
288
|
-
* // ^? { Request: { method: 'eth_blockNumber'; params?: undefined }; ReturnType: `0x${string}` } | ...
|
|
289
287
|
* ```
|
|
290
288
|
*/
|
|
291
289
|
export type FromViem<schema extends readonly ViemSchemaItem[]> = {
|