8
8
import { EMPTY_ADDRESS } from './consts.js'
9
9
import { LegacyRegistrationInvalidConfigError } from '../errors/register.js'
10
10
11
- export type LegacyRegistrationBaseParameters = {
11
+ export type LegacyRegistrationParameters = {
12
12
/** Name to register */
13
13
name : string
14
14
/** Address to set owner to */
@@ -24,15 +24,11 @@ export type LegacyRegistrationBaseParameters = {
24
24
}
25
25
26
26
export type LegacyRegistrationWithConfigParameters =
27
- LegacyRegistrationBaseParameters & {
27
+ LegacyRegistrationParameters & {
28
28
resolverAddress : Address
29
29
address ?: Address
30
30
}
31
31
32
- export type LegacyRegistrationParameters =
33
- | LegacyRegistrationBaseParameters
34
- | LegacyRegistrationWithConfigParameters
35
-
36
32
export const isLegacyRegistrationWithConfig = (
37
33
params : LegacyRegistrationParameters ,
38
34
) : params is LegacyRegistrationWithConfigParameters => {
@@ -47,67 +43,79 @@ export const isLegacyRegistrationWithConfig = (
47
43
return resolverAddress !== EMPTY_ADDRESS || address !== EMPTY_ADDRESS
48
44
}
49
45
50
- export type LegacyCommitmentTuple =
51
- | [ label : string , owner : Address , secret : Hex ]
52
- | [
53
- label : string ,
54
- owner : Address ,
55
- resolverAddress : Address ,
56
- address : Address ,
57
- secret : Hex ,
58
- ]
59
-
60
- export type LegacyRegistrationTuple =
61
- | [ label : string , owner : Address , duration : bigint , secret : Hex ]
62
- | [
63
- label : string ,
64
- owner : Address ,
65
- duration : bigint ,
66
- secret : Hex ,
67
- resolverAddress : Address ,
68
- address : Address ,
69
- ]
46
+ export type LegacyCommitmentTuple = [ label : string , owner : Address , secret : Hex ]
47
+
48
+ export type LegacyCommitmentWithConfigTuple = [
49
+ label : string ,
50
+ owner : Address ,
51
+ resolverAddress : Address ,
52
+ address : Address ,
53
+ secret : Hex ,
54
+ ]
55
+
56
+ export type LegacyRegistrationTuple = [
57
+ label : string ,
58
+ owner : Address ,
59
+ duration : bigint ,
60
+ secret : Hex ,
61
+ ]
62
+
63
+ export type LegacyRegistrationWithConfigTuple = [
64
+ label : string ,
65
+ owner : Address ,
66
+ duration : bigint ,
67
+ secret : Hex ,
68
+ resolverAddress : Address ,
69
+ address : Address ,
70
+ ]
70
71
71
72
export const makeLegacyCommitmentTuple = (
72
73
params : LegacyRegistrationParameters ,
73
74
) : LegacyCommitmentTuple => {
74
- const {
75
- name,
76
- owner,
77
- secret,
78
- resolverAddress = EMPTY_ADDRESS ,
79
- address = EMPTY_ADDRESS ,
80
- } = params as LegacyRegistrationWithConfigParameters
81
-
75
+ const { name, owner, secret } = params
82
76
const label = name . split ( '.' ) [ 0 ]
83
-
84
- if ( isLegacyRegistrationWithConfig ( params ) ) {
85
- return [ label , owner , secret , resolverAddress , address ]
86
- }
87
77
return [ label , owner , secret ]
88
78
}
89
79
90
- export const makeLegacyRegistrationTuple = (
91
- params : LegacyRegistrationParameters ,
92
- ) : LegacyRegistrationTuple => {
80
+ export const makeLegacyCommitmentWithConfigTuple = (
81
+ params : LegacyRegistrationWithConfigParameters ,
82
+ ) : LegacyCommitmentWithConfigTuple => {
93
83
const {
94
84
name,
95
85
owner,
96
86
secret,
97
- duration,
98
87
resolverAddress = EMPTY_ADDRESS ,
99
88
address = EMPTY_ADDRESS ,
100
89
} = params as LegacyRegistrationWithConfigParameters
101
90
const label = name . split ( '.' ) [ 0 ]
102
- if ( isLegacyRegistrationWithConfig ( params ) )
103
- return [ label , owner , BigInt ( duration ) , secret , resolverAddress , address ]
104
- return [ label , owner , BigInt ( params . duration ) , secret ]
91
+ return [ label , owner , secret , resolverAddress , address ]
92
+ }
93
+
94
+ export const makeLegacyRegistrationTuple = ( {
95
+ name,
96
+ owner,
97
+ secret,
98
+ duration,
99
+ } : LegacyRegistrationParameters ) : LegacyRegistrationTuple => {
100
+ const label = name . split ( '.' ) [ 0 ]
101
+ return [ label , owner , BigInt ( duration ) , secret ]
105
102
}
106
103
107
- export const makeLegacyCommitmentFromTuple = ( [
108
- label ,
109
- ...others
110
- ] : LegacyCommitmentTuple ) : Hex => {
104
+ export const makeLegacyRegistrationWithConfigTuple = ( {
105
+ name,
106
+ owner,
107
+ secret,
108
+ duration,
109
+ resolverAddress,
110
+ address = EMPTY_ADDRESS ,
111
+ } : LegacyRegistrationWithConfigParameters ) : LegacyRegistrationWithConfigTuple => {
112
+ const label = name . split ( '.' ) [ 0 ]
113
+ return [ label , owner , BigInt ( duration ) , secret , resolverAddress , address ]
114
+ }
115
+
116
+ export const makeLegacyCommitmentFromTuple = ( [ label , ...others ] :
117
+ | LegacyCommitmentTuple
118
+ | LegacyCommitmentWithConfigTuple ) : Hex => {
111
119
const labelHash = labelhash ( label )
112
120
const params = [ labelHash , ...others ] as const
113
121
@@ -130,5 +138,10 @@ export const makeLegacyCommitmentFromTuple = ([
130
138
}
131
139
132
140
export const makeLegacyCommitment = (
133
- params : LegacyRegistrationParameters ,
134
- ) : Hex => makeLegacyCommitmentFromTuple ( makeLegacyCommitmentTuple ( params ) )
141
+ params : LegacyRegistrationParameters | LegacyRegistrationWithConfigParameters ,
142
+ ) : Hex => {
143
+ const touple = isLegacyRegistrationWithConfig ( params )
144
+ ? makeLegacyCommitmentWithConfigTuple ( params )
145
+ : makeLegacyCommitmentTuple ( params )
146
+ return makeLegacyCommitmentFromTuple ( touple )
147
+ }
0 commit comments