tempo.ts 0.10.5 → 0.11.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 +30 -0
- package/README.md +0 -41
- package/dist/viem/Account.d.ts +8 -3
- package/dist/viem/Account.d.ts.map +1 -1
- package/dist/viem/Account.js +9 -2
- package/dist/viem/Account.js.map +1 -1
- package/dist/viem/Actions/amm.d.ts +1 -1
- package/dist/viem/Actions/amm.d.ts.map +1 -1
- package/dist/viem/Actions/amm.js +1 -2
- package/dist/viem/Actions/amm.js.map +1 -1
- package/dist/viem/Actions/dex.d.ts +0 -35
- package/dist/viem/Actions/dex.d.ts.map +1 -1
- package/dist/viem/Actions/dex.js +0 -43
- package/dist/viem/Actions/dex.js.map +1 -1
- package/dist/viem/Actions/fee.d.ts +1 -1
- package/dist/viem/Actions/fee.d.ts.map +1 -1
- package/dist/viem/Actions/fee.js +1 -1
- package/dist/viem/Actions/fee.js.map +1 -1
- package/dist/viem/Actions/nonce.d.ts.map +1 -1
- package/dist/viem/Actions/nonce.js +6 -4
- package/dist/viem/Actions/nonce.js.map +1 -1
- package/dist/viem/Actions/token.d.ts +1 -2
- package/dist/viem/Actions/token.d.ts.map +1 -1
- package/dist/viem/Actions/token.js +1 -2
- package/dist/viem/Actions/token.js.map +1 -1
- package/dist/viem/Chain.d.ts +34 -34
- package/dist/viem/Chain.d.ts.map +1 -1
- package/dist/viem/Chain.js +2 -0
- package/dist/viem/Chain.js.map +1 -1
- package/dist/viem/Formatters.d.ts.map +1 -1
- package/dist/viem/Formatters.js +5 -3
- package/dist/viem/Formatters.js.map +1 -1
- package/dist/viem/Transaction.d.ts +8 -5
- package/dist/viem/Transaction.d.ts.map +1 -1
- package/dist/viem/Transaction.js +13 -3
- package/dist/viem/Transaction.js.map +1 -1
- package/dist/viem/internal/types.d.ts +1 -1
- package/dist/viem/internal/types.d.ts.map +1 -1
- package/dist/wagmi/Actions/dex.d.ts +1 -45
- package/dist/wagmi/Actions/dex.d.ts.map +1 -1
- package/dist/wagmi/Actions/dex.js +0 -55
- package/dist/wagmi/Actions/dex.js.map +1 -1
- package/dist/wagmi/Connector.d.ts +1 -1
- package/dist/wagmi/Connector.d.ts.map +1 -1
- package/dist/wagmi/Connector.js +1 -2
- package/dist/wagmi/Connector.js.map +1 -1
- package/dist/wagmi/Hooks/dex.d.ts +3 -46
- package/dist/wagmi/Hooks/dex.d.ts.map +1 -1
- package/dist/wagmi/Hooks/dex.js +2 -54
- package/dist/wagmi/Hooks/dex.js.map +1 -1
- package/dist/wagmi/index.d.ts +1 -1
- package/dist/wagmi/index.d.ts.map +1 -1
- package/dist/wagmi/index.js +1 -1
- package/dist/wagmi/index.js.map +1 -1
- package/package.json +5 -23
- package/src/viem/Account.test.ts +1 -1
- package/src/viem/Account.ts +11 -2
- package/src/viem/Actions/account.ts +1 -1
- package/src/viem/Actions/amm.ts +1 -2
- package/src/viem/Actions/dex.test.ts +1 -195
- package/src/viem/Actions/dex.ts +0 -53
- package/src/viem/Actions/fee.test.ts +2 -2
- package/src/viem/Actions/fee.ts +1 -1
- package/src/viem/Actions/nonce.test.ts +27 -14
- package/src/viem/Actions/nonce.ts +6 -4
- package/src/viem/Actions/token.test.ts +18 -52
- package/src/viem/Actions/token.ts +1 -2
- package/src/viem/Chain.ts +3 -1
- package/src/viem/Decorator.ts +0 -30
- package/src/viem/Formatters.ts +9 -3
- package/src/viem/Transaction.ts +23 -7
- package/src/viem/e2e.test.ts +19 -0
- package/src/viem/index.ts +12 -1
- package/src/viem/internal/types.ts +1 -1
- package/src/wagmi/Actions/dex.test.ts +0 -26
- package/src/wagmi/Actions/dex.ts +1 -111
- package/src/wagmi/Actions/nonce.test.ts +8 -4
- package/src/wagmi/Actions/token.test.ts +2 -2
- package/src/wagmi/Connector.ts +1 -2
- package/src/wagmi/Hooks/dex.test.ts +0 -26
- package/src/wagmi/Hooks/dex.ts +1 -88
- package/src/wagmi/Hooks/nonce.test.ts +3 -3
- package/src/wagmi/index.ts +4 -1
- package/dist/chains.d.ts +0 -73
- package/dist/chains.d.ts.map +0 -1
- package/dist/chains.js +0 -51
- package/dist/chains.js.map +0 -1
- package/dist/ox/AuthorizationTempo.d.ts +0 -450
- package/dist/ox/AuthorizationTempo.d.ts.map +0 -1
- package/dist/ox/AuthorizationTempo.js +0 -433
- package/dist/ox/AuthorizationTempo.js.map +0 -1
- package/dist/ox/KeyAuthorization.d.ts +0 -356
- package/dist/ox/KeyAuthorization.d.ts.map +0 -1
- package/dist/ox/KeyAuthorization.js +0 -359
- package/dist/ox/KeyAuthorization.js.map +0 -1
- package/dist/ox/Order.d.ts +0 -92
- package/dist/ox/Order.d.ts.map +0 -1
- package/dist/ox/Order.js +0 -88
- package/dist/ox/Order.js.map +0 -1
- package/dist/ox/OrdersFilters.d.ts +0 -72
- package/dist/ox/OrdersFilters.d.ts.map +0 -1
- package/dist/ox/OrdersFilters.js +0 -100
- package/dist/ox/OrdersFilters.js.map +0 -1
- package/dist/ox/Pagination.d.ts +0 -128
- package/dist/ox/Pagination.d.ts.map +0 -1
- package/dist/ox/Pagination.js +0 -78
- package/dist/ox/Pagination.js.map +0 -1
- package/dist/ox/PoolId.d.ts +0 -18
- package/dist/ox/PoolId.d.ts.map +0 -1
- package/dist/ox/PoolId.js +0 -13
- package/dist/ox/PoolId.js.map +0 -1
- package/dist/ox/RpcSchema.d.ts +0 -32
- package/dist/ox/RpcSchema.d.ts.map +0 -1
- package/dist/ox/RpcSchema.js +0 -2
- package/dist/ox/RpcSchema.js.map +0 -1
- package/dist/ox/SignatureEnvelope.d.ts +0 -260
- package/dist/ox/SignatureEnvelope.d.ts.map +0 -1
- package/dist/ox/SignatureEnvelope.js +0 -477
- package/dist/ox/SignatureEnvelope.js.map +0 -1
- package/dist/ox/Tick.d.ts +0 -115
- package/dist/ox/Tick.d.ts.map +0 -1
- package/dist/ox/Tick.js +0 -127
- package/dist/ox/Tick.js.map +0 -1
- package/dist/ox/TokenId.d.ts +0 -25
- package/dist/ox/TokenId.d.ts.map +0 -1
- package/dist/ox/TokenId.js +0 -41
- package/dist/ox/TokenId.js.map +0 -1
- package/dist/ox/TokenRole.d.ts +0 -11
- package/dist/ox/TokenRole.d.ts.map +0 -1
- package/dist/ox/TokenRole.js +0 -22
- package/dist/ox/TokenRole.js.map +0 -1
- package/dist/ox/Transaction.d.ts +0 -201
- package/dist/ox/Transaction.d.ts.map +0 -1
- package/dist/ox/Transaction.js +0 -167
- package/dist/ox/Transaction.js.map +0 -1
- package/dist/ox/TransactionEnvelopeTempo.d.ts +0 -470
- package/dist/ox/TransactionEnvelopeTempo.d.ts.map +0 -1
- package/dist/ox/TransactionEnvelopeTempo.js +0 -547
- package/dist/ox/TransactionEnvelopeTempo.js.map +0 -1
- package/dist/ox/TransactionReceipt.d.ts +0 -155
- package/dist/ox/TransactionReceipt.d.ts.map +0 -1
- package/dist/ox/TransactionReceipt.js +0 -136
- package/dist/ox/TransactionReceipt.js.map +0 -1
- package/dist/ox/TransactionRequest.d.ts +0 -76
- package/dist/ox/TransactionRequest.d.ts.map +0 -1
- package/dist/ox/TransactionRequest.js +0 -93
- package/dist/ox/TransactionRequest.js.map +0 -1
- package/dist/ox/index.d.ts +0 -14
- package/dist/ox/index.d.ts.map +0 -1
- package/dist/ox/index.js +0 -14
- package/dist/ox/index.js.map +0 -1
- package/dist/prool/Instance.d.ts +0 -101
- package/dist/prool/Instance.d.ts.map +0 -1
- package/dist/prool/Instance.js +0 -136
- package/dist/prool/Instance.js.map +0 -1
- package/dist/prool/chain.json +0 -238
- package/dist/prool/index.d.ts +0 -2
- package/dist/prool/index.d.ts.map +0 -1
- package/dist/prool/index.js +0 -2
- package/dist/prool/index.js.map +0 -1
- package/dist/viem/Actions/account.d.ts +0 -40
- package/dist/viem/Actions/account.d.ts.map +0 -1
- package/dist/viem/Actions/account.js +0 -86
- package/dist/viem/Actions/account.js.map +0 -1
- package/dist/viem/Actions/index.d.ts +0 -10
- package/dist/viem/Actions/index.d.ts.map +0 -1
- package/dist/viem/Actions/index.js +0 -10
- package/dist/viem/Actions/index.js.map +0 -1
- package/dist/viem/Decorator.d.ts +0 -2810
- package/dist/viem/Decorator.d.ts.map +0 -1
- package/dist/viem/Decorator.js +0 -138
- package/dist/viem/Decorator.js.map +0 -1
- package/dist/viem/P256.d.ts +0 -2
- package/dist/viem/P256.d.ts.map +0 -1
- package/dist/viem/P256.js +0 -2
- package/dist/viem/P256.js.map +0 -1
- package/dist/viem/Secp256k1.d.ts +0 -2
- package/dist/viem/Secp256k1.d.ts.map +0 -1
- package/dist/viem/Secp256k1.js +0 -2
- package/dist/viem/Secp256k1.js.map +0 -1
- package/dist/viem/TokenIds.d.ts +0 -2
- package/dist/viem/TokenIds.d.ts.map +0 -1
- package/dist/viem/TokenIds.js +0 -2
- package/dist/viem/TokenIds.js.map +0 -1
- package/dist/viem/index.d.ts +0 -17
- package/dist/viem/index.d.ts.map +0 -1
- package/dist/viem/index.js +0 -17
- package/dist/viem/index.js.map +0 -1
- package/src/ox/AuthorizationTempo.test.ts +0 -1256
- package/src/ox/AuthorizationTempo.ts +0 -648
- package/src/ox/KeyAuthorization.test.ts +0 -1332
- package/src/ox/KeyAuthorization.ts +0 -540
- package/src/ox/Order.test.ts +0 -78
- package/src/ox/Order.ts +0 -125
- package/src/ox/OrdersFilters.test.ts +0 -182
- package/src/ox/OrdersFilters.ts +0 -125
- package/src/ox/Pagination.test.ts +0 -162
- package/src/ox/Pagination.ts +0 -164
- package/src/ox/PoolId.test.ts +0 -33
- package/src/ox/PoolId.ts +0 -27
- package/src/ox/RpcSchema.ts +0 -35
- package/src/ox/SignatureEnvelope.test.ts +0 -1876
- package/src/ox/SignatureEnvelope.ts +0 -791
- package/src/ox/Tick.test.ts +0 -281
- package/src/ox/Tick.ts +0 -181
- package/src/ox/TokenId.test.ts +0 -40
- package/src/ox/TokenId.ts +0 -50
- package/src/ox/TokenRole.test.ts +0 -16
- package/src/ox/TokenRole.ts +0 -27
- package/src/ox/Transaction.test.ts +0 -523
- package/src/ox/Transaction.ts +0 -332
- package/src/ox/TransactionEnvelopeTempo.test.ts +0 -1352
- package/src/ox/TransactionEnvelopeTempo.ts +0 -905
- package/src/ox/TransactionReceipt.ts +0 -190
- package/src/ox/TransactionRequest.ts +0 -147
- package/src/ox/e2e.test.ts +0 -1393
- package/src/ox/index.ts +0 -13
- package/src/prool/Instance.test.ts +0 -43
- package/src/prool/Instance.ts +0 -247
- package/src/prool/chain.json +0 -238
- package/src/prool/index.ts +0 -1
- package/src/viem/Actions/__snapshots__/dex.test.ts.snap +0 -850
- package/src/wagmi/Actions/__snapshots__/dex.test.ts.snap +0 -310
- package/src/wagmi/Hooks/__snapshots__/dex.test.ts.snap +0 -457
|
@@ -1,540 +0,0 @@
|
|
|
1
|
-
import type * as Address from 'ox/Address'
|
|
2
|
-
import type * as Errors from 'ox/Errors'
|
|
3
|
-
import * as Hash from 'ox/Hash'
|
|
4
|
-
import * as Hex from 'ox/Hex'
|
|
5
|
-
import * as Rlp from 'ox/Rlp'
|
|
6
|
-
import type { Compute } from '../internal/types.js'
|
|
7
|
-
import * as SignatureEnvelope from './SignatureEnvelope.js'
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Key authorization for provisioning access keys.
|
|
11
|
-
*
|
|
12
|
-
* Used in TransactionEnvelopeTempo to add a new key to the keychain precompile.
|
|
13
|
-
* The transaction must be signed by the root key to authorize adding this access key.
|
|
14
|
-
*/
|
|
15
|
-
export type KeyAuthorization<
|
|
16
|
-
signed extends boolean = boolean,
|
|
17
|
-
bigintType = bigint,
|
|
18
|
-
numberType = number,
|
|
19
|
-
> = {
|
|
20
|
-
/** Address derived from the public key of the key type. */
|
|
21
|
-
address: Address.Address
|
|
22
|
-
/** Chain ID for replay protection (0 = valid on any chain). */
|
|
23
|
-
chainId?: bigintType | undefined
|
|
24
|
-
/** Unix timestamp when key expires (0 = never expires). */
|
|
25
|
-
expiry?: numberType | undefined
|
|
26
|
-
/** TIP20 spending limits for this key. */
|
|
27
|
-
limits?: readonly TokenLimit<bigintType>[] | undefined
|
|
28
|
-
/** Key type. (secp256k1, P256, WebAuthn). */
|
|
29
|
-
type: SignatureEnvelope.Type
|
|
30
|
-
} & (signed extends true
|
|
31
|
-
? { signature: SignatureEnvelope.SignatureEnvelope<bigintType, numberType> }
|
|
32
|
-
: {
|
|
33
|
-
signature?:
|
|
34
|
-
| SignatureEnvelope.SignatureEnvelope<bigintType, numberType>
|
|
35
|
-
| undefined
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
/** RPC representation of an {@link ox#KeyAuthorization.KeyAuthorization}. */
|
|
39
|
-
export type Rpc = Omit<
|
|
40
|
-
KeyAuthorization<false, Hex.Hex, Hex.Hex>,
|
|
41
|
-
'address' | 'signature' | 'type'
|
|
42
|
-
> & {
|
|
43
|
-
keyId: Address.Address
|
|
44
|
-
keyType: SignatureEnvelope.Type
|
|
45
|
-
signature: SignatureEnvelope.SignatureEnvelopeRpc
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/** Signed representation of a Key Authorization. */
|
|
49
|
-
export type Signed<bigintType = bigint, numberType = number> = KeyAuthorization<
|
|
50
|
-
true,
|
|
51
|
-
bigintType,
|
|
52
|
-
numberType
|
|
53
|
-
>
|
|
54
|
-
|
|
55
|
-
type BaseTuple = readonly [
|
|
56
|
-
chainId: Hex.Hex,
|
|
57
|
-
keyType: Hex.Hex,
|
|
58
|
-
keyId: Address.Address,
|
|
59
|
-
]
|
|
60
|
-
|
|
61
|
-
/** Tuple representation of a Key Authorization. */
|
|
62
|
-
export type Tuple<signed extends boolean = boolean> = signed extends true
|
|
63
|
-
? readonly [
|
|
64
|
-
authorization:
|
|
65
|
-
| BaseTuple
|
|
66
|
-
| readonly [...BaseTuple, expiry: Hex.Hex]
|
|
67
|
-
| readonly [
|
|
68
|
-
...BaseTuple,
|
|
69
|
-
expiry: Hex.Hex,
|
|
70
|
-
limits: readonly [token: Address.Address, limit: Hex.Hex][],
|
|
71
|
-
],
|
|
72
|
-
signature: Hex.Hex,
|
|
73
|
-
]
|
|
74
|
-
: readonly [
|
|
75
|
-
authorization:
|
|
76
|
-
| BaseTuple
|
|
77
|
-
| readonly [...BaseTuple, expiry: Hex.Hex]
|
|
78
|
-
| readonly [
|
|
79
|
-
...BaseTuple,
|
|
80
|
-
expiry: Hex.Hex,
|
|
81
|
-
limits: readonly [token: Address.Address, limit: Hex.Hex][],
|
|
82
|
-
],
|
|
83
|
-
]
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Token spending limit for access keys.
|
|
87
|
-
*
|
|
88
|
-
* Defines a per-token spending limit for an access key provisioned via a key authorization.
|
|
89
|
-
* This limit is enforced by the keychain precompile when the key is used.
|
|
90
|
-
*/
|
|
91
|
-
export type TokenLimit<bigintType = bigint> = {
|
|
92
|
-
/** Address of the TIP-20 token. */
|
|
93
|
-
token: Address.Address
|
|
94
|
-
/** Maximum spending amount for this token (enforced over the key's lifetime). */
|
|
95
|
-
limit: bigintType
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Converts a Key Authorization object into a typed {@link ox#KeyAuthorization.KeyAuthorization}.
|
|
100
|
-
*
|
|
101
|
-
* @example
|
|
102
|
-
* A Key Authorization can be instantiated from a Key Authorization tuple in object format.
|
|
103
|
-
*
|
|
104
|
-
* ```ts twoslash
|
|
105
|
-
* import { KeyAuthorization } from 'tempo.ts/ox'
|
|
106
|
-
* import { Value } from 'ox'
|
|
107
|
-
*
|
|
108
|
-
* const authorization = KeyAuthorization.from({
|
|
109
|
-
* expiry: 1234567890,
|
|
110
|
-
* keyId: '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c',
|
|
111
|
-
* keyType: 'secp256k1',
|
|
112
|
-
* limits: [{
|
|
113
|
-
* token: '0x20c0000000000000000000000000000000000001',
|
|
114
|
-
* limit: Value.from('10', 6)
|
|
115
|
-
* }],
|
|
116
|
-
* })
|
|
117
|
-
* ```
|
|
118
|
-
*
|
|
119
|
-
* @example
|
|
120
|
-
* ### Attaching Signatures
|
|
121
|
-
*
|
|
122
|
-
* A {@link ox#SignatureEnvelope.SignatureEnvelope} can be attached with the `signature` option. The example below demonstrates signing
|
|
123
|
-
* a Key Authorization with {@link ox#Secp256k1.(sign:function)}.
|
|
124
|
-
*
|
|
125
|
-
* ```ts twoslash
|
|
126
|
-
* import { KeyAuthorization } from 'tempo.ts/ox'
|
|
127
|
-
* import { Secp256k1 } from 'ox'
|
|
128
|
-
*
|
|
129
|
-
* const authorization = KeyAuthorization.from({
|
|
130
|
-
* expiry: 1234567890,
|
|
131
|
-
* keyId: '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c',
|
|
132
|
-
* keyType: 'secp256k1',
|
|
133
|
-
* limits: [{
|
|
134
|
-
* token: '0x20c0000000000000000000000000000000000001',
|
|
135
|
-
* limit: Value.from('10', 6)
|
|
136
|
-
* }],
|
|
137
|
-
* })
|
|
138
|
-
*
|
|
139
|
-
* const signature = Secp256k1.sign({
|
|
140
|
-
* payload: KeyAuthorization.getSignPayload(authorization),
|
|
141
|
-
* privateKey: '0x...',
|
|
142
|
-
* })
|
|
143
|
-
*
|
|
144
|
-
* const authorization_signed = KeyAuthorization.from(authorization, { signature }) // [!code focus]
|
|
145
|
-
* ```
|
|
146
|
-
*
|
|
147
|
-
* @param authorization - A Key Authorization tuple in object format.
|
|
148
|
-
* @param options - Key Authorization options.
|
|
149
|
-
* @returns The {@link ox#KeyAuthorization.KeyAuthorization}.
|
|
150
|
-
*/
|
|
151
|
-
export function from<
|
|
152
|
-
const authorization extends KeyAuthorization | Rpc,
|
|
153
|
-
const signature extends
|
|
154
|
-
| SignatureEnvelope.SignatureEnvelope
|
|
155
|
-
| undefined = undefined,
|
|
156
|
-
>(
|
|
157
|
-
authorization: authorization | KeyAuthorization,
|
|
158
|
-
options: from.Options<signature> = {},
|
|
159
|
-
): from.ReturnType<authorization, signature> {
|
|
160
|
-
if (typeof authorization.expiry === 'string')
|
|
161
|
-
return fromRpc(authorization as Rpc) as never
|
|
162
|
-
if (options.signature)
|
|
163
|
-
return { ...authorization, signature: options.signature } as never
|
|
164
|
-
return authorization as never
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
export declare namespace from {
|
|
168
|
-
type Options<
|
|
169
|
-
signature extends SignatureEnvelope.SignatureEnvelope | undefined =
|
|
170
|
-
| SignatureEnvelope.SignatureEnvelope
|
|
171
|
-
| undefined,
|
|
172
|
-
> = {
|
|
173
|
-
/** The {@link ox#SignatureEnvelope.SignatureEnvelope} to attach to the Key Authorization. */
|
|
174
|
-
signature?: signature | SignatureEnvelope.SignatureEnvelope | undefined
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
type ReturnType<
|
|
178
|
-
authorization extends KeyAuthorization | Rpc = KeyAuthorization,
|
|
179
|
-
signature extends SignatureEnvelope.SignatureEnvelope | undefined =
|
|
180
|
-
| SignatureEnvelope.SignatureEnvelope
|
|
181
|
-
| undefined,
|
|
182
|
-
> = Compute<
|
|
183
|
-
authorization extends Rpc
|
|
184
|
-
? Signed
|
|
185
|
-
: authorization &
|
|
186
|
-
(signature extends SignatureEnvelope.SignatureEnvelope
|
|
187
|
-
? { signature: SignatureEnvelope.from.ReturnValue<signature> }
|
|
188
|
-
: {})
|
|
189
|
-
>
|
|
190
|
-
|
|
191
|
-
type ErrorType = Errors.GlobalErrorType
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
/**
|
|
195
|
-
* Converts an {@link ox#AuthorizationAA.Rpc} to an {@link ox#AuthorizationAA.AuthorizationAA}.
|
|
196
|
-
*
|
|
197
|
-
* @example
|
|
198
|
-
* ```ts twoslash
|
|
199
|
-
* import { KeyAuthorization } from 'tempo.ts/ox'
|
|
200
|
-
*
|
|
201
|
-
* const keyAuthorization = KeyAuthorization.fromRpc({
|
|
202
|
-
* expiry: '0x174876e800',
|
|
203
|
-
* keyId: '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c',
|
|
204
|
-
* keyType: 'secp256k1',
|
|
205
|
-
* limits: [{ token: '0x20c0000000000000000000000000000000000001', limit: '0xf4240' }],
|
|
206
|
-
* signature: {
|
|
207
|
-
* type: 'secp256k1',
|
|
208
|
-
* r: '0x635dc2033e60185bb36709c29c75d64ea51dfbd91c32ef4be198e4ceb169fb4d',
|
|
209
|
-
* s: '0x50c2667ac4c771072746acfdcf1f1483336dcca8bd2df47cd83175dbe60f0540',
|
|
210
|
-
* yParity: '0x0'
|
|
211
|
-
* },
|
|
212
|
-
* })
|
|
213
|
-
* ```
|
|
214
|
-
*
|
|
215
|
-
* @param authorization - The RPC-formatted Key Authorization.
|
|
216
|
-
* @returns A signed {@link ox#AuthorizationAA.AuthorizationAA}.
|
|
217
|
-
*/
|
|
218
|
-
export function fromRpc(authorization: Rpc): Signed {
|
|
219
|
-
const { chainId = '0x0', keyId, expiry = 0, limits, keyType } = authorization
|
|
220
|
-
const signature = SignatureEnvelope.fromRpc(authorization.signature)
|
|
221
|
-
return {
|
|
222
|
-
address: keyId,
|
|
223
|
-
chainId: chainId === '0x' ? 0n : Hex.toBigInt(chainId),
|
|
224
|
-
expiry: Number(expiry),
|
|
225
|
-
limits: limits?.map((limit) => ({
|
|
226
|
-
token: limit.token,
|
|
227
|
-
limit: BigInt(limit.limit),
|
|
228
|
-
})),
|
|
229
|
-
signature,
|
|
230
|
-
type: keyType,
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
export declare namespace fromRpc {
|
|
235
|
-
type ErrorType = Errors.GlobalErrorType
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
/**
|
|
239
|
-
* Converts an {@link ox#KeyAuthorization.Tuple} to an {@link ox#KeyAuthorization.KeyAuthorization}.
|
|
240
|
-
*
|
|
241
|
-
* @example
|
|
242
|
-
* ```ts twoslash
|
|
243
|
-
* import { KeyAuthorization } from 'tempo.ts/ox'
|
|
244
|
-
*
|
|
245
|
-
* const authorization = KeyAuthorization.fromTuple([
|
|
246
|
-
* '0x174876e800',
|
|
247
|
-
* [['0x20c0000000000000000000000000000000000001', '0xf4240']],
|
|
248
|
-
* 'secp256k1',
|
|
249
|
-
* '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c',
|
|
250
|
-
* '0x01a068a020a209d3d56c46f38cc50a33f704f4a9a10a59377f8dd762ac66910e9b907e865ad05c4035ab5792787d4a0297a43617ae897930a6fe4d822b8faea52064'
|
|
251
|
-
* ])
|
|
252
|
-
* // @log: {
|
|
253
|
-
* // @log: expiry: 1234567890,
|
|
254
|
-
* // @log: keyId: '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c',
|
|
255
|
-
* // @log: keyType: 'secp256k1',
|
|
256
|
-
* // @log: limits: [{ token: '0x20c0000000000000000000000000000000000001', limit: '0xf4240' }],
|
|
257
|
-
* // @log: signature: {
|
|
258
|
-
* // @log: type: 'secp256k1',
|
|
259
|
-
* // @log: r: '0x68a020a209d3d56c46f38cc50a33f704f4a9a10a59377f8dd762ac66910e9b90',
|
|
260
|
-
* // @log: s: '0x7e865ad05c4035ab5792787d4a0297a43617ae897930a6fe4d822b8faea52064',
|
|
261
|
-
* // @log: yParity: 0,
|
|
262
|
-
* // @log: },
|
|
263
|
-
* // @log: }
|
|
264
|
-
* ```
|
|
265
|
-
*
|
|
266
|
-
* @example
|
|
267
|
-
* It is also possible to append a serialized SignatureEnvelope to the end of a Key Authorization tuple.
|
|
268
|
-
*
|
|
269
|
-
* ```ts twoslash
|
|
270
|
-
* import { KeyAuthorization } from 'tempo.ts/ox'
|
|
271
|
-
*
|
|
272
|
-
* const authorization = KeyAuthorization.fromTuple([
|
|
273
|
-
* '0x174876e800',
|
|
274
|
-
* [['0x20c0000000000000000000000000000000000001', '0xf4240']],
|
|
275
|
-
* 'secp256k1',
|
|
276
|
-
* '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c',
|
|
277
|
-
* '0x01a068a020a209d3d56c46f38cc50a33f704f4a9a10a59377f8dd762ac66910e9b907e865ad05c4035ab5792787d4a0297a43617ae897930a6fe4d822b8faea52064',
|
|
278
|
-
* ])
|
|
279
|
-
* // @log: {
|
|
280
|
-
* // @log: expiry: 1234567890,
|
|
281
|
-
* // @log: keyId: '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c',
|
|
282
|
-
* // @log: keyType: 'secp256k1',
|
|
283
|
-
* // @log: limits: [{ token: '0x20c0000000000000000000000000000000000001', limit: '0xf4240' }],
|
|
284
|
-
* // @log: signature: {
|
|
285
|
-
* // @log: type: 'secp256k1',
|
|
286
|
-
* // @log: r: '0x68a020a209d3d56c46f38cc50a33f704f4a9a10a59377f8dd762ac66910e9b90',
|
|
287
|
-
* // @log: s: '0x7e865ad05c4035ab5792787d4a0297a43617ae897930a6fe4d822b8faea52064',
|
|
288
|
-
* // @log: yParity: 0,
|
|
289
|
-
* // @log: },
|
|
290
|
-
* // @log: }
|
|
291
|
-
* ```
|
|
292
|
-
*
|
|
293
|
-
* @param tuple - The Key Authorization tuple.
|
|
294
|
-
* @returns The {@link ox#KeyAuthorization.KeyAuthorization}.
|
|
295
|
-
*/
|
|
296
|
-
export function fromTuple<const tuple extends Tuple>(
|
|
297
|
-
tuple: tuple,
|
|
298
|
-
): fromTuple.ReturnType<tuple> {
|
|
299
|
-
const [authorization, signatureSerialized] = tuple
|
|
300
|
-
const [chainId, keyType_hex, keyId, expiry, limits] = authorization
|
|
301
|
-
const keyType = (() => {
|
|
302
|
-
switch (keyType_hex) {
|
|
303
|
-
case '0x':
|
|
304
|
-
case '0x00':
|
|
305
|
-
return 'secp256k1'
|
|
306
|
-
case '0x01':
|
|
307
|
-
return 'p256'
|
|
308
|
-
case '0x02':
|
|
309
|
-
return 'webAuthn'
|
|
310
|
-
default:
|
|
311
|
-
throw new Error(`Invalid key type: ${keyType_hex}`)
|
|
312
|
-
}
|
|
313
|
-
})()
|
|
314
|
-
const args: KeyAuthorization = {
|
|
315
|
-
address: keyId,
|
|
316
|
-
expiry: typeof expiry !== 'undefined' ? Hex.toNumber(expiry) : undefined,
|
|
317
|
-
type: keyType,
|
|
318
|
-
...(chainId !== '0x' ? { chainId: Hex.toBigInt(chainId) } : {}),
|
|
319
|
-
...(typeof expiry !== 'undefined' ? { expiry: Hex.toNumber(expiry) } : {}),
|
|
320
|
-
...(typeof limits !== 'undefined'
|
|
321
|
-
? {
|
|
322
|
-
limits: limits.map(([token, limit]) => ({
|
|
323
|
-
token,
|
|
324
|
-
limit: BigInt(limit),
|
|
325
|
-
})),
|
|
326
|
-
}
|
|
327
|
-
: {}),
|
|
328
|
-
}
|
|
329
|
-
if (signatureSerialized)
|
|
330
|
-
args.signature = SignatureEnvelope.deserialize(signatureSerialized)
|
|
331
|
-
return from(args) as never
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
export declare namespace fromTuple {
|
|
335
|
-
type ReturnType<authorization extends Tuple = Tuple> = Compute<
|
|
336
|
-
KeyAuthorization<authorization extends Tuple<true> ? true : false>
|
|
337
|
-
>
|
|
338
|
-
|
|
339
|
-
type ErrorType = Errors.GlobalErrorType
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
/**
|
|
343
|
-
* Computes the sign payload for an {@link ox#KeyAuthorization.KeyAuthorization}.
|
|
344
|
-
*
|
|
345
|
-
* @example
|
|
346
|
-
* The example below demonstrates computing the sign payload for an {@link ox#KeyAuthorization.KeyAuthorization}. This payload
|
|
347
|
-
* can then be passed to signing functions like {@link ox#Secp256k1.(sign:function)}.
|
|
348
|
-
*
|
|
349
|
-
* ```ts twoslash
|
|
350
|
-
* import { KeyAuthorization } from 'tempo.ts/ox'
|
|
351
|
-
* import { Secp256k1 } from 'ox'
|
|
352
|
-
*
|
|
353
|
-
* const authorization = KeyAuthorization.from({
|
|
354
|
-
* expiry: 1234567890,
|
|
355
|
-
* keyId: '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c',
|
|
356
|
-
* keyType: 'secp256k1',
|
|
357
|
-
* limits: [{
|
|
358
|
-
* token: '0x20c0000000000000000000000000000000000001',
|
|
359
|
-
* limit: Value.from('10', 6)
|
|
360
|
-
* }],
|
|
361
|
-
* })
|
|
362
|
-
*
|
|
363
|
-
* const payload = KeyAuthorization.getSignPayload(authorization) // [!code focus]
|
|
364
|
-
*
|
|
365
|
-
* const signature = Secp256k1.sign({
|
|
366
|
-
* payload,
|
|
367
|
-
* privateKey: '0x...',
|
|
368
|
-
* })
|
|
369
|
-
* ```
|
|
370
|
-
*
|
|
371
|
-
* @param authorization - The {@link ox#KeyAuthorization.KeyAuthorization}.
|
|
372
|
-
* @returns The sign payload.
|
|
373
|
-
*/
|
|
374
|
-
export function getSignPayload(authorization: KeyAuthorization): Hex.Hex {
|
|
375
|
-
return hash(authorization)
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
export declare namespace getSignPayload {
|
|
379
|
-
type ErrorType = hash.ErrorType | Errors.GlobalErrorType
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
/**
|
|
383
|
-
* Computes the hash for an {@link ox#KeyAuthorization.KeyAuthorization}.
|
|
384
|
-
*
|
|
385
|
-
* @example
|
|
386
|
-
* ```ts twoslash
|
|
387
|
-
* import { KeyAuthorization } from 'tempo.ts/ox'
|
|
388
|
-
* import { Value } from 'ox'
|
|
389
|
-
*
|
|
390
|
-
* const authorization = KeyAuthorization.from({
|
|
391
|
-
* expiry: 1234567890,
|
|
392
|
-
* keyId: '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c',
|
|
393
|
-
* keyType: 'secp256k1',
|
|
394
|
-
* limits: [{
|
|
395
|
-
* token: '0x20c0000000000000000000000000000000000001',
|
|
396
|
-
* limit: Value.from('10', 6)
|
|
397
|
-
* }],
|
|
398
|
-
* })
|
|
399
|
-
*
|
|
400
|
-
* const hash = KeyAuthorization.hash(authorization) // [!code focus]
|
|
401
|
-
* ```
|
|
402
|
-
*
|
|
403
|
-
* @param authorization - The {@link ox#KeyAuthorization.KeyAuthorization}.
|
|
404
|
-
* @returns The hash.
|
|
405
|
-
*/
|
|
406
|
-
export function hash(authorization: KeyAuthorization): Hex.Hex {
|
|
407
|
-
const [authorizationTuple] = toTuple(authorization)
|
|
408
|
-
const serialized = Rlp.fromHex(authorizationTuple)
|
|
409
|
-
return Hash.keccak256(serialized)
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
export declare namespace hash {
|
|
413
|
-
type ErrorType =
|
|
414
|
-
| toTuple.ErrorType
|
|
415
|
-
| Hash.keccak256.ErrorType
|
|
416
|
-
| Hex.concat.ErrorType
|
|
417
|
-
| Rlp.fromHex.ErrorType
|
|
418
|
-
| Errors.GlobalErrorType
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
/**
|
|
422
|
-
* Converts an {@link ox#KeyAuthorization.KeyAuthorization} to an {@link ox#KeyAuthorization.Rpc}.
|
|
423
|
-
*
|
|
424
|
-
* @example
|
|
425
|
-
* ```ts twoslash
|
|
426
|
-
* import { KeyAuthorization } from 'tempo.ts/ox'
|
|
427
|
-
*
|
|
428
|
-
* const authorization = KeyAuthorization.toRpc({
|
|
429
|
-
* expiry: 1234567890,
|
|
430
|
-
* keyId: '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c',
|
|
431
|
-
* keyType: 'secp256k1',
|
|
432
|
-
* limits: [{
|
|
433
|
-
* token: '0x20c0000000000000000000000000000000000001',
|
|
434
|
-
* limit: Value.from('10', 6)
|
|
435
|
-
* }],
|
|
436
|
-
* signature: {
|
|
437
|
-
* type: 'secp256k1',
|
|
438
|
-
* r: 44944627813007772897391531230081695102703289123332187696115181104739239197517n,
|
|
439
|
-
* s: 36528503505192438307355164441104001310566505351980369085208178712678799181120n,
|
|
440
|
-
* yParity: 0,
|
|
441
|
-
* },
|
|
442
|
-
* })
|
|
443
|
-
* ```
|
|
444
|
-
*
|
|
445
|
-
* @param authorization - A Key Authorization.
|
|
446
|
-
* @returns An RPC-formatted Key Authorization.
|
|
447
|
-
*/
|
|
448
|
-
export function toRpc(authorization: Signed): Rpc {
|
|
449
|
-
const {
|
|
450
|
-
address,
|
|
451
|
-
chainId = 0n,
|
|
452
|
-
expiry,
|
|
453
|
-
limits,
|
|
454
|
-
type,
|
|
455
|
-
signature,
|
|
456
|
-
} = authorization
|
|
457
|
-
|
|
458
|
-
return {
|
|
459
|
-
chainId: chainId === 0n ? '0x' : Hex.fromNumber(chainId),
|
|
460
|
-
expiry: typeof expiry === 'number' ? Hex.fromNumber(expiry) : undefined,
|
|
461
|
-
limits: limits?.map(({ token, limit }) => ({
|
|
462
|
-
token,
|
|
463
|
-
limit: Hex.fromNumber(limit),
|
|
464
|
-
})),
|
|
465
|
-
keyId: address,
|
|
466
|
-
signature: SignatureEnvelope.toRpc(signature),
|
|
467
|
-
keyType: type,
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
export declare namespace toRpc {
|
|
472
|
-
type ErrorType = Errors.GlobalErrorType
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
/**
|
|
476
|
-
* Converts an {@link ox#KeyAuthorization.KeyAuthorization} to an {@link ox#KeyAuthorization.Tuple}.
|
|
477
|
-
*
|
|
478
|
-
* @example
|
|
479
|
-
* ```ts twoslash
|
|
480
|
-
* import { KeyAuthorization } from 'tempo.ts/ox'
|
|
481
|
-
* import { Value } from 'ox'
|
|
482
|
-
*
|
|
483
|
-
* const authorization = KeyAuthorization.from({
|
|
484
|
-
* expiry: 1234567890,
|
|
485
|
-
* keyId: '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c',
|
|
486
|
-
* keyType: 'secp256k1',
|
|
487
|
-
* limits: [{
|
|
488
|
-
* token: '0x20c0000000000000000000000000000000000001',
|
|
489
|
-
* limit: Value.from('10', 6)
|
|
490
|
-
* }],
|
|
491
|
-
* })
|
|
492
|
-
*
|
|
493
|
-
* const tuple = KeyAuthorization.toTuple(authorization) // [!code focus]
|
|
494
|
-
* // @log: [
|
|
495
|
-
* // @log: '0x174876e800',
|
|
496
|
-
* // @log: [['0x20c0000000000000000000000000000000000001', '0xf4240']],
|
|
497
|
-
* // @log: '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c',
|
|
498
|
-
* // @log: 'secp256k1',
|
|
499
|
-
* // @log: ]
|
|
500
|
-
* ```
|
|
501
|
-
*
|
|
502
|
-
* @param authorization - The {@link ox#KeyAuthorization.KeyAuthorization}.
|
|
503
|
-
* @returns A Tempo Key Authorization tuple.
|
|
504
|
-
*/
|
|
505
|
-
export function toTuple<const authorization extends KeyAuthorization>(
|
|
506
|
-
authorization: authorization,
|
|
507
|
-
): toTuple.ReturnType<authorization> {
|
|
508
|
-
const { address, chainId = 0n, expiry, limits } = authorization
|
|
509
|
-
const signature = authorization.signature
|
|
510
|
-
? SignatureEnvelope.serialize(authorization.signature)
|
|
511
|
-
: undefined
|
|
512
|
-
const type = (() => {
|
|
513
|
-
switch (authorization.type) {
|
|
514
|
-
case 'secp256k1':
|
|
515
|
-
return '0x'
|
|
516
|
-
case 'p256':
|
|
517
|
-
return '0x01'
|
|
518
|
-
case 'webAuthn':
|
|
519
|
-
return '0x02'
|
|
520
|
-
default:
|
|
521
|
-
throw new Error(`Invalid key type: ${authorization.type}`)
|
|
522
|
-
}
|
|
523
|
-
})()
|
|
524
|
-
const authorizationTuple = [
|
|
525
|
-
chainId === 0n ? '0x' : Hex.fromNumber(chainId),
|
|
526
|
-
type,
|
|
527
|
-
address,
|
|
528
|
-
typeof expiry === 'number' ? Hex.fromNumber(expiry) : undefined,
|
|
529
|
-
limits?.map((limit) => [limit.token, Hex.fromNumber(limit.limit)]) ??
|
|
530
|
-
undefined,
|
|
531
|
-
].filter(Boolean)
|
|
532
|
-
return [authorizationTuple, ...(signature ? [signature] : [])] as never
|
|
533
|
-
}
|
|
534
|
-
|
|
535
|
-
export declare namespace toTuple {
|
|
536
|
-
type ReturnType<authorization extends KeyAuthorization = KeyAuthorization> =
|
|
537
|
-
Compute<Tuple<authorization extends KeyAuthorization<true> ? true : false>>
|
|
538
|
-
|
|
539
|
-
type ErrorType = Errors.GlobalErrorType
|
|
540
|
-
}
|
package/src/ox/Order.test.ts
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from 'vitest'
|
|
2
|
-
import * as Order from './Order.js'
|
|
3
|
-
|
|
4
|
-
describe('fromRpc', () => {
|
|
5
|
-
test('default', () => {
|
|
6
|
-
const rpcOrder: Order.Rpc = {
|
|
7
|
-
amount: '0x64',
|
|
8
|
-
baseToken: '0x20c0000000000000000000000000000000000001',
|
|
9
|
-
flipTick: 0,
|
|
10
|
-
isBid: true,
|
|
11
|
-
isFlip: false,
|
|
12
|
-
maker: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb',
|
|
13
|
-
next: '0x0',
|
|
14
|
-
orderId: '0x1',
|
|
15
|
-
quoteToken: '0x20c0000000000000000000000000000000000002',
|
|
16
|
-
prev: '0x0',
|
|
17
|
-
remaining: '0x64',
|
|
18
|
-
tick: 100,
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const order = Order.fromRpc(rpcOrder)
|
|
22
|
-
|
|
23
|
-
expect(order).toMatchInlineSnapshot(`
|
|
24
|
-
{
|
|
25
|
-
"amount": 100n,
|
|
26
|
-
"baseToken": "0x20c0000000000000000000000000000000000001",
|
|
27
|
-
"flipTick": 0,
|
|
28
|
-
"isBid": true,
|
|
29
|
-
"isFlip": false,
|
|
30
|
-
"maker": "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb",
|
|
31
|
-
"next": 0n,
|
|
32
|
-
"orderId": 1n,
|
|
33
|
-
"prev": 0n,
|
|
34
|
-
"quoteToken": "0x20c0000000000000000000000000000000000002",
|
|
35
|
-
"remaining": 100n,
|
|
36
|
-
"tick": 100,
|
|
37
|
-
}
|
|
38
|
-
`)
|
|
39
|
-
})
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
describe('toRpc', () => {
|
|
43
|
-
test('default', () => {
|
|
44
|
-
const order: Order.Order = {
|
|
45
|
-
amount: 100n,
|
|
46
|
-
baseToken: '0x20c0000000000000000000000000000000000001',
|
|
47
|
-
flipTick: 0,
|
|
48
|
-
isBid: true,
|
|
49
|
-
isFlip: false,
|
|
50
|
-
maker: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb',
|
|
51
|
-
next: 0n,
|
|
52
|
-
orderId: 1n,
|
|
53
|
-
quoteToken: '0x20c0000000000000000000000000000000000002',
|
|
54
|
-
prev: 0n,
|
|
55
|
-
remaining: 100n,
|
|
56
|
-
tick: 100,
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const rpcOrder = Order.toRpc(order)
|
|
60
|
-
|
|
61
|
-
expect(rpcOrder).toMatchInlineSnapshot(`
|
|
62
|
-
{
|
|
63
|
-
"amount": "0x64",
|
|
64
|
-
"baseToken": "0x20c0000000000000000000000000000000000001",
|
|
65
|
-
"flipTick": 0,
|
|
66
|
-
"isBid": true,
|
|
67
|
-
"isFlip": false,
|
|
68
|
-
"maker": "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb",
|
|
69
|
-
"next": "0x0",
|
|
70
|
-
"orderId": "0x1",
|
|
71
|
-
"prev": "0x0",
|
|
72
|
-
"quoteToken": "0x20c0000000000000000000000000000000000002",
|
|
73
|
-
"remaining": "0x64",
|
|
74
|
-
"tick": 100,
|
|
75
|
-
}
|
|
76
|
-
`)
|
|
77
|
-
})
|
|
78
|
-
})
|