ox 0.14.24 → 0.14.25
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 +6 -0
- package/_cjs/tempo/Channel.js +31 -11
- package/_cjs/tempo/Channel.js.map +1 -1
- package/_cjs/tempo/index.js +1 -2
- package/_cjs/tempo/index.js.map +1 -1
- package/_cjs/version.js +1 -1
- package/_esm/tempo/Channel.js +56 -13
- package/_esm/tempo/Channel.js.map +1 -1
- package/_esm/tempo/index.js +9 -30
- package/_esm/tempo/index.js.map +1 -1
- package/_esm/version.js +1 -1
- package/_types/tempo/Channel.d.ts +73 -8
- package/_types/tempo/Channel.d.ts.map +1 -1
- package/_types/tempo/index.d.ts +9 -30
- package/_types/tempo/index.d.ts.map +1 -1
- package/_types/version.d.ts +1 -1
- package/package.json +1 -6
- package/tempo/Channel.test.ts +99 -16
- package/tempo/Channel.ts +127 -18
- package/tempo/index.ts +9 -30
- package/version.ts +1 -1
- package/_cjs/tempo/ChannelDescriptor.js +0 -24
- package/_cjs/tempo/ChannelDescriptor.js.map +0 -1
- package/_esm/tempo/ChannelDescriptor.js +0 -43
- package/_esm/tempo/ChannelDescriptor.js.map +0 -1
- package/_types/tempo/ChannelDescriptor.d.ts +0 -73
- package/_types/tempo/ChannelDescriptor.d.ts.map +0 -1
- package/tempo/ChannelDescriptor/package.json +0 -6
- package/tempo/ChannelDescriptor.test.ts +0 -93
- package/tempo/ChannelDescriptor.ts +0 -115
package/tempo/Channel.test.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { Hash, Hex, TypedData } from 'ox'
|
|
1
|
+
import { type Address, Hash, Hex, TypedData } from 'ox'
|
|
2
2
|
import { Channel } from 'ox/tempo'
|
|
3
3
|
import { describe, expect, test } from 'vitest'
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const channel = {
|
|
6
6
|
authorizedSigner: '0x3333333333333333333333333333333333333333',
|
|
7
|
-
chainId: 4217,
|
|
8
7
|
expiringNonceHash:
|
|
9
8
|
'0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
10
9
|
operator: '0x0000000000000000000000000000000000000000',
|
|
@@ -14,6 +13,8 @@ const descriptor = {
|
|
|
14
13
|
token: 1n,
|
|
15
14
|
} as const
|
|
16
15
|
|
|
16
|
+
const chainId = 4217
|
|
17
|
+
|
|
17
18
|
describe('address', () => {
|
|
18
19
|
test('default', () => {
|
|
19
20
|
expect(Channel.address).toMatchInlineSnapshot(
|
|
@@ -41,38 +42,120 @@ describe('voucherTypehash', () => {
|
|
|
41
42
|
})
|
|
42
43
|
})
|
|
43
44
|
|
|
45
|
+
describe('from', () => {
|
|
46
|
+
test('default', () => {
|
|
47
|
+
expect(
|
|
48
|
+
Channel.from({
|
|
49
|
+
...channel,
|
|
50
|
+
operator: '0x4444444444444444444444444444444444444444',
|
|
51
|
+
}),
|
|
52
|
+
).toMatchInlineSnapshot(`
|
|
53
|
+
{
|
|
54
|
+
"authorizedSigner": "0x3333333333333333333333333333333333333333",
|
|
55
|
+
"expiringNonceHash": "0x0000000000000000000000000000000000000000000000000000000000000002",
|
|
56
|
+
"operator": "0x4444444444444444444444444444444444444444",
|
|
57
|
+
"payee": "0x2222222222222222222222222222222222222222",
|
|
58
|
+
"payer": "0x1111111111111111111111111111111111111111",
|
|
59
|
+
"salt": "0x0000000000000000000000000000000000000000000000000000000000000001",
|
|
60
|
+
"token": "0x20c0000000000000000000000000000000000001",
|
|
61
|
+
}
|
|
62
|
+
`)
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
test('default values', () => {
|
|
66
|
+
expect(
|
|
67
|
+
Channel.from({
|
|
68
|
+
expiringNonceHash: channel.expiringNonceHash,
|
|
69
|
+
payee: channel.payee,
|
|
70
|
+
payer: channel.payer,
|
|
71
|
+
salt: channel.salt,
|
|
72
|
+
token: channel.token,
|
|
73
|
+
}),
|
|
74
|
+
).toMatchInlineSnapshot(`
|
|
75
|
+
{
|
|
76
|
+
"authorizedSigner": "0x0000000000000000000000000000000000000000",
|
|
77
|
+
"expiringNonceHash": "0x0000000000000000000000000000000000000000000000000000000000000002",
|
|
78
|
+
"operator": "0x0000000000000000000000000000000000000000",
|
|
79
|
+
"payee": "0x2222222222222222222222222222222222222222",
|
|
80
|
+
"payer": "0x1111111111111111111111111111111111111111",
|
|
81
|
+
"salt": "0x0000000000000000000000000000000000000000000000000000000000000001",
|
|
82
|
+
"token": "0x20c0000000000000000000000000000000000001",
|
|
83
|
+
}
|
|
84
|
+
`)
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
test('token address input', () => {
|
|
88
|
+
expect(
|
|
89
|
+
Channel.from({
|
|
90
|
+
...channel,
|
|
91
|
+
operator: '0x4444444444444444444444444444444444444444',
|
|
92
|
+
token: '0x20c0000000000000000000000000000000000001',
|
|
93
|
+
}),
|
|
94
|
+
).toMatchInlineSnapshot(`
|
|
95
|
+
{
|
|
96
|
+
"authorizedSigner": "0x3333333333333333333333333333333333333333",
|
|
97
|
+
"expiringNonceHash": "0x0000000000000000000000000000000000000000000000000000000000000002",
|
|
98
|
+
"operator": "0x4444444444444444444444444444444444444444",
|
|
99
|
+
"payee": "0x2222222222222222222222222222222222222222",
|
|
100
|
+
"payer": "0x1111111111111111111111111111111111111111",
|
|
101
|
+
"salt": "0x0000000000000000000000000000000000000000000000000000000000000001",
|
|
102
|
+
"token": "0x20c0000000000000000000000000000000000001",
|
|
103
|
+
}
|
|
104
|
+
`)
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
test('return type', () => {
|
|
108
|
+
const resolved = Channel.from({
|
|
109
|
+
expiringNonceHash:
|
|
110
|
+
'0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
111
|
+
payee: '0x2222222222222222222222222222222222222222',
|
|
112
|
+
payer: '0x1111111111111111111111111111111111111111',
|
|
113
|
+
salt: '0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
114
|
+
token: 1n,
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
resolved satisfies Channel.Resolved
|
|
118
|
+
resolved satisfies Channel.Channel
|
|
119
|
+
resolved.payer satisfies Address.Address
|
|
120
|
+
resolved.token satisfies Address.Address
|
|
121
|
+
})
|
|
122
|
+
})
|
|
123
|
+
|
|
44
124
|
describe('computeId', () => {
|
|
45
125
|
test('default', () => {
|
|
46
|
-
expect(Channel.computeId(
|
|
126
|
+
expect(Channel.computeId(channel, { chainId })).toMatchInlineSnapshot(
|
|
47
127
|
`"0xa392474fdbb5c6753e8789236893343f11200f43ba53cca09c0cda3651946ef2"`,
|
|
48
128
|
)
|
|
49
129
|
})
|
|
50
130
|
|
|
51
131
|
test('token address input', () => {
|
|
52
132
|
expect(
|
|
53
|
-
Channel.computeId(
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
133
|
+
Channel.computeId(
|
|
134
|
+
{
|
|
135
|
+
...channel,
|
|
136
|
+
token: '0x20c0000000000000000000000000000000000001',
|
|
137
|
+
},
|
|
138
|
+
{ chainId },
|
|
139
|
+
),
|
|
140
|
+
).toBe(Channel.computeId(channel, { chainId }))
|
|
58
141
|
})
|
|
59
142
|
|
|
60
143
|
test('chain id bigint', () => {
|
|
61
|
-
expect(Channel.computeId({
|
|
62
|
-
Channel.computeId(
|
|
144
|
+
expect(Channel.computeId(channel, { chainId: 4217n })).toBe(
|
|
145
|
+
Channel.computeId(channel, { chainId }),
|
|
63
146
|
)
|
|
64
147
|
})
|
|
65
148
|
})
|
|
66
149
|
|
|
67
150
|
describe('domainSeparator', () => {
|
|
68
151
|
test('default', () => {
|
|
69
|
-
const separator = Channel.domainSeparator({ chainId
|
|
152
|
+
const separator = Channel.domainSeparator({ chainId })
|
|
70
153
|
|
|
71
154
|
expect(separator).toBe(
|
|
72
155
|
TypedData.domainSeparator({
|
|
73
156
|
name: 'TIP20 Channel Reserve',
|
|
74
157
|
version: '1',
|
|
75
|
-
chainId
|
|
158
|
+
chainId,
|
|
76
159
|
verifyingContract: Channel.address,
|
|
77
160
|
}),
|
|
78
161
|
)
|
|
@@ -84,10 +167,10 @@ describe('domainSeparator', () => {
|
|
|
84
167
|
|
|
85
168
|
describe('getVoucherSignPayload', () => {
|
|
86
169
|
test('default', () => {
|
|
87
|
-
const channelId = Channel.computeId(
|
|
170
|
+
const channelId = Channel.computeId(channel, { chainId })
|
|
88
171
|
const cumulativeAmount = 100n
|
|
89
172
|
const payload = Channel.getVoucherSignPayload({
|
|
90
|
-
chainId
|
|
173
|
+
chainId,
|
|
91
174
|
channelId,
|
|
92
175
|
cumulativeAmount,
|
|
93
176
|
})
|
|
@@ -97,7 +180,7 @@ describe('getVoucherSignPayload', () => {
|
|
|
97
180
|
domain: {
|
|
98
181
|
name: 'TIP20 Channel Reserve',
|
|
99
182
|
version: '1',
|
|
100
|
-
chainId
|
|
183
|
+
chainId,
|
|
101
184
|
verifyingContract: Channel.address,
|
|
102
185
|
},
|
|
103
186
|
message: {
|
package/tempo/Channel.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import * as AbiParameters from '../core/AbiParameters.js'
|
|
2
|
-
import
|
|
2
|
+
import * as Address from '../core/Address.js'
|
|
3
|
+
import type * as Errors from '../core/Errors.js'
|
|
3
4
|
import * as Hash from '../core/Hash.js'
|
|
4
5
|
import * as Hex from '../core/Hex.js'
|
|
5
|
-
import * as
|
|
6
|
+
import * as TokenId from './TokenId.js'
|
|
6
7
|
|
|
7
8
|
const channelIdParameters = AbiParameters.from(
|
|
8
9
|
'address, address, address, address, bytes32, address, bytes32, address, uint256',
|
|
@@ -19,6 +20,8 @@ const eip712DomainTypehash = Hash.keccak256(
|
|
|
19
20
|
)
|
|
20
21
|
const nameHash = Hash.keccak256(Hex.fromString('TIP20 Channel Reserve'))
|
|
21
22
|
const versionHash = Hash.keccak256(Hex.fromString('1'))
|
|
23
|
+
const zeroAddress =
|
|
24
|
+
'0x0000000000000000000000000000000000000000' as const satisfies Address.Address
|
|
22
25
|
|
|
23
26
|
/**
|
|
24
27
|
* TIP-20 channel reserve precompile address.
|
|
@@ -41,7 +44,102 @@ export const voucherTypehash = Hash.keccak256(
|
|
|
41
44
|
/**
|
|
42
45
|
* TIP-20 channel descriptor.
|
|
43
46
|
*/
|
|
44
|
-
export type
|
|
47
|
+
export type Channel<
|
|
48
|
+
addressType = Address.Address,
|
|
49
|
+
tokenType = TokenId.TokenIdOrAddress<addressType>,
|
|
50
|
+
> = {
|
|
51
|
+
/** Optional signer for vouchers. Zero means `payer` signs. */
|
|
52
|
+
authorizedSigner: addressType
|
|
53
|
+
/** Transaction-derived hash assigned when the channel was opened. */
|
|
54
|
+
expiringNonceHash: Hex.Hex
|
|
55
|
+
/** Optional relayer allowed to submit `settle` for the payee. */
|
|
56
|
+
operator: addressType
|
|
57
|
+
/** Account that receives settled voucher payments. */
|
|
58
|
+
payee: addressType
|
|
59
|
+
/** Account that funded the channel and receives refunds. */
|
|
60
|
+
payer: addressType
|
|
61
|
+
/** User-supplied salt to distinguish otherwise identical channels. */
|
|
62
|
+
salt: Hex.Hex
|
|
63
|
+
/** TIP-20 token address held by the channel. */
|
|
64
|
+
token: tokenType
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Hex-address-normalized {@link ox#Channel.Channel}. */
|
|
68
|
+
export type Resolved = Channel<Address.Address, Address.Address>
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Instantiates a TIP-20 channel reserve descriptor.
|
|
72
|
+
*
|
|
73
|
+
* Accepts a TIP-20 token ID or address, and defaults `operator` and
|
|
74
|
+
* `authorizedSigner` to the zero address.
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```ts twoslash
|
|
78
|
+
* import { Channel } from 'ox/tempo'
|
|
79
|
+
*
|
|
80
|
+
* const channel = Channel.from({
|
|
81
|
+
* expiringNonceHash: '0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
82
|
+
* payee: '0x2222222222222222222222222222222222222222',
|
|
83
|
+
* payer: '0x1111111111111111111111111111111111111111',
|
|
84
|
+
* salt: '0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
85
|
+
* token: 1n,
|
|
86
|
+
* })
|
|
87
|
+
* ```
|
|
88
|
+
*
|
|
89
|
+
* @param value - The channel descriptor input.
|
|
90
|
+
* @returns The normalized channel descriptor.
|
|
91
|
+
*/
|
|
92
|
+
export function from(value: from.Value): from.ReturnType {
|
|
93
|
+
const {
|
|
94
|
+
authorizedSigner = zeroAddress,
|
|
95
|
+
expiringNonceHash,
|
|
96
|
+
operator = zeroAddress,
|
|
97
|
+
payee,
|
|
98
|
+
payer,
|
|
99
|
+
salt,
|
|
100
|
+
token,
|
|
101
|
+
} = value
|
|
102
|
+
|
|
103
|
+
return {
|
|
104
|
+
authorizedSigner: resolveAddress(authorizedSigner),
|
|
105
|
+
expiringNonceHash,
|
|
106
|
+
operator: resolveAddress(operator),
|
|
107
|
+
payee: resolveAddress(payee),
|
|
108
|
+
payer: resolveAddress(payer),
|
|
109
|
+
salt,
|
|
110
|
+
token:
|
|
111
|
+
typeof token === 'string'
|
|
112
|
+
? resolveAddress(token)
|
|
113
|
+
: TokenId.toAddress(token),
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export declare namespace from {
|
|
118
|
+
type Value = {
|
|
119
|
+
/** Optional signer for vouchers. Zero means `payer` signs. */
|
|
120
|
+
authorizedSigner?: Address.Address | undefined
|
|
121
|
+
/** Transaction-derived hash assigned when the channel was opened. */
|
|
122
|
+
expiringNonceHash: Hex.Hex
|
|
123
|
+
/** Optional relayer allowed to submit `settle` for the payee. */
|
|
124
|
+
operator?: Address.Address | undefined
|
|
125
|
+
/** Account that receives settled voucher payments. */
|
|
126
|
+
payee: Address.Address
|
|
127
|
+
/** Account that funded the channel and receives refunds. */
|
|
128
|
+
payer: Address.Address
|
|
129
|
+
/** User-supplied salt to distinguish otherwise identical channels. */
|
|
130
|
+
salt: Hex.Hex
|
|
131
|
+
/** TIP-20 token address or ID held by the channel. */
|
|
132
|
+
token: TokenId.TokenIdOrAddress<Address.Address>
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
type ReturnType = Resolved
|
|
136
|
+
|
|
137
|
+
type ErrorType =
|
|
138
|
+
| Address.from.ErrorType
|
|
139
|
+
| Hex.concat.ErrorType
|
|
140
|
+
| Hex.fromNumber.ErrorType
|
|
141
|
+
| Errors.GlobalErrorType
|
|
142
|
+
}
|
|
45
143
|
|
|
46
144
|
/**
|
|
47
145
|
* Computes the canonical TIP-20 channel id for a descriptor.
|
|
@@ -55,45 +153,52 @@ export type Descriptor = ChannelDescriptor.ChannelDescriptor
|
|
|
55
153
|
*
|
|
56
154
|
* const channelId = Channel.computeId({
|
|
57
155
|
* authorizedSigner: '0x0000000000000000000000000000000000000000',
|
|
58
|
-
* chainId: 4217,
|
|
59
156
|
* expiringNonceHash: '0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
60
157
|
* operator: '0x0000000000000000000000000000000000000000',
|
|
61
158
|
* payee: '0x2222222222222222222222222222222222222222',
|
|
62
159
|
* payer: '0x1111111111111111111111111111111111111111',
|
|
63
160
|
* salt: '0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
64
161
|
* token: 1n,
|
|
162
|
+
* }, {
|
|
163
|
+
* chainId: 4217,
|
|
65
164
|
* })
|
|
66
165
|
* ```
|
|
67
166
|
*
|
|
68
|
-
* @param
|
|
167
|
+
* @param channel - Channel descriptor.
|
|
168
|
+
* @param options - Options.
|
|
69
169
|
* @returns The channel id.
|
|
70
170
|
*/
|
|
71
|
-
export function computeId(
|
|
72
|
-
|
|
171
|
+
export function computeId(
|
|
172
|
+
channel: computeId.Channel,
|
|
173
|
+
options: computeId.Options,
|
|
174
|
+
): Hex.Hex {
|
|
175
|
+
const channel_ = from(channel)
|
|
73
176
|
return Hash.keccak256(
|
|
74
177
|
AbiParameters.encode(channelIdParameters, [
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
178
|
+
channel_.payer,
|
|
179
|
+
channel_.payee,
|
|
180
|
+
channel_.operator,
|
|
181
|
+
channel_.token,
|
|
182
|
+
channel_.salt,
|
|
183
|
+
channel_.authorizedSigner,
|
|
184
|
+
channel_.expiringNonceHash,
|
|
82
185
|
address,
|
|
83
|
-
BigInt(
|
|
186
|
+
BigInt(options.chainId),
|
|
84
187
|
]),
|
|
85
188
|
)
|
|
86
189
|
}
|
|
87
190
|
|
|
88
191
|
export declare namespace computeId {
|
|
89
|
-
type
|
|
90
|
-
|
|
192
|
+
type Channel = from.Value
|
|
193
|
+
|
|
194
|
+
type Options = {
|
|
195
|
+
/** Chain ID used by the channel reserve precompile. */
|
|
91
196
|
chainId: number | bigint
|
|
92
197
|
}
|
|
93
198
|
|
|
94
199
|
type ErrorType =
|
|
95
200
|
| AbiParameters.encode.ErrorType
|
|
96
|
-
|
|
|
201
|
+
| from.ErrorType
|
|
97
202
|
| Hash.keccak256.ErrorType
|
|
98
203
|
}
|
|
99
204
|
|
|
@@ -188,3 +293,7 @@ export declare namespace getVoucherSignPayload {
|
|
|
188
293
|
| domainSeparator.ErrorType
|
|
189
294
|
| Hash.keccak256.ErrorType
|
|
190
295
|
}
|
|
296
|
+
|
|
297
|
+
function resolveAddress(address: Address.Address): Address.Address {
|
|
298
|
+
return Address.from(address)
|
|
299
|
+
}
|
package/tempo/index.ts
CHANGED
|
@@ -36,53 +36,32 @@ export type {}
|
|
|
36
36
|
*/
|
|
37
37
|
export * as AuthorizationTempo from './AuthorizationTempo.js'
|
|
38
38
|
/**
|
|
39
|
-
* TIP-20 channel reserve constants and deterministic hashing utilities.
|
|
39
|
+
* TIP-20 channel reserve descriptor, constants, and deterministic hashing utilities.
|
|
40
40
|
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
41
|
+
* Channel descriptors are emitted by `Channel.open` and then reused to settle,
|
|
42
|
+
* top up, close, request close, withdraw, or compute the channel ID. The channel
|
|
43
|
+
* reserve precompile exposes helper methods for channel identifiers, voucher sign
|
|
44
|
+
* payloads, and its EIP-712 domain separator. These utilities compute the same
|
|
45
|
+
* values locally when the chain id and channel fields are known.
|
|
44
46
|
*
|
|
45
47
|
* @example
|
|
46
48
|
* ```ts twoslash
|
|
47
49
|
* import { Channel } from 'ox/tempo'
|
|
48
50
|
*
|
|
49
|
-
* const
|
|
50
|
-
* authorizedSigner: '0x0000000000000000000000000000000000000000',
|
|
51
|
-
* chainId: 4217,
|
|
51
|
+
* const channel = Channel.from({
|
|
52
52
|
* expiringNonceHash: '0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
53
|
-
* operator: '0x0000000000000000000000000000000000000000',
|
|
54
53
|
* payee: '0x2222222222222222222222222222222222222222',
|
|
55
54
|
* payer: '0x1111111111111111111111111111111111111111',
|
|
56
55
|
* salt: '0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
57
56
|
* token: 1n,
|
|
58
57
|
* })
|
|
59
|
-
* ```
|
|
60
|
-
*
|
|
61
|
-
* @category Reference
|
|
62
|
-
*/
|
|
63
|
-
export * as Channel from './Channel.js'
|
|
64
|
-
/**
|
|
65
|
-
* TIP-20 channel reserve descriptor utilities.
|
|
66
58
|
*
|
|
67
|
-
*
|
|
68
|
-
* top up, close, request close, withdraw, or compute the channel ID.
|
|
69
|
-
*
|
|
70
|
-
* @example
|
|
71
|
-
* ```ts twoslash
|
|
72
|
-
* import { ChannelDescriptor } from 'ox/tempo'
|
|
73
|
-
*
|
|
74
|
-
* const descriptor = ChannelDescriptor.from({
|
|
75
|
-
* expiringNonceHash: '0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
76
|
-
* payee: '0x2222222222222222222222222222222222222222',
|
|
77
|
-
* payer: '0x1111111111111111111111111111111111111111',
|
|
78
|
-
* salt: '0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
79
|
-
* token: 1n,
|
|
80
|
-
* })
|
|
59
|
+
* const channelId = Channel.computeId(channel, { chainId: 4217 })
|
|
81
60
|
* ```
|
|
82
61
|
*
|
|
83
62
|
* @category Reference
|
|
84
63
|
*/
|
|
85
|
-
export * as
|
|
64
|
+
export * as Channel from './Channel.js'
|
|
86
65
|
/**
|
|
87
66
|
* Tempo key authorization utilities for provisioning and signing access keys.
|
|
88
67
|
*
|
package/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** @internal */
|
|
2
|
-
export const version = '0.14.
|
|
2
|
+
export const version = '0.14.25'
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.from = from;
|
|
4
|
-
const Address = require("../core/Address.js");
|
|
5
|
-
const TokenId = require("./TokenId.js");
|
|
6
|
-
const zeroAddress = '0x0000000000000000000000000000000000000000';
|
|
7
|
-
function from(value) {
|
|
8
|
-
const { authorizedSigner = zeroAddress, expiringNonceHash, operator = zeroAddress, payee, payer, salt, token, } = value;
|
|
9
|
-
return {
|
|
10
|
-
authorizedSigner: resolveAddress(authorizedSigner),
|
|
11
|
-
expiringNonceHash,
|
|
12
|
-
operator: resolveAddress(operator),
|
|
13
|
-
payee: resolveAddress(payee),
|
|
14
|
-
payer: resolveAddress(payer),
|
|
15
|
-
salt,
|
|
16
|
-
token: typeof token === 'string'
|
|
17
|
-
? resolveAddress(token)
|
|
18
|
-
: TokenId.toAddress(token),
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
function resolveAddress(address) {
|
|
22
|
-
return Address.from(address);
|
|
23
|
-
}
|
|
24
|
-
//# sourceMappingURL=ChannelDescriptor.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ChannelDescriptor.js","sourceRoot":"","sources":["../../tempo/ChannelDescriptor.ts"],"names":[],"mappings":";;AA4DA,oBAuBC;AAnFD,8CAA6C;AAG7C,wCAAuC;AAEvC,MAAM,WAAW,GACf,4CAA+E,CAAA;AAsDjF,SAAgB,IAAI,CAAC,KAAiB;IACpC,MAAM,EACJ,gBAAgB,GAAG,WAAW,EAC9B,iBAAiB,EACjB,QAAQ,GAAG,WAAW,EACtB,KAAK,EACL,KAAK,EACL,IAAI,EACJ,KAAK,GACN,GAAG,KAAK,CAAA;IAET,OAAO;QACL,gBAAgB,EAAE,cAAc,CAAC,gBAAgB,CAAC;QAClD,iBAAiB;QACjB,QAAQ,EAAE,cAAc,CAAC,QAAQ,CAAC;QAClC,KAAK,EAAE,cAAc,CAAC,KAAK,CAAC;QAC5B,KAAK,EAAE,cAAc,CAAC,KAAK,CAAC;QAC5B,IAAI;QACJ,KAAK,EACH,OAAO,KAAK,KAAK,QAAQ;YACvB,CAAC,CAAC,cAAc,CAAC,KAAK,CAAC;YACvB,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC;KAC/B,CAAA;AACH,CAAC;AA6BD,SAAS,cAAc,CAAC,OAAwB;IAC9C,OAAO,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;AAC9B,CAAC"}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import * as Address from '../core/Address.js';
|
|
2
|
-
import * as TokenId from './TokenId.js';
|
|
3
|
-
const zeroAddress = '0x0000000000000000000000000000000000000000';
|
|
4
|
-
/**
|
|
5
|
-
* Instantiates a TIP-20 channel reserve descriptor.
|
|
6
|
-
*
|
|
7
|
-
* Accepts a TIP-20 token ID or address, and defaults `operator` and
|
|
8
|
-
* `authorizedSigner` to the zero address.
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* ```ts twoslash
|
|
12
|
-
* import { ChannelDescriptor } from 'ox/tempo'
|
|
13
|
-
*
|
|
14
|
-
* const descriptor = ChannelDescriptor.from({
|
|
15
|
-
* expiringNonceHash: '0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
16
|
-
* payee: '0x2222222222222222222222222222222222222222',
|
|
17
|
-
* payer: '0x1111111111111111111111111111111111111111',
|
|
18
|
-
* salt: '0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
19
|
-
* token: 1n,
|
|
20
|
-
* })
|
|
21
|
-
* ```
|
|
22
|
-
*
|
|
23
|
-
* @param value - The descriptor input.
|
|
24
|
-
* @returns The normalized channel descriptor.
|
|
25
|
-
*/
|
|
26
|
-
export function from(value) {
|
|
27
|
-
const { authorizedSigner = zeroAddress, expiringNonceHash, operator = zeroAddress, payee, payer, salt, token, } = value;
|
|
28
|
-
return {
|
|
29
|
-
authorizedSigner: resolveAddress(authorizedSigner),
|
|
30
|
-
expiringNonceHash,
|
|
31
|
-
operator: resolveAddress(operator),
|
|
32
|
-
payee: resolveAddress(payee),
|
|
33
|
-
payer: resolveAddress(payer),
|
|
34
|
-
salt,
|
|
35
|
-
token: typeof token === 'string'
|
|
36
|
-
? resolveAddress(token)
|
|
37
|
-
: TokenId.toAddress(token),
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
function resolveAddress(address) {
|
|
41
|
-
return Address.from(address);
|
|
42
|
-
}
|
|
43
|
-
//# sourceMappingURL=ChannelDescriptor.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ChannelDescriptor.js","sourceRoot":"","sources":["../../tempo/ChannelDescriptor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,oBAAoB,CAAA;AAG7C,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AAEvC,MAAM,WAAW,GACf,4CAA+E,CAAA;AAgCjF;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,IAAI,CAAC,KAAiB;IACpC,MAAM,EACJ,gBAAgB,GAAG,WAAW,EAC9B,iBAAiB,EACjB,QAAQ,GAAG,WAAW,EACtB,KAAK,EACL,KAAK,EACL,IAAI,EACJ,KAAK,GACN,GAAG,KAAK,CAAA;IAET,OAAO;QACL,gBAAgB,EAAE,cAAc,CAAC,gBAAgB,CAAC;QAClD,iBAAiB;QACjB,QAAQ,EAAE,cAAc,CAAC,QAAQ,CAAC;QAClC,KAAK,EAAE,cAAc,CAAC,KAAK,CAAC;QAC5B,KAAK,EAAE,cAAc,CAAC,KAAK,CAAC;QAC5B,IAAI;QACJ,KAAK,EACH,OAAO,KAAK,KAAK,QAAQ;YACvB,CAAC,CAAC,cAAc,CAAC,KAAK,CAAC;YACvB,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC;KAC/B,CAAA;AACH,CAAC;AA6BD,SAAS,cAAc,CAAC,OAAwB;IAC9C,OAAO,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;AAC9B,CAAC"}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import * as Address from '../core/Address.js';
|
|
2
|
-
import type * as Errors from '../core/Errors.js';
|
|
3
|
-
import type * as Hex from '../core/Hex.js';
|
|
4
|
-
import * as TokenId from './TokenId.js';
|
|
5
|
-
/**
|
|
6
|
-
* TIP-20 channel reserve descriptor.
|
|
7
|
-
*
|
|
8
|
-
* Descriptors identify a channel without reading chain state. They are emitted
|
|
9
|
-
* by `open` and reused by `settle`, `topUp`, `close`, `requestClose`, and
|
|
10
|
-
* `withdraw`.
|
|
11
|
-
*/
|
|
12
|
-
export type ChannelDescriptor<addressType = Address.Address, tokenType = TokenId.TokenIdOrAddress<addressType>> = {
|
|
13
|
-
/** Account that funded the channel and receives refunds. */
|
|
14
|
-
payer: addressType;
|
|
15
|
-
/** Account that receives settled voucher payments. */
|
|
16
|
-
payee: addressType;
|
|
17
|
-
/** Optional relayer allowed to submit `settle` for the payee. */
|
|
18
|
-
operator: addressType;
|
|
19
|
-
/** TIP-20 token address held by the channel. */
|
|
20
|
-
token: tokenType;
|
|
21
|
-
/** User-supplied salt to distinguish otherwise identical channels. */
|
|
22
|
-
salt: Hex.Hex;
|
|
23
|
-
/** Optional signer for vouchers. Zero means `payer` signs. */
|
|
24
|
-
authorizedSigner: addressType;
|
|
25
|
-
/** Transaction-derived hash assigned when the channel was opened. */
|
|
26
|
-
expiringNonceHash: Hex.Hex;
|
|
27
|
-
};
|
|
28
|
-
/** Hex-address-normalized {@link ox#ChannelDescriptor.ChannelDescriptor}. */
|
|
29
|
-
export type Resolved = ChannelDescriptor<Address.Address, Address.Address>;
|
|
30
|
-
/**
|
|
31
|
-
* Instantiates a TIP-20 channel reserve descriptor.
|
|
32
|
-
*
|
|
33
|
-
* Accepts a TIP-20 token ID or address, and defaults `operator` and
|
|
34
|
-
* `authorizedSigner` to the zero address.
|
|
35
|
-
*
|
|
36
|
-
* @example
|
|
37
|
-
* ```ts twoslash
|
|
38
|
-
* import { ChannelDescriptor } from 'ox/tempo'
|
|
39
|
-
*
|
|
40
|
-
* const descriptor = ChannelDescriptor.from({
|
|
41
|
-
* expiringNonceHash: '0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
42
|
-
* payee: '0x2222222222222222222222222222222222222222',
|
|
43
|
-
* payer: '0x1111111111111111111111111111111111111111',
|
|
44
|
-
* salt: '0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
45
|
-
* token: 1n,
|
|
46
|
-
* })
|
|
47
|
-
* ```
|
|
48
|
-
*
|
|
49
|
-
* @param value - The descriptor input.
|
|
50
|
-
* @returns The normalized channel descriptor.
|
|
51
|
-
*/
|
|
52
|
-
export declare function from(value: from.Value): from.ReturnType;
|
|
53
|
-
export declare namespace from {
|
|
54
|
-
type Value = {
|
|
55
|
-
/** Account that funded the channel and receives refunds. */
|
|
56
|
-
payer: Address.Address;
|
|
57
|
-
/** Account that receives settled voucher payments. */
|
|
58
|
-
payee: Address.Address;
|
|
59
|
-
/** Optional relayer allowed to submit `settle` for the payee. */
|
|
60
|
-
operator?: Address.Address | undefined;
|
|
61
|
-
/** TIP-20 token address or ID held by the channel. */
|
|
62
|
-
token: TokenId.TokenIdOrAddress<Address.Address>;
|
|
63
|
-
/** User-supplied salt to distinguish otherwise identical channels. */
|
|
64
|
-
salt: Hex.Hex;
|
|
65
|
-
/** Optional signer for vouchers. Zero means `payer` signs. */
|
|
66
|
-
authorizedSigner?: Address.Address | undefined;
|
|
67
|
-
/** Transaction-derived hash assigned when the channel was opened. */
|
|
68
|
-
expiringNonceHash: Hex.Hex;
|
|
69
|
-
};
|
|
70
|
-
type ReturnType = Resolved;
|
|
71
|
-
type ErrorType = Address.from.ErrorType | Hex.concat.ErrorType | Hex.fromNumber.ErrorType | Errors.GlobalErrorType;
|
|
72
|
-
}
|
|
73
|
-
//# sourceMappingURL=ChannelDescriptor.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ChannelDescriptor.d.ts","sourceRoot":"","sources":["../../tempo/ChannelDescriptor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,oBAAoB,CAAA;AAC7C,OAAO,KAAK,KAAK,MAAM,MAAM,mBAAmB,CAAA;AAChD,OAAO,KAAK,KAAK,GAAG,MAAM,gBAAgB,CAAA;AAC1C,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AAKvC;;;;;;GAMG;AACH,MAAM,MAAM,iBAAiB,CAC3B,WAAW,GAAG,OAAO,CAAC,OAAO,EAC7B,SAAS,GAAG,OAAO,CAAC,gBAAgB,CAAC,WAAW,CAAC,IAC/C;IACF,4DAA4D;IAC5D,KAAK,EAAE,WAAW,CAAA;IAClB,sDAAsD;IACtD,KAAK,EAAE,WAAW,CAAA;IAClB,iEAAiE;IACjE,QAAQ,EAAE,WAAW,CAAA;IACrB,gDAAgD;IAChD,KAAK,EAAE,SAAS,CAAA;IAChB,sEAAsE;IACtE,IAAI,EAAE,GAAG,CAAC,GAAG,CAAA;IACb,8DAA8D;IAC9D,gBAAgB,EAAE,WAAW,CAAA;IAC7B,qEAAqE;IACrE,iBAAiB,EAAE,GAAG,CAAC,GAAG,CAAA;CAC3B,CAAA;AAED,6EAA6E;AAC7E,MAAM,MAAM,QAAQ,GAAG,iBAAiB,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,CAAA;AAE1E;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,UAAU,CAuBvD;AAED,MAAM,CAAC,OAAO,WAAW,IAAI,CAAC;IAC5B,KAAK,KAAK,GAAG;QACX,4DAA4D;QAC5D,KAAK,EAAE,OAAO,CAAC,OAAO,CAAA;QACtB,sDAAsD;QACtD,KAAK,EAAE,OAAO,CAAC,OAAO,CAAA;QACtB,iEAAiE;QACjE,QAAQ,CAAC,EAAE,OAAO,CAAC,OAAO,GAAG,SAAS,CAAA;QACtC,sDAAsD;QACtD,KAAK,EAAE,OAAO,CAAC,gBAAgB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;QAChD,sEAAsE;QACtE,IAAI,EAAE,GAAG,CAAC,GAAG,CAAA;QACb,8DAA8D;QAC9D,gBAAgB,CAAC,EAAE,OAAO,CAAC,OAAO,GAAG,SAAS,CAAA;QAC9C,qEAAqE;QACrE,iBAAiB,EAAE,GAAG,CAAC,GAAG,CAAA;KAC3B,CAAA;IAED,KAAK,UAAU,GAAG,QAAQ,CAAA;IAE1B,KAAK,SAAS,GACV,OAAO,CAAC,IAAI,CAAC,SAAS,GACtB,GAAG,CAAC,MAAM,CAAC,SAAS,GACpB,GAAG,CAAC,UAAU,CAAC,SAAS,GACxB,MAAM,CAAC,eAAe,CAAA;CAC3B"}
|