ox 0.9.16 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +27 -0
- package/README.md +4 -4
- package/TxEnvelope/package.json +6 -0
- package/TxEnvelopeEip1559/package.json +6 -0
- package/TxEnvelopeEip2930/package.json +6 -0
- package/TxEnvelopeEip4844/package.json +6 -0
- package/TxEnvelopeEip7702/package.json +6 -0
- package/TxEnvelopeLegacy/package.json +6 -0
- package/_cjs/core/{TransactionEnvelope.js → TxEnvelope.js} +1 -1
- package/_cjs/core/TxEnvelope.js.map +1 -0
- package/_cjs/core/{TransactionEnvelopeEip1559.js → TxEnvelopeEip1559.js} +2 -2
- package/_cjs/core/TxEnvelopeEip1559.js.map +1 -0
- package/_cjs/core/{TransactionEnvelopeEip2930.js → TxEnvelopeEip2930.js} +2 -2
- package/_cjs/core/TxEnvelopeEip2930.js.map +1 -0
- package/_cjs/core/{TransactionEnvelopeEip4844.js → TxEnvelopeEip4844.js} +4 -4
- package/_cjs/core/TxEnvelopeEip4844.js.map +1 -0
- package/_cjs/core/{TransactionEnvelopeEip7702.js → TxEnvelopeEip7702.js} +4 -4
- package/_cjs/core/TxEnvelopeEip7702.js.map +1 -0
- package/_cjs/core/{TransactionEnvelopeLegacy.js → TxEnvelopeLegacy.js} +2 -2
- package/_cjs/core/TxEnvelopeLegacy.js.map +1 -0
- package/_cjs/core/WebAuthnP256.js +1 -1
- package/_cjs/core/WebAuthnP256.js.map +1 -1
- package/_cjs/erc8021/Attribution.js +36 -6
- package/_cjs/erc8021/Attribution.js.map +1 -1
- package/_cjs/index.docs.js +1 -0
- package/_cjs/index.docs.js.map +1 -1
- package/_cjs/index.js +7 -7
- package/_cjs/index.js.map +1 -1
- package/_cjs/tempo/AuthorizationTempo.js +101 -0
- package/_cjs/tempo/AuthorizationTempo.js.map +1 -0
- package/_cjs/tempo/KeyAuthorization.js +123 -0
- package/_cjs/tempo/KeyAuthorization.js.map +1 -0
- package/_cjs/tempo/PoolId.js +10 -0
- package/_cjs/tempo/PoolId.js.map +1 -0
- package/_cjs/tempo/SignatureEnvelope.js +394 -0
- package/_cjs/tempo/SignatureEnvelope.js.map +1 -0
- package/_cjs/tempo/Tick.js +77 -0
- package/_cjs/tempo/Tick.js.map +1 -0
- package/_cjs/tempo/TokenId.js +28 -0
- package/_cjs/tempo/TokenId.js.map +1 -0
- package/_cjs/tempo/TokenRole.js +26 -0
- package/_cjs/tempo/TokenRole.js.map +1 -0
- package/_cjs/tempo/Transaction.js +80 -0
- package/_cjs/tempo/Transaction.js.map +1 -0
- package/_cjs/tempo/TransactionReceipt.js +26 -0
- package/_cjs/tempo/TransactionReceipt.js.map +1 -0
- package/_cjs/tempo/TransactionRequest.js +53 -0
- package/_cjs/tempo/TransactionRequest.js.map +1 -0
- package/_cjs/tempo/TxEnvelopeTempo.js +267 -0
- package/_cjs/tempo/TxEnvelopeTempo.js.map +1 -0
- package/_cjs/tempo/index.js +15 -0
- package/_cjs/tempo/index.js.map +1 -0
- package/_cjs/version.js +1 -1
- package/_esm/core/Blobs.js +8 -8
- package/_esm/core/{TransactionEnvelope.js → TxEnvelope.js} +11 -11
- package/_esm/core/TxEnvelope.js.map +1 -0
- package/_esm/core/{TransactionEnvelopeEip1559.js → TxEnvelopeEip1559.js} +42 -42
- package/_esm/core/TxEnvelopeEip1559.js.map +1 -0
- package/_esm/core/{TransactionEnvelopeEip2930.js → TxEnvelopeEip2930.js} +43 -43
- package/_esm/core/TxEnvelopeEip2930.js.map +1 -0
- package/_esm/core/{TransactionEnvelopeEip4844.js → TxEnvelopeEip4844.js} +42 -42
- package/_esm/core/TxEnvelopeEip4844.js.map +1 -0
- package/_esm/core/{TransactionEnvelopeEip7702.js → TxEnvelopeEip7702.js} +40 -40
- package/_esm/core/TxEnvelopeEip7702.js.map +1 -0
- package/_esm/core/{TransactionEnvelopeLegacy.js → TxEnvelopeLegacy.js} +42 -42
- package/_esm/core/TxEnvelopeLegacy.js.map +1 -0
- package/_esm/core/WebAuthnP256.js +1 -1
- package/_esm/core/WebAuthnP256.js.map +1 -1
- package/_esm/erc8021/Attribution.js +58 -13
- package/_esm/erc8021/Attribution.js.map +1 -1
- package/_esm/index.docs.js +1 -0
- package/_esm/index.docs.js.map +1 -1
- package/_esm/index.js +192 -192
- package/_esm/index.js.map +1 -1
- package/_esm/tempo/AuthorizationTempo.js +664 -0
- package/_esm/tempo/AuthorizationTempo.js.map +1 -0
- package/_esm/tempo/KeyAuthorization.js +426 -0
- package/_esm/tempo/KeyAuthorization.js.map +1 -0
- package/_esm/tempo/PoolId.js +28 -0
- package/_esm/tempo/PoolId.js.map +1 -0
- package/_esm/tempo/SignatureEnvelope.js +660 -0
- package/_esm/tempo/SignatureEnvelope.js.map +1 -0
- package/_esm/tempo/Tick.js +147 -0
- package/_esm/tempo/Tick.js.map +1 -0
- package/_esm/tempo/TokenId.js +71 -0
- package/_esm/tempo/TokenId.js.map +1 -0
- package/_esm/tempo/TokenRole.js +40 -0
- package/_esm/tempo/TokenRole.js.map +1 -0
- package/_esm/tempo/Transaction.js +167 -0
- package/_esm/tempo/Transaction.js.map +1 -0
- package/_esm/tempo/TransactionReceipt.js +138 -0
- package/_esm/tempo/TransactionReceipt.js.map +1 -0
- package/_esm/tempo/TransactionRequest.js +99 -0
- package/_esm/tempo/TransactionRequest.js.map +1 -0
- package/_esm/tempo/TxEnvelopeTempo.js +607 -0
- package/_esm/tempo/TxEnvelopeTempo.js.map +1 -0
- package/_esm/tempo/index.js +298 -0
- package/_esm/tempo/index.js.map +1 -0
- package/_esm/version.js +1 -1
- package/_types/core/Blobs.d.ts +8 -8
- package/_types/core/{TransactionEnvelope.d.ts → TxEnvelope.d.ts} +11 -11
- package/_types/core/TxEnvelope.d.ts.map +1 -0
- package/_types/core/{TransactionEnvelopeEip1559.d.ts → TxEnvelopeEip1559.d.ts} +54 -54
- package/_types/core/TxEnvelopeEip1559.d.ts.map +1 -0
- package/_types/core/{TransactionEnvelopeEip2930.d.ts → TxEnvelopeEip2930.d.ts} +55 -55
- package/_types/core/TxEnvelopeEip2930.d.ts.map +1 -0
- package/_types/core/{TransactionEnvelopeEip4844.d.ts → TxEnvelopeEip4844.d.ts} +54 -54
- package/_types/core/TxEnvelopeEip4844.d.ts.map +1 -0
- package/_types/core/{TransactionEnvelopeEip7702.d.ts → TxEnvelopeEip7702.d.ts} +49 -49
- package/_types/core/TxEnvelopeEip7702.d.ts.map +1 -0
- package/_types/core/{TransactionEnvelopeLegacy.d.ts → TxEnvelopeLegacy.d.ts} +54 -54
- package/_types/core/TxEnvelopeLegacy.d.ts.map +1 -0
- package/_types/core/WebAuthnP256.d.ts +1 -1
- package/_types/core/WebAuthnP256.d.ts.map +1 -1
- package/_types/erc8021/Attribution.d.ts +20 -6
- package/_types/erc8021/Attribution.d.ts.map +1 -1
- package/_types/index.d.ts +192 -192
- package/_types/index.d.ts.map +1 -1
- package/_types/index.docs.d.ts +1 -0
- package/_types/index.docs.d.ts.map +1 -1
- package/_types/tempo/AuthorizationTempo.d.ts +688 -0
- package/_types/tempo/AuthorizationTempo.d.ts.map +1 -0
- package/_types/tempo/KeyAuthorization.d.ts +437 -0
- package/_types/tempo/KeyAuthorization.d.ts.map +1 -0
- package/_types/tempo/PoolId.d.ts +33 -0
- package/_types/tempo/PoolId.d.ts.map +1 -0
- package/_types/tempo/SignatureEnvelope.d.ts +438 -0
- package/_types/tempo/SignatureEnvelope.d.ts.map +1 -0
- package/_types/tempo/Tick.d.ts +120 -0
- package/_types/tempo/Tick.d.ts.map +1 -0
- package/_types/tempo/TokenId.d.ts +55 -0
- package/_types/tempo/TokenId.d.ts.map +1 -0
- package/_types/tempo/TokenRole.d.ts +29 -0
- package/_types/tempo/TokenRole.d.ts.map +1 -0
- package/_types/tempo/Transaction.d.ts +208 -0
- package/_types/tempo/Transaction.d.ts.map +1 -0
- package/_types/tempo/TransactionReceipt.d.ts +165 -0
- package/_types/tempo/TransactionReceipt.d.ts.map +1 -0
- package/_types/tempo/TransactionRequest.d.ts +89 -0
- package/_types/tempo/TransactionRequest.d.ts.map +1 -0
- package/_types/tempo/TxEnvelopeTempo.d.ts +551 -0
- package/_types/tempo/TxEnvelopeTempo.d.ts.map +1 -0
- package/_types/tempo/index.d.ts +300 -0
- package/_types/tempo/index.d.ts.map +1 -0
- package/_types/version.d.ts +1 -1
- package/core/Blobs.ts +8 -8
- package/core/{TransactionEnvelope.ts → TxEnvelope.ts} +10 -10
- package/core/{TransactionEnvelopeEip1559.ts → TxEnvelopeEip1559.ts} +60 -69
- package/core/{TransactionEnvelopeEip2930.ts → TxEnvelopeEip2930.ts} +61 -72
- package/core/{TransactionEnvelopeEip4844.ts → TxEnvelopeEip4844.ts} +62 -71
- package/core/{TransactionEnvelopeEip7702.ts → TxEnvelopeEip7702.ts} +58 -67
- package/core/{TransactionEnvelopeLegacy.ts → TxEnvelopeLegacy.ts} +59 -68
- package/core/WebAuthnP256.ts +3 -1
- package/erc8021/Attribution.ts +77 -15
- package/index.docs.ts +1 -0
- package/index.ts +192 -195
- package/package.json +91 -31
- package/tempo/AuthorizationTempo/package.json +6 -0
- package/tempo/AuthorizationTempo.test.ts +1293 -0
- package/tempo/AuthorizationTempo.ts +884 -0
- package/tempo/KeyAuthorization/package.json +6 -0
- package/tempo/KeyAuthorization.test.ts +1373 -0
- package/tempo/KeyAuthorization.ts +622 -0
- package/tempo/PoolId/package.json +6 -0
- package/tempo/PoolId.test.ts +33 -0
- package/tempo/PoolId.ts +42 -0
- package/tempo/SignatureEnvelope/package.json +6 -0
- package/tempo/SignatureEnvelope.test.ts +1877 -0
- package/tempo/SignatureEnvelope.ts +973 -0
- package/tempo/Tick/package.json +6 -0
- package/tempo/Tick.test.ts +281 -0
- package/tempo/Tick.ts +186 -0
- package/tempo/TokenId/package.json +6 -0
- package/tempo/TokenId.test.ts +40 -0
- package/tempo/TokenId.ts +80 -0
- package/tempo/TokenRole/package.json +6 -0
- package/tempo/TokenRole.test.ts +16 -0
- package/tempo/TokenRole.ts +45 -0
- package/tempo/Transaction/package.json +6 -0
- package/tempo/Transaction.test.ts +523 -0
- package/tempo/Transaction.ts +339 -0
- package/tempo/TransactionReceipt/package.json +6 -0
- package/tempo/TransactionReceipt.ts +200 -0
- package/tempo/TransactionRequest/package.json +6 -0
- package/tempo/TransactionRequest.ts +160 -0
- package/tempo/TxEnvelopeTempo/package.json +6 -0
- package/tempo/TxEnvelopeTempo.test.ts +1371 -0
- package/tempo/TxEnvelopeTempo.ts +972 -0
- package/tempo/e2e.test.ts +1387 -0
- package/tempo/index.ts +308 -0
- package/tempo/package.json +6 -0
- package/version.ts +1 -1
- package/TransactionEnvelope/package.json +0 -6
- package/TransactionEnvelopeEip1559/package.json +0 -6
- package/TransactionEnvelopeEip2930/package.json +0 -6
- package/TransactionEnvelopeEip4844/package.json +0 -6
- package/TransactionEnvelopeEip7702/package.json +0 -6
- package/TransactionEnvelopeLegacy/package.json +0 -6
- package/_cjs/core/TransactionEnvelope.js.map +0 -1
- package/_cjs/core/TransactionEnvelopeEip1559.js.map +0 -1
- package/_cjs/core/TransactionEnvelopeEip2930.js.map +0 -1
- package/_cjs/core/TransactionEnvelopeEip4844.js.map +0 -1
- package/_cjs/core/TransactionEnvelopeEip7702.js.map +0 -1
- package/_cjs/core/TransactionEnvelopeLegacy.js.map +0 -1
- package/_esm/core/TransactionEnvelope.js.map +0 -1
- package/_esm/core/TransactionEnvelopeEip1559.js.map +0 -1
- package/_esm/core/TransactionEnvelopeEip2930.js.map +0 -1
- package/_esm/core/TransactionEnvelopeEip4844.js.map +0 -1
- package/_esm/core/TransactionEnvelopeEip7702.js.map +0 -1
- package/_esm/core/TransactionEnvelopeLegacy.js.map +0 -1
- package/_types/core/TransactionEnvelope.d.ts.map +0 -1
- package/_types/core/TransactionEnvelopeEip1559.d.ts.map +0 -1
- package/_types/core/TransactionEnvelopeEip2930.d.ts.map +0 -1
- package/_types/core/TransactionEnvelopeEip4844.d.ts.map +0 -1
- package/_types/core/TransactionEnvelopeEip7702.d.ts.map +0 -1
- package/_types/core/TransactionEnvelopeLegacy.d.ts.map +0 -1
|
@@ -0,0 +1,438 @@
|
|
|
1
|
+
import type * as Address from '../core/Address.js';
|
|
2
|
+
import * as Errors from '../core/Errors.js';
|
|
3
|
+
import * as Hex from '../core/Hex.js';
|
|
4
|
+
import type { Assign, Compute, IsNarrowable, OneOf, PartialBy, UnionPartialBy } from '../core/internal/types.js';
|
|
5
|
+
import type * as PublicKey from '../core/PublicKey.js';
|
|
6
|
+
import * as Signature from '../core/Signature.js';
|
|
7
|
+
import type * as WebAuthnP256 from '../core/WebAuthnP256.js';
|
|
8
|
+
/**
|
|
9
|
+
* Statically determines the signature type of an envelope at compile time.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts twoslash
|
|
13
|
+
* import type { SignatureEnvelope } from 'ox/tempo'
|
|
14
|
+
*
|
|
15
|
+
* type Type = SignatureEnvelope.GetType<{ r: bigint; s: bigint; yParity: number }>
|
|
16
|
+
* // @log: 'secp256k1'
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export type GetType<envelope extends PartialBy<SignatureEnvelope, 'type'> | unknown> = unknown extends envelope ? envelope extends unknown ? Type : never : envelope extends {
|
|
20
|
+
type: infer T extends Type;
|
|
21
|
+
} ? T : envelope extends {
|
|
22
|
+
signature: {
|
|
23
|
+
r: bigint;
|
|
24
|
+
s: bigint;
|
|
25
|
+
};
|
|
26
|
+
prehash: boolean;
|
|
27
|
+
publicKey: PublicKey.PublicKey;
|
|
28
|
+
} ? 'p256' : envelope extends {
|
|
29
|
+
signature: {
|
|
30
|
+
r: bigint;
|
|
31
|
+
s: bigint;
|
|
32
|
+
};
|
|
33
|
+
metadata: any;
|
|
34
|
+
publicKey: PublicKey.PublicKey;
|
|
35
|
+
} ? 'webAuthn' : envelope extends {
|
|
36
|
+
r: bigint;
|
|
37
|
+
s: bigint;
|
|
38
|
+
yParity: number;
|
|
39
|
+
} ? 'secp256k1' : envelope extends {
|
|
40
|
+
signature: {
|
|
41
|
+
r: bigint;
|
|
42
|
+
s: bigint;
|
|
43
|
+
yParity: number;
|
|
44
|
+
};
|
|
45
|
+
} ? 'secp256k1' : envelope extends {
|
|
46
|
+
userAddress: Address.Address;
|
|
47
|
+
} ? 'keychain' : never;
|
|
48
|
+
/**
|
|
49
|
+
* Represents a signature envelope that can contain different signature types.
|
|
50
|
+
*
|
|
51
|
+
* Tempo transactions support multiple signature types, each with different wire formats:
|
|
52
|
+
*
|
|
53
|
+
* - **secp256k1** (no type prefix, 65 bytes): Standard Ethereum ECDSA signature. The sender
|
|
54
|
+
* address is recovered via `ecrecover`. Base transaction cost: 21,000 gas.
|
|
55
|
+
*
|
|
56
|
+
* - **p256** (type `0x01`, 130 bytes): P256/secp256r1 curve signature for passkey accounts.
|
|
57
|
+
* Includes embedded public key (64 bytes) and prehash flag. Enables native WebCrypto
|
|
58
|
+
* key support. Additional gas cost: +5,000 gas over secp256k1.
|
|
59
|
+
*
|
|
60
|
+
* - **webAuthn** (type `0x02`, 129-2049 bytes): WebAuthn signature with authenticator data
|
|
61
|
+
* and clientDataJSON. Enables browser passkey authentication. The signature is also
|
|
62
|
+
* charged as calldata (16 gas/non-zero byte, 4 gas/zero byte).
|
|
63
|
+
*
|
|
64
|
+
* - **keychain** (type `0x03`): Access key signature that wraps an inner signature (secp256k1,
|
|
65
|
+
* p256, or webAuthn). Format: `0x03` + user_address (20 bytes) + inner signature. The
|
|
66
|
+
* protocol validates the access key authorization via the AccountKeychain precompile.
|
|
67
|
+
*
|
|
68
|
+
* [Signature Types Specification](https://docs.tempo.xyz/protocol/transactions/spec-tempo-transaction#signature-types)
|
|
69
|
+
*/
|
|
70
|
+
export type SignatureEnvelope<bigintType = bigint, numberType = number> = OneOf<Secp256k1<bigintType, numberType> | P256<bigintType, numberType> | WebAuthn<bigintType, numberType> | Keychain<bigintType, numberType>>;
|
|
71
|
+
/**
|
|
72
|
+
* RPC-formatted signature envelope.
|
|
73
|
+
*/
|
|
74
|
+
export type SignatureEnvelopeRpc = OneOf<Secp256k1Rpc | P256Rpc | WebAuthnRpc | KeychainRpc>;
|
|
75
|
+
export type Keychain<bigintType = bigint, numberType = number> = {
|
|
76
|
+
/** Root account address that this transaction is being executed for */
|
|
77
|
+
userAddress: Address.Address;
|
|
78
|
+
/** The actual signature from the access key (can be Secp256k1, P256, or WebAuthn) */
|
|
79
|
+
inner: SignatureEnvelope<bigintType, numberType>;
|
|
80
|
+
type: 'keychain';
|
|
81
|
+
};
|
|
82
|
+
export type KeychainRpc = {
|
|
83
|
+
type: 'keychain';
|
|
84
|
+
userAddress: Address.Address;
|
|
85
|
+
signature: SignatureEnvelopeRpc;
|
|
86
|
+
};
|
|
87
|
+
export type P256<bigintType = bigint, numberType = number> = {
|
|
88
|
+
prehash: boolean;
|
|
89
|
+
publicKey: PublicKey.PublicKey;
|
|
90
|
+
signature: Signature.Signature<false, bigintType, numberType>;
|
|
91
|
+
type: 'p256';
|
|
92
|
+
};
|
|
93
|
+
export type P256Rpc = {
|
|
94
|
+
prehash: boolean;
|
|
95
|
+
pubKeyX: Hex.Hex;
|
|
96
|
+
pubKeyY: Hex.Hex;
|
|
97
|
+
r: Hex.Hex;
|
|
98
|
+
s: Hex.Hex;
|
|
99
|
+
type: 'p256';
|
|
100
|
+
};
|
|
101
|
+
export type Secp256k1<bigintType = bigint, numberType = number> = {
|
|
102
|
+
signature: Signature.Signature<true, bigintType, numberType>;
|
|
103
|
+
type: 'secp256k1';
|
|
104
|
+
};
|
|
105
|
+
export type Secp256k1Rpc = Compute<Signature.Rpc<true> & {
|
|
106
|
+
v?: Hex.Hex | undefined;
|
|
107
|
+
type: 'secp256k1';
|
|
108
|
+
}>;
|
|
109
|
+
export type Secp256k1Flat<bigintType = bigint, numberType = number> = Signature.Signature<true, bigintType, numberType> & {
|
|
110
|
+
type?: 'secp256k1' | undefined;
|
|
111
|
+
};
|
|
112
|
+
export type WebAuthn<bigintType = bigint, numberType = number> = {
|
|
113
|
+
metadata: Pick<WebAuthnP256.SignMetadata, 'authenticatorData' | 'clientDataJSON'>;
|
|
114
|
+
signature: Signature.Signature<false, bigintType, numberType>;
|
|
115
|
+
publicKey: PublicKey.PublicKey;
|
|
116
|
+
type: 'webAuthn';
|
|
117
|
+
};
|
|
118
|
+
export type WebAuthnRpc = {
|
|
119
|
+
pubKeyX: Hex.Hex;
|
|
120
|
+
pubKeyY: Hex.Hex;
|
|
121
|
+
r: Hex.Hex;
|
|
122
|
+
s: Hex.Hex;
|
|
123
|
+
type: 'webAuthn';
|
|
124
|
+
webauthnData: Hex.Hex;
|
|
125
|
+
};
|
|
126
|
+
/** Hex-encoded serialized signature envelope. */
|
|
127
|
+
export type Serialized = Hex.Hex;
|
|
128
|
+
/** List of supported signature types. */
|
|
129
|
+
export declare const types: readonly ["secp256k1", "p256", "webAuthn"];
|
|
130
|
+
/** Union type of supported signature types. */
|
|
131
|
+
export type Type = (typeof types)[number];
|
|
132
|
+
/**
|
|
133
|
+
* Asserts that a {@link ox#SignatureEnvelope.SignatureEnvelope} is valid.
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* ```ts twoslash
|
|
137
|
+
* import { SignatureEnvelope } from 'ox/tempo'
|
|
138
|
+
*
|
|
139
|
+
* SignatureEnvelope.assert({
|
|
140
|
+
* type: 'secp256k1',
|
|
141
|
+
* signature: {
|
|
142
|
+
* r: 0n,
|
|
143
|
+
* s: 0n,
|
|
144
|
+
* yParity: 0,
|
|
145
|
+
* },
|
|
146
|
+
* })
|
|
147
|
+
* ```
|
|
148
|
+
*
|
|
149
|
+
* @param envelope - The signature envelope to assert.
|
|
150
|
+
* @throws `CoercionError` if the envelope type cannot be determined.
|
|
151
|
+
*/
|
|
152
|
+
export declare function assert(envelope: PartialBy<SignatureEnvelope, 'type'>): void;
|
|
153
|
+
export declare namespace assert {
|
|
154
|
+
type ErrorType = CoercionError | MissingPropertiesError | Signature.assert.ErrorType | Errors.GlobalErrorType;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Deserializes a hex-encoded signature envelope into a typed signature object.
|
|
158
|
+
*
|
|
159
|
+
* Wire format detection:
|
|
160
|
+
* - 65 bytes (no prefix): secp256k1 signature
|
|
161
|
+
* - Type `0x01` + 129 bytes: P256 signature (r, s, pubKeyX, pubKeyY, prehash)
|
|
162
|
+
* - Type `0x02` + variable: WebAuthn signature (webauthnData, r, s, pubKeyX, pubKeyY)
|
|
163
|
+
* - Type `0x03` + 20 bytes + inner: Keychain signature (userAddress + inner signature)
|
|
164
|
+
*
|
|
165
|
+
* [Signature Types](https://docs.tempo.xyz/protocol/transactions/spec-tempo-transaction#signature-types)
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* ```ts twoslash
|
|
169
|
+
* import { SignatureEnvelope } from 'ox/tempo'
|
|
170
|
+
*
|
|
171
|
+
* const envelope = SignatureEnvelope.deserialize('0x...')
|
|
172
|
+
* ```
|
|
173
|
+
*
|
|
174
|
+
* @param serialized - The hex-encoded signature envelope to deserialize.
|
|
175
|
+
* @returns The deserialized signature envelope.
|
|
176
|
+
* @throws `CoercionError` if the serialized value cannot be coerced to a valid signature envelope.
|
|
177
|
+
*/
|
|
178
|
+
export declare function deserialize(serialized: Serialized): SignatureEnvelope;
|
|
179
|
+
/**
|
|
180
|
+
* Coerces a value to a signature envelope.
|
|
181
|
+
*
|
|
182
|
+
* Accepts either a serialized hex string or an existing signature envelope object.
|
|
183
|
+
* Use this to wrap raw signatures from {@link ox#Secp256k1.(sign:function)}, {@link ox#P256.(sign:function)},
|
|
184
|
+
* {@link ox#WebCryptoP256.(sign:function)}, or {@link ox#WebAuthnP256.(sign:function)} into the envelope format
|
|
185
|
+
* required by Tempo transactions.
|
|
186
|
+
*
|
|
187
|
+
* [Signature Types](https://docs.tempo.xyz/protocol/transactions/spec-tempo-transaction#signature-types)
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* ### Secp256k1
|
|
191
|
+
*
|
|
192
|
+
* Standard Ethereum ECDSA signature using the secp256k1 curve.
|
|
193
|
+
*
|
|
194
|
+
* ```ts twoslash
|
|
195
|
+
* import { Secp256k1 } from 'ox'
|
|
196
|
+
* import { SignatureEnvelope } from 'ox/tempo'
|
|
197
|
+
*
|
|
198
|
+
* const privateKey = Secp256k1.randomPrivateKey()
|
|
199
|
+
* const signature = Secp256k1.sign({ payload: '0xdeadbeef', privateKey })
|
|
200
|
+
*
|
|
201
|
+
* const envelope = SignatureEnvelope.from(signature)
|
|
202
|
+
* ```
|
|
203
|
+
*
|
|
204
|
+
* @example
|
|
205
|
+
* ### P256
|
|
206
|
+
*
|
|
207
|
+
* ECDSA signature using the P-256 (secp256r1) curve. Requires embedding the
|
|
208
|
+
* public key.
|
|
209
|
+
*
|
|
210
|
+
* ```ts twoslash
|
|
211
|
+
* import { P256 } from 'ox'
|
|
212
|
+
* import { SignatureEnvelope } from 'ox/tempo'
|
|
213
|
+
*
|
|
214
|
+
* const { privateKey, publicKey } = P256.createKeyPair()
|
|
215
|
+
* const signature = P256.sign({ payload: '0xdeadbeef', privateKey })
|
|
216
|
+
*
|
|
217
|
+
* const envelope = SignatureEnvelope.from({
|
|
218
|
+
* signature,
|
|
219
|
+
* publicKey,
|
|
220
|
+
* })
|
|
221
|
+
* ```
|
|
222
|
+
*
|
|
223
|
+
* @example
|
|
224
|
+
* ### P256 (WebCrypto)
|
|
225
|
+
*
|
|
226
|
+
* When using WebCrypto keys, `prehash` must be `true` since WebCrypto always
|
|
227
|
+
* SHA256 hashes the digest before signing.
|
|
228
|
+
*
|
|
229
|
+
* ```ts twoslash
|
|
230
|
+
* // @noErrors
|
|
231
|
+
* import { WebCryptoP256 } from 'ox'
|
|
232
|
+
* import { SignatureEnvelope } from 'ox/tempo'
|
|
233
|
+
*
|
|
234
|
+
* const { privateKey, publicKey } = await WebCryptoP256.createKeyPair()
|
|
235
|
+
* const signature = await WebCryptoP256.sign({ payload: '0xdeadbeef', privateKey })
|
|
236
|
+
*
|
|
237
|
+
* const envelope = SignatureEnvelope.from({
|
|
238
|
+
* signature,
|
|
239
|
+
* publicKey,
|
|
240
|
+
* prehash: true,
|
|
241
|
+
* })
|
|
242
|
+
* ```
|
|
243
|
+
*
|
|
244
|
+
* @example
|
|
245
|
+
* ### WebAuthn
|
|
246
|
+
*
|
|
247
|
+
* Passkey-based signature using WebAuthn. Includes authenticator metadata
|
|
248
|
+
* (authenticatorData and clientDataJSON) along with the P-256 signature and
|
|
249
|
+
* public key.
|
|
250
|
+
*
|
|
251
|
+
* ```ts twoslash
|
|
252
|
+
* // @noErrors
|
|
253
|
+
* import { WebAuthnP256 } from 'ox'
|
|
254
|
+
* import { SignatureEnvelope } from 'ox/tempo'
|
|
255
|
+
*
|
|
256
|
+
* const credential = await WebAuthnP256.createCredential({
|
|
257
|
+
* name: 'Example',
|
|
258
|
+
* })
|
|
259
|
+
*
|
|
260
|
+
* const { metadata, signature } = await WebAuthnP256.sign({
|
|
261
|
+
* challenge: '0xdeadbeef',
|
|
262
|
+
* credentialId: credential.id,
|
|
263
|
+
* })
|
|
264
|
+
*
|
|
265
|
+
* const envelope = SignatureEnvelope.from({
|
|
266
|
+
* signature,
|
|
267
|
+
* publicKey: credential.publicKey,
|
|
268
|
+
* metadata,
|
|
269
|
+
* })
|
|
270
|
+
* ```
|
|
271
|
+
*
|
|
272
|
+
* @example
|
|
273
|
+
* ### Keychain
|
|
274
|
+
*
|
|
275
|
+
* Wraps another signature type with a user address, used for delegated signing
|
|
276
|
+
* via access keys on behalf of a root account.
|
|
277
|
+
*
|
|
278
|
+
* ```ts twoslash
|
|
279
|
+
* import { Secp256k1 } from 'ox'
|
|
280
|
+
* import { SignatureEnvelope } from 'ox/tempo'
|
|
281
|
+
*
|
|
282
|
+
* const privateKey = Secp256k1.randomPrivateKey()
|
|
283
|
+
* const signature = Secp256k1.sign({ payload: '0xdeadbeef', privateKey })
|
|
284
|
+
*
|
|
285
|
+
* const envelope = SignatureEnvelope.from({
|
|
286
|
+
* userAddress: '0x1234567890123456789012345678901234567890',
|
|
287
|
+
* inner: SignatureEnvelope.from(signature),
|
|
288
|
+
* })
|
|
289
|
+
* ```
|
|
290
|
+
*
|
|
291
|
+
* @param value - The value to coerce (either a hex string or signature envelope).
|
|
292
|
+
* @returns The signature envelope.
|
|
293
|
+
*/
|
|
294
|
+
export declare function from<const value extends from.Value>(value: value | from.Value): from.ReturnValue<value>;
|
|
295
|
+
export declare namespace from {
|
|
296
|
+
type Value = UnionPartialBy<SignatureEnvelope, 'prehash' | 'type'> | Secp256k1Flat | Serialized;
|
|
297
|
+
type ReturnValue<value extends Value> = Compute<OneOf<value extends Serialized ? SignatureEnvelope : value extends Secp256k1Flat ? Secp256k1 : IsNarrowable<value, SignatureEnvelope> extends true ? SignatureEnvelope : Assign<value, {
|
|
298
|
+
readonly type: GetType<value>;
|
|
299
|
+
}>>>;
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Converts an RPC-formatted signature envelope to a typed signature envelope.
|
|
303
|
+
*
|
|
304
|
+
* @example
|
|
305
|
+
* ```ts twoslash
|
|
306
|
+
* import { SignatureEnvelope } from 'ox/tempo'
|
|
307
|
+
*
|
|
308
|
+
* const envelope = SignatureEnvelope.fromRpc({
|
|
309
|
+
* r: '0x0',
|
|
310
|
+
* s: '0x0',
|
|
311
|
+
* yParity: '0x0',
|
|
312
|
+
* type: 'secp256k1',
|
|
313
|
+
* })
|
|
314
|
+
* ```
|
|
315
|
+
*
|
|
316
|
+
* @param envelope - The RPC signature envelope to convert.
|
|
317
|
+
* @returns The signature envelope with bigint values.
|
|
318
|
+
*/
|
|
319
|
+
export declare function fromRpc(envelope: SignatureEnvelopeRpc): SignatureEnvelope;
|
|
320
|
+
export declare namespace fromRpc {
|
|
321
|
+
type ErrorType = CoercionError | InvalidSerializedError | Signature.fromRpc.ErrorType | Errors.GlobalErrorType;
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Determines the signature type of an envelope.
|
|
325
|
+
*
|
|
326
|
+
* @example
|
|
327
|
+
* ```ts twoslash
|
|
328
|
+
* import { SignatureEnvelope } from 'ox/tempo'
|
|
329
|
+
*
|
|
330
|
+
* const type = SignatureEnvelope.getType({
|
|
331
|
+
* signature: { r: 0n, s: 0n, yParity: 0 },
|
|
332
|
+
* })
|
|
333
|
+
* // @log: 'secp256k1'
|
|
334
|
+
* ```
|
|
335
|
+
*
|
|
336
|
+
* @param envelope - The signature envelope to inspect.
|
|
337
|
+
* @returns The signature type ('secp256k1', 'p256', or 'webAuthn').
|
|
338
|
+
* @throws `CoercionError` if the envelope type cannot be determined.
|
|
339
|
+
*/
|
|
340
|
+
export declare function getType<envelope extends PartialBy<SignatureEnvelope, 'type'> | Secp256k1Flat | unknown>(envelope: envelope): GetType<envelope>;
|
|
341
|
+
/**
|
|
342
|
+
* Serializes a signature envelope to a hex-encoded string.
|
|
343
|
+
*
|
|
344
|
+
* Wire format:
|
|
345
|
+
* - secp256k1: 65 bytes (no type prefix, for backward compatibility)
|
|
346
|
+
* - P256: `0x01` + r (32) + s (32) + pubKeyX (32) + pubKeyY (32) + prehash (1) = 130 bytes
|
|
347
|
+
* - WebAuthn: `0x02` + webauthnData (variable) + r (32) + s (32) + pubKeyX (32) + pubKeyY (32)
|
|
348
|
+
* - Keychain: `0x03` + userAddress (20) + inner signature (recursive)
|
|
349
|
+
*
|
|
350
|
+
* [Signature Types](https://docs.tempo.xyz/protocol/transactions/spec-tempo-transaction#signature-types)
|
|
351
|
+
*
|
|
352
|
+
* @example
|
|
353
|
+
* ```ts twoslash
|
|
354
|
+
* import { SignatureEnvelope } from 'ox/tempo'
|
|
355
|
+
*
|
|
356
|
+
* const serialized = SignatureEnvelope.serialize({
|
|
357
|
+
* signature: { r: 0n, s: 0n, yParity: 0 },
|
|
358
|
+
* type: 'secp256k1',
|
|
359
|
+
* })
|
|
360
|
+
* ```
|
|
361
|
+
*
|
|
362
|
+
* @param envelope - The signature envelope to serialize.
|
|
363
|
+
* @returns The hex-encoded serialized signature.
|
|
364
|
+
* @throws `CoercionError` if the envelope cannot be serialized.
|
|
365
|
+
*/
|
|
366
|
+
export declare function serialize(envelope: UnionPartialBy<SignatureEnvelope, 'prehash'>): Serialized;
|
|
367
|
+
/**
|
|
368
|
+
* Converts a signature envelope to RPC format.
|
|
369
|
+
*
|
|
370
|
+
* @example
|
|
371
|
+
* ```ts twoslash
|
|
372
|
+
* import { SignatureEnvelope } from 'ox/tempo'
|
|
373
|
+
*
|
|
374
|
+
* const rpc = SignatureEnvelope.toRpc({
|
|
375
|
+
* signature: { r: 0n, s: 0n, yParity: 0 },
|
|
376
|
+
* type: 'secp256k1',
|
|
377
|
+
* })
|
|
378
|
+
* ```
|
|
379
|
+
*
|
|
380
|
+
* @param envelope - The signature envelope to convert.
|
|
381
|
+
* @returns The RPC signature envelope with hex values.
|
|
382
|
+
*/
|
|
383
|
+
export declare function toRpc(envelope: SignatureEnvelope): SignatureEnvelopeRpc;
|
|
384
|
+
export declare namespace toRpc {
|
|
385
|
+
type ErrorType = CoercionError | Signature.toRpc.ErrorType | Errors.GlobalErrorType;
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* Validates a signature envelope. Returns `true` if the envelope is valid, `false` otherwise.
|
|
389
|
+
*
|
|
390
|
+
* @example
|
|
391
|
+
* ```ts twoslash
|
|
392
|
+
* import { SignatureEnvelope } from 'ox/tempo'
|
|
393
|
+
*
|
|
394
|
+
* const valid = SignatureEnvelope.validate({
|
|
395
|
+
* signature: { r: 0n, s: 0n, yParity: 0 },
|
|
396
|
+
* type: 'secp256k1',
|
|
397
|
+
* })
|
|
398
|
+
* // @log: true
|
|
399
|
+
* ```
|
|
400
|
+
*
|
|
401
|
+
* @param envelope - The signature envelope to validate.
|
|
402
|
+
* @returns `true` if valid, `false` otherwise.
|
|
403
|
+
*/
|
|
404
|
+
export declare function validate(envelope: PartialBy<SignatureEnvelope, 'type'>): boolean;
|
|
405
|
+
export declare namespace validate {
|
|
406
|
+
type ErrorType = Errors.GlobalErrorType;
|
|
407
|
+
}
|
|
408
|
+
/**
|
|
409
|
+
* Error thrown when a signature envelope cannot be coerced to a valid type.
|
|
410
|
+
*/
|
|
411
|
+
export declare class CoercionError extends Errors.BaseError {
|
|
412
|
+
readonly name = "SignatureEnvelope.CoercionError";
|
|
413
|
+
constructor({ envelope }: {
|
|
414
|
+
envelope: unknown;
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* Error thrown when a signature envelope is missing required properties.
|
|
419
|
+
*/
|
|
420
|
+
export declare class MissingPropertiesError extends Errors.BaseError {
|
|
421
|
+
readonly name = "SignatureEnvelope.MissingPropertiesError";
|
|
422
|
+
constructor({ envelope, missing, type, }: {
|
|
423
|
+
envelope: unknown;
|
|
424
|
+
missing: string[];
|
|
425
|
+
type: Type;
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* Error thrown when a serialized signature envelope cannot be deserialized.
|
|
430
|
+
*/
|
|
431
|
+
export declare class InvalidSerializedError extends Errors.BaseError {
|
|
432
|
+
readonly name = "SignatureEnvelope.InvalidSerializedError";
|
|
433
|
+
constructor({ reason, serialized, }: {
|
|
434
|
+
reason: string;
|
|
435
|
+
serialized: Hex.Hex;
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
//# sourceMappingURL=SignatureEnvelope.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SignatureEnvelope.d.ts","sourceRoot":"","sources":["../../tempo/SignatureEnvelope.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,OAAO,MAAM,oBAAoB,CAAA;AAClD,OAAO,KAAK,MAAM,MAAM,mBAAmB,CAAA;AAC3C,OAAO,KAAK,GAAG,MAAM,gBAAgB,CAAA;AACrC,OAAO,KAAK,EACV,MAAM,EACN,OAAO,EACP,YAAY,EACZ,KAAK,EACL,SAAS,EACT,cAAc,EACf,MAA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,MAAM,CAAC,OAAO,WAAW,QAAQ,CAAC;IAChC,KAAK,SAAS,GAAG,MAAM,CAAC,eAAe,CAAA;CACxC;AAED;;GAEG;AACH,qBAAa,aAAc,SAAQ,MAAM,CAAC,SAAS;IACjD,SAAkB,IAAI,qCAAoC;gBAC9C,EAAE,QAAQ,EAAE,EAAE;QAAE,QAAQ,EAAE,OAAO,CAAA;KAAE;CAKhD;AAED;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,MAAM,CAAC,SAAS;IAC1D,SAAkB,IAAI,8CAA6C;gBACvD,EACV,QAAQ,EACR,OAAO,EACP,IAAI,GACL,EAAE;QACD,QAAQ,EAAE,OAAO,CAAA;QACjB,OAAO,EAAE,MAAM,EAAE,CAAA;QACjB,IAAI,EAAE,IAAI,CAAA;KACX;CAKF;AAED;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,MAAM,CAAC,SAAS;IAC1D,SAAkB,IAAI,8CAA6C;gBACvD,EACV,MAAM,EACN,UAAU,GACX,EAAE;QACD,MAAM,EAAE,MAAM,CAAA;QACd,UAAU,EAAE,GAAG,CAAC,GAAG,CAAA;KACpB;CAKF"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import * as Errors from '../core/Errors.js';
|
|
2
|
+
/**
|
|
3
|
+
* Minimum allowed tick value (-2% from peg).
|
|
4
|
+
*
|
|
5
|
+
* [Stablecoin DEX Pricing](https://docs.tempo.xyz/protocol/exchange/spec#key-concepts)
|
|
6
|
+
*/
|
|
7
|
+
export declare const minTick = -2000;
|
|
8
|
+
/**
|
|
9
|
+
* Maximum allowed tick value (+2% from peg).
|
|
10
|
+
*
|
|
11
|
+
* [Stablecoin DEX Pricing](https://docs.tempo.xyz/protocol/exchange/spec#key-concepts)
|
|
12
|
+
*/
|
|
13
|
+
export declare const maxTick = 2000;
|
|
14
|
+
/**
|
|
15
|
+
* Price scaling factor (5 decimal places for 0.1 bps precision).
|
|
16
|
+
*
|
|
17
|
+
* The DEX uses a tick-based pricing system where `price = PRICE_SCALE + tick`.
|
|
18
|
+
* Orders must be placed at ticks divisible by `TICK_SPACING = 10` (1 bp grid).
|
|
19
|
+
*
|
|
20
|
+
* [Stablecoin DEX Pricing](https://docs.tempo.xyz/protocol/exchange/spec#key-concepts)
|
|
21
|
+
*/
|
|
22
|
+
export declare const priceScale = 100000;
|
|
23
|
+
/**
|
|
24
|
+
* Tick type.
|
|
25
|
+
*/
|
|
26
|
+
export type Tick = number;
|
|
27
|
+
/**
|
|
28
|
+
* Converts a tick to a price string.
|
|
29
|
+
*
|
|
30
|
+
* [Stablecoin DEX Pricing](https://docs.tempo.xyz/protocol/exchange/spec#key-concepts)
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* import { Tick } from 'ox/tempo'
|
|
35
|
+
*
|
|
36
|
+
* // Tick 0 = price of 1.0
|
|
37
|
+
* const price1 = Tick.toPrice(0) // "1"
|
|
38
|
+
*
|
|
39
|
+
* // Tick 100 = price of 1.001 (0.1% higher)
|
|
40
|
+
* const price2 = Tick.toPrice(100) // "1.001"
|
|
41
|
+
*
|
|
42
|
+
* // Tick -100 = price of 0.999 (0.1% lower)
|
|
43
|
+
* const price3 = Tick.toPrice(-100) // "0.999"
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* @param tick - The tick value (range: -2000 to +2000).
|
|
47
|
+
* @returns The price as a string with exact decimal representation.
|
|
48
|
+
* @throws `TickOutOfBoundsError` If tick is out of bounds.
|
|
49
|
+
*/
|
|
50
|
+
export declare function toPrice(tick: toPrice.Tick): toPrice.ReturnType;
|
|
51
|
+
export declare namespace toPrice {
|
|
52
|
+
type Tick = number;
|
|
53
|
+
type ReturnType = string;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Converts a price string to a tick.
|
|
57
|
+
*
|
|
58
|
+
* [Stablecoin DEX Pricing](https://docs.tempo.xyz/protocol/exchange/spec#key-concepts)
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* import { Tick } from 'ox/tempo'
|
|
63
|
+
*
|
|
64
|
+
* // Price of 1.0 = tick 0
|
|
65
|
+
* const tick1 = Tick.fromPrice('1.0') // 0
|
|
66
|
+
* const tick2 = Tick.fromPrice('1.00000') // 0
|
|
67
|
+
*
|
|
68
|
+
* // Price of 1.001 = tick 100
|
|
69
|
+
* const tick3 = Tick.fromPrice('1.001') // 100
|
|
70
|
+
*
|
|
71
|
+
* // Price of 0.999 = tick -100
|
|
72
|
+
* const tick4 = Tick.fromPrice('0.999') // -100
|
|
73
|
+
* ```
|
|
74
|
+
*
|
|
75
|
+
* @param price - The price as a string (e.g., "1.001", "0.999").
|
|
76
|
+
* @returns The tick value.
|
|
77
|
+
*/
|
|
78
|
+
export declare function fromPrice(price: fromPrice.Price): fromPrice.ReturnType;
|
|
79
|
+
export declare namespace fromPrice {
|
|
80
|
+
type Price = string;
|
|
81
|
+
type ReturnType = number;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Error thrown when a tick value is out of the allowed bounds.
|
|
85
|
+
*/
|
|
86
|
+
export declare class TickOutOfBoundsError extends Errors.BaseError {
|
|
87
|
+
readonly name = "Tick.TickOutOfBoundsError";
|
|
88
|
+
constructor(options: TickOutOfBoundsError.Options);
|
|
89
|
+
}
|
|
90
|
+
export declare namespace TickOutOfBoundsError {
|
|
91
|
+
type Options = {
|
|
92
|
+
tick: number;
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Error thrown when a price string has an invalid format.
|
|
97
|
+
*/
|
|
98
|
+
export declare class InvalidPriceFormatError extends Errors.BaseError {
|
|
99
|
+
readonly name = "Tick.InvalidPriceFormatError";
|
|
100
|
+
constructor(options: InvalidPriceFormatError.Options);
|
|
101
|
+
}
|
|
102
|
+
export declare namespace InvalidPriceFormatError {
|
|
103
|
+
type Options = {
|
|
104
|
+
price: string;
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Error thrown when a price string results in an out-of-bounds tick.
|
|
109
|
+
*/
|
|
110
|
+
export declare class PriceOutOfBoundsError extends Errors.BaseError {
|
|
111
|
+
readonly name = "Tick.PriceOutOfBoundsError";
|
|
112
|
+
constructor(options: PriceOutOfBoundsError.Options);
|
|
113
|
+
}
|
|
114
|
+
export declare namespace PriceOutOfBoundsError {
|
|
115
|
+
type Options = {
|
|
116
|
+
price: string;
|
|
117
|
+
tick: number;
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingURL=Tick.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Tick.d.ts","sourceRoot":"","sources":["../../tempo/Tick.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,mBAAmB,CAAA;AAE3C;;;;GAIG;AACH,eAAO,MAAM,OAAO,QAAQ,CAAA;AAE5B;;;;GAIG;AACH,eAAO,MAAM,OAAO,OAAO,CAAA;AAE3B;;;;;;;GAOG;AACH,eAAO,MAAM,UAAU,SAAU,CAAA;AAEjC;;GAEG;AACH,MAAM,MAAM,IAAI,GAAG,MAAM,CAAA;AAEzB;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,GAAG,OAAO,CAAC,UAAU,CAa9D;AAED,MAAM,CAAC,OAAO,WAAW,OAAO,CAAC;IAC/B,KAAY,IAAI,GAAG,MAAM,CAAA;IACzB,KAAY,UAAU,GAAG,MAAM,CAAA;CAChC;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,SAAS,CAAC,KAAK,GAAG,SAAS,CAAC,UAAU,CAsBtE;AAED,MAAM,CAAC,OAAO,WAAW,SAAS,CAAC;IACjC,KAAY,KAAK,GAAG,MAAM,CAAA;IAC1B,KAAY,UAAU,GAAG,MAAM,CAAA;CAChC;AAED;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,MAAM,CAAC,SAAS;IACxD,SAAkB,IAAI,+BAA8B;gBAExC,OAAO,EAAE,oBAAoB,CAAC,OAAO;CAKlD;AAED,MAAM,CAAC,OAAO,WAAW,oBAAoB,CAAC;IAC5C,KAAY,OAAO,GAAG;QACpB,IAAI,EAAE,MAAM,CAAA;KACb,CAAA;CACF;AAED;;GAEG;AACH,qBAAa,uBAAwB,SAAQ,MAAM,CAAC,SAAS;IAC3D,SAAkB,IAAI,kCAAiC;gBAE3C,OAAO,EAAE,uBAAuB,CAAC,OAAO;CAKrD;AAED,MAAM,CAAC,OAAO,WAAW,uBAAuB,CAAC;IAC/C,KAAY,OAAO,GAAG;QACpB,KAAK,EAAE,MAAM,CAAA;KACd,CAAA;CACF;AAED;;GAEG;AACH,qBAAa,qBAAsB,SAAQ,MAAM,CAAC,SAAS;IACzD,SAAkB,IAAI,gCAA+B;gBAEzC,OAAO,EAAE,qBAAqB,CAAC,OAAO;CAQnD;AAED,MAAM,CAAC,OAAO,WAAW,qBAAqB,CAAC;IAC7C,KAAY,OAAO,GAAG;QACpB,KAAK,EAAE,MAAM,CAAA;QACb,IAAI,EAAE,MAAM,CAAA;KACb,CAAA;CACF"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import * as Address from '../core/Address.js';
|
|
2
|
+
export type TokenId = bigint;
|
|
3
|
+
export type TokenIdOrAddress = TokenId | Address.Address;
|
|
4
|
+
/**
|
|
5
|
+
* Converts a token ID or address to a token ID.
|
|
6
|
+
*
|
|
7
|
+
* TIP-20 is Tempo's native token standard for stablecoins with deterministic addresses
|
|
8
|
+
* derived from sequential token IDs (prefix `0x20c0`).
|
|
9
|
+
*
|
|
10
|
+
* [TIP-20 Token Standard](https://docs.tempo.xyz/protocol/tip20/overview)
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts twoslash
|
|
14
|
+
* import { TokenId } from 'ox/tempo'
|
|
15
|
+
*
|
|
16
|
+
* const tokenId = TokenId.from(1n)
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @param tokenIdOrAddress - The token ID or address.
|
|
20
|
+
* @returns The token ID.
|
|
21
|
+
*/
|
|
22
|
+
export declare function from(tokenIdOrAddress: TokenIdOrAddress | number): TokenId;
|
|
23
|
+
/**
|
|
24
|
+
* Converts a TIP-20 token address to a token ID.
|
|
25
|
+
*
|
|
26
|
+
* [TIP-20 Token Standard](https://docs.tempo.xyz/protocol/tip20/overview)
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts twoslash
|
|
30
|
+
* import { TokenId } from 'ox/tempo'
|
|
31
|
+
*
|
|
32
|
+
* const tokenId = TokenId.fromAddress('0x20c00000000000000000000000000000000000000001')
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @param address - The token address.
|
|
36
|
+
* @returns The token ID.
|
|
37
|
+
*/
|
|
38
|
+
export declare function fromAddress(address: Address.Address): TokenId;
|
|
39
|
+
/**
|
|
40
|
+
* Converts a TIP-20 token ID to an address.
|
|
41
|
+
*
|
|
42
|
+
* [TIP-20 Token Standard](https://docs.tempo.xyz/protocol/tip20/overview)
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts twoslash
|
|
46
|
+
* import { TokenId } from 'ox/tempo'
|
|
47
|
+
*
|
|
48
|
+
* const address = TokenId.toAddress(1n)
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* @param tokenId - The token ID.
|
|
52
|
+
* @returns The address.
|
|
53
|
+
*/
|
|
54
|
+
export declare function toAddress(tokenId: TokenIdOrAddress): Address.Address;
|
|
55
|
+
//# sourceMappingURL=TokenId.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TokenId.d.ts","sourceRoot":"","sources":["../../tempo/TokenId.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,oBAAoB,CAAA;AAK7C,MAAM,MAAM,OAAO,GAAG,MAAM,CAAA;AAC5B,MAAM,MAAM,gBAAgB,GAAG,OAAO,GAAG,OAAO,CAAC,OAAO,CAAA;AAExD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,IAAI,CAAC,gBAAgB,EAAE,gBAAgB,GAAG,MAAM,GAAG,OAAO,CAOzE;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,GAAG,OAAO,CAI7D;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAQpE"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export declare const roles: readonly ["defaultAdmin", "pause", "unpause", "issuer", "burnBlocked"];
|
|
2
|
+
export type TokenRole = (typeof roles)[number];
|
|
3
|
+
export declare const toPreHashed: {
|
|
4
|
+
readonly defaultAdmin: "DEFAULT_ADMIN_ROLE";
|
|
5
|
+
readonly pause: "PAUSE_ROLE";
|
|
6
|
+
readonly unpause: "UNPAUSE_ROLE";
|
|
7
|
+
readonly issuer: "ISSUER_ROLE";
|
|
8
|
+
readonly burnBlocked: "BURN_BLOCKED_ROLE";
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Serializes a token role to its keccak256 hash representation.
|
|
12
|
+
*
|
|
13
|
+
* TIP-20 includes a built-in RBAC system with roles like `ISSUER_ROLE` (mint/burn),
|
|
14
|
+
* `PAUSE_ROLE`/`UNPAUSE_ROLE` (emergency controls), and `BURN_BLOCKED_ROLE` (compliance).
|
|
15
|
+
*
|
|
16
|
+
* [TIP-20 RBAC](https://docs.tempo.xyz/protocol/tip20/overview#role-based-access-control-rbac)
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts twoslash
|
|
20
|
+
* import { TokenRole } from 'ox/tempo'
|
|
21
|
+
*
|
|
22
|
+
* const hash = TokenRole.serialize('issuer')
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @param role - The token role to serialize.
|
|
26
|
+
* @returns The keccak256 hash of the role.
|
|
27
|
+
*/
|
|
28
|
+
export declare function serialize(role: TokenRole): `0x${string}`;
|
|
29
|
+
//# sourceMappingURL=TokenRole.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TokenRole.d.ts","sourceRoot":"","sources":["../../tempo/TokenRole.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,KAAK,wEAMR,CAAA;AACV,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,KAAK,CAAC,CAAC,MAAM,CAAC,CAAA;AAE9C,eAAO,MAAM,WAAW;;;;;;CAMsB,CAAA;AAE9C;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,SAAS,iBAMxC"}
|