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
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import type { Address } from 'ox'
|
|
2
|
-
import { ChannelDescriptor } from 'ox/tempo'
|
|
3
|
-
import { describe, expect, test } from 'vitest'
|
|
4
|
-
|
|
5
|
-
describe('from', () => {
|
|
6
|
-
test('default', () => {
|
|
7
|
-
expect(
|
|
8
|
-
ChannelDescriptor.from({
|
|
9
|
-
authorizedSigner: '0x3333333333333333333333333333333333333333',
|
|
10
|
-
expiringNonceHash:
|
|
11
|
-
'0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
12
|
-
operator: '0x4444444444444444444444444444444444444444',
|
|
13
|
-
payee: '0x2222222222222222222222222222222222222222',
|
|
14
|
-
payer: '0x1111111111111111111111111111111111111111',
|
|
15
|
-
salt: '0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
16
|
-
token: 1n,
|
|
17
|
-
}),
|
|
18
|
-
).toMatchInlineSnapshot(`
|
|
19
|
-
{
|
|
20
|
-
"authorizedSigner": "0x3333333333333333333333333333333333333333",
|
|
21
|
-
"expiringNonceHash": "0x0000000000000000000000000000000000000000000000000000000000000002",
|
|
22
|
-
"operator": "0x4444444444444444444444444444444444444444",
|
|
23
|
-
"payee": "0x2222222222222222222222222222222222222222",
|
|
24
|
-
"payer": "0x1111111111111111111111111111111111111111",
|
|
25
|
-
"salt": "0x0000000000000000000000000000000000000000000000000000000000000001",
|
|
26
|
-
"token": "0x20c0000000000000000000000000000000000001",
|
|
27
|
-
}
|
|
28
|
-
`)
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
test('default values', () => {
|
|
32
|
-
expect(
|
|
33
|
-
ChannelDescriptor.from({
|
|
34
|
-
expiringNonceHash:
|
|
35
|
-
'0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
36
|
-
payee: '0x2222222222222222222222222222222222222222',
|
|
37
|
-
payer: '0x1111111111111111111111111111111111111111',
|
|
38
|
-
salt: '0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
39
|
-
token: 1n,
|
|
40
|
-
}),
|
|
41
|
-
).toMatchInlineSnapshot(`
|
|
42
|
-
{
|
|
43
|
-
"authorizedSigner": "0x0000000000000000000000000000000000000000",
|
|
44
|
-
"expiringNonceHash": "0x0000000000000000000000000000000000000000000000000000000000000002",
|
|
45
|
-
"operator": "0x0000000000000000000000000000000000000000",
|
|
46
|
-
"payee": "0x2222222222222222222222222222222222222222",
|
|
47
|
-
"payer": "0x1111111111111111111111111111111111111111",
|
|
48
|
-
"salt": "0x0000000000000000000000000000000000000000000000000000000000000001",
|
|
49
|
-
"token": "0x20c0000000000000000000000000000000000001",
|
|
50
|
-
}
|
|
51
|
-
`)
|
|
52
|
-
})
|
|
53
|
-
|
|
54
|
-
test('token address input', () => {
|
|
55
|
-
expect(
|
|
56
|
-
ChannelDescriptor.from({
|
|
57
|
-
authorizedSigner: '0x3333333333333333333333333333333333333333',
|
|
58
|
-
expiringNonceHash:
|
|
59
|
-
'0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
60
|
-
operator: '0x4444444444444444444444444444444444444444',
|
|
61
|
-
payee: '0x2222222222222222222222222222222222222222',
|
|
62
|
-
payer: '0x1111111111111111111111111111111111111111',
|
|
63
|
-
salt: '0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
64
|
-
token: '0x20c0000000000000000000000000000000000001',
|
|
65
|
-
}),
|
|
66
|
-
).toMatchInlineSnapshot(`
|
|
67
|
-
{
|
|
68
|
-
"authorizedSigner": "0x3333333333333333333333333333333333333333",
|
|
69
|
-
"expiringNonceHash": "0x0000000000000000000000000000000000000000000000000000000000000002",
|
|
70
|
-
"operator": "0x4444444444444444444444444444444444444444",
|
|
71
|
-
"payee": "0x2222222222222222222222222222222222222222",
|
|
72
|
-
"payer": "0x1111111111111111111111111111111111111111",
|
|
73
|
-
"salt": "0x0000000000000000000000000000000000000000000000000000000000000001",
|
|
74
|
-
"token": "0x20c0000000000000000000000000000000000001",
|
|
75
|
-
}
|
|
76
|
-
`)
|
|
77
|
-
})
|
|
78
|
-
|
|
79
|
-
test('return type', () => {
|
|
80
|
-
const descriptor = ChannelDescriptor.from({
|
|
81
|
-
expiringNonceHash:
|
|
82
|
-
'0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
83
|
-
payee: '0x2222222222222222222222222222222222222222',
|
|
84
|
-
payer: '0x1111111111111111111111111111111111111111',
|
|
85
|
-
salt: '0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
86
|
-
token: 1n,
|
|
87
|
-
})
|
|
88
|
-
|
|
89
|
-
descriptor satisfies ChannelDescriptor.Resolved
|
|
90
|
-
descriptor.payer satisfies Address.Address
|
|
91
|
-
descriptor.token satisfies Address.Address
|
|
92
|
-
})
|
|
93
|
-
})
|
|
@@ -1,115 +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
|
-
const zeroAddress =
|
|
7
|
-
'0x0000000000000000000000000000000000000000' as const satisfies Address.Address
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* TIP-20 channel reserve descriptor.
|
|
11
|
-
*
|
|
12
|
-
* Descriptors identify a channel without reading chain state. They are emitted
|
|
13
|
-
* by `open` and reused by `settle`, `topUp`, `close`, `requestClose`, and
|
|
14
|
-
* `withdraw`.
|
|
15
|
-
*/
|
|
16
|
-
export type ChannelDescriptor<
|
|
17
|
-
addressType = Address.Address,
|
|
18
|
-
tokenType = TokenId.TokenIdOrAddress<addressType>,
|
|
19
|
-
> = {
|
|
20
|
-
/** Account that funded the channel and receives refunds. */
|
|
21
|
-
payer: addressType
|
|
22
|
-
/** Account that receives settled voucher payments. */
|
|
23
|
-
payee: addressType
|
|
24
|
-
/** Optional relayer allowed to submit `settle` for the payee. */
|
|
25
|
-
operator: addressType
|
|
26
|
-
/** TIP-20 token address held by the channel. */
|
|
27
|
-
token: tokenType
|
|
28
|
-
/** User-supplied salt to distinguish otherwise identical channels. */
|
|
29
|
-
salt: Hex.Hex
|
|
30
|
-
/** Optional signer for vouchers. Zero means `payer` signs. */
|
|
31
|
-
authorizedSigner: addressType
|
|
32
|
-
/** Transaction-derived hash assigned when the channel was opened. */
|
|
33
|
-
expiringNonceHash: Hex.Hex
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/** Hex-address-normalized {@link ox#ChannelDescriptor.ChannelDescriptor}. */
|
|
37
|
-
export type Resolved = ChannelDescriptor<Address.Address, Address.Address>
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Instantiates a TIP-20 channel reserve descriptor.
|
|
41
|
-
*
|
|
42
|
-
* Accepts a TIP-20 token ID or address, and defaults `operator` and
|
|
43
|
-
* `authorizedSigner` to the zero address.
|
|
44
|
-
*
|
|
45
|
-
* @example
|
|
46
|
-
* ```ts twoslash
|
|
47
|
-
* import { ChannelDescriptor } from 'ox/tempo'
|
|
48
|
-
*
|
|
49
|
-
* const descriptor = ChannelDescriptor.from({
|
|
50
|
-
* expiringNonceHash: '0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
51
|
-
* payee: '0x2222222222222222222222222222222222222222',
|
|
52
|
-
* payer: '0x1111111111111111111111111111111111111111',
|
|
53
|
-
* salt: '0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
54
|
-
* token: 1n,
|
|
55
|
-
* })
|
|
56
|
-
* ```
|
|
57
|
-
*
|
|
58
|
-
* @param value - The descriptor input.
|
|
59
|
-
* @returns The normalized channel descriptor.
|
|
60
|
-
*/
|
|
61
|
-
export function from(value: from.Value): from.ReturnType {
|
|
62
|
-
const {
|
|
63
|
-
authorizedSigner = zeroAddress,
|
|
64
|
-
expiringNonceHash,
|
|
65
|
-
operator = zeroAddress,
|
|
66
|
-
payee,
|
|
67
|
-
payer,
|
|
68
|
-
salt,
|
|
69
|
-
token,
|
|
70
|
-
} = value
|
|
71
|
-
|
|
72
|
-
return {
|
|
73
|
-
authorizedSigner: resolveAddress(authorizedSigner),
|
|
74
|
-
expiringNonceHash,
|
|
75
|
-
operator: resolveAddress(operator),
|
|
76
|
-
payee: resolveAddress(payee),
|
|
77
|
-
payer: resolveAddress(payer),
|
|
78
|
-
salt,
|
|
79
|
-
token:
|
|
80
|
-
typeof token === 'string'
|
|
81
|
-
? resolveAddress(token)
|
|
82
|
-
: TokenId.toAddress(token),
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export declare namespace from {
|
|
87
|
-
type Value = {
|
|
88
|
-
/** Account that funded the channel and receives refunds. */
|
|
89
|
-
payer: Address.Address
|
|
90
|
-
/** Account that receives settled voucher payments. */
|
|
91
|
-
payee: Address.Address
|
|
92
|
-
/** Optional relayer allowed to submit `settle` for the payee. */
|
|
93
|
-
operator?: Address.Address | undefined
|
|
94
|
-
/** TIP-20 token address or ID held by the channel. */
|
|
95
|
-
token: TokenId.TokenIdOrAddress<Address.Address>
|
|
96
|
-
/** User-supplied salt to distinguish otherwise identical channels. */
|
|
97
|
-
salt: Hex.Hex
|
|
98
|
-
/** Optional signer for vouchers. Zero means `payer` signs. */
|
|
99
|
-
authorizedSigner?: Address.Address | undefined
|
|
100
|
-
/** Transaction-derived hash assigned when the channel was opened. */
|
|
101
|
-
expiringNonceHash: Hex.Hex
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
type ReturnType = Resolved
|
|
105
|
-
|
|
106
|
-
type ErrorType =
|
|
107
|
-
| Address.from.ErrorType
|
|
108
|
-
| Hex.concat.ErrorType
|
|
109
|
-
| Hex.fromNumber.ErrorType
|
|
110
|
-
| Errors.GlobalErrorType
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
function resolveAddress(address: Address.Address): Address.Address {
|
|
114
|
-
return Address.from(address)
|
|
115
|
-
}
|