@@ -43,83 +43,85 @@ export const collectPaymentsTypes = {
43
43
] ,
44
44
}
45
45
46
- export const createSignedCancellationRequest = async (
47
- agreementId : string ,
48
- wallet : Wallet ,
49
- ) : Promise < Uint8Array > => {
50
- const signature = await wallet . _signTypedData (
51
- cancelAgreementDomain ,
52
- cancelAgreementTypes ,
53
- { agreement_id : agreementId } ,
54
- )
55
- return arrayify (
56
- defaultAbiCoder . encode ( [ 'tuple(bytes16)' , 'bytes' ] , [ [ agreementId ] , signature ] ) ,
57
- )
58
- }
59
-
60
- export const createSignedCollectionRequest = async (
61
- agreementId : string ,
62
- allocationId : string ,
63
- entityCount : number ,
64
- wallet : Wallet ,
65
- ) : Promise < Uint8Array > => {
66
- const signature = await wallet . _signTypedData (
67
- collectPaymentsDomain ,
68
- collectPaymentsTypes ,
69
- {
70
- agreement_id : agreementId ,
71
- allocation_id : toAddress ( allocationId ) ,
72
- entity_count : entityCount ,
73
- } ,
74
- )
75
- return arrayify (
76
- defaultAbiCoder . encode (
77
- [ 'tuple(bytes16, address, uint64)' , 'bytes' ] ,
78
- [ [ agreementId , toAddress ( allocationId ) , entityCount ] , signature ] ,
79
- ) ,
80
- )
81
- }
82
-
83
- export const decodeTapReceipt = ( receipt : Uint8Array , verifyingContract : string ) => {
84
- const [ message , signature ] = defaultAbiCoder . decode (
85
- [ 'tuple(address,uint64,uint64,uint128)' , 'bytes' ] ,
86
- receipt ,
87
- )
88
-
89
- const [ allocationId , timestampNs , nonce , value ] = message
90
-
91
- // Recover the signer address from the signature
92
- // compute the EIP-712 digest of the message
93
- const domain = {
94
- name : 'TAP' ,
95
- version : '1' ,
96
- chainId : chainId ,
97
- verifyingContract,
46
+ export class GatewayDipsServiceMessages {
47
+ static createSignedCancellationRequest = async (
48
+ agreementId : string ,
49
+ wallet : Wallet ,
50
+ ) : Promise < Uint8Array > => {
51
+ const signature = await wallet . _signTypedData (
52
+ cancelAgreementDomain ,
53
+ cancelAgreementTypes ,
54
+ { agreement_id : agreementId } ,
55
+ )
56
+ return arrayify (
57
+ defaultAbiCoder . encode ( [ 'tuple(bytes16)' , 'bytes' ] , [ [ agreementId ] , signature ] ) ,
58
+ )
98
59
}
99
60
100
- const types = {
101
- Receipt : [
102
- { name : 'allocation_id' , type : 'address' } ,
103
- { name : 'timestamp_ns' , type : 'uint64' } ,
104
- { name : 'nonce' , type : 'uint64' } ,
105
- { name : 'value' , type : 'uint128' } ,
106
- ] ,
61
+ static createSignedCollectionRequest = async (
62
+ agreementId : string ,
63
+ allocationId : string ,
64
+ entityCount : number ,
65
+ wallet : Wallet ,
66
+ ) : Promise < Uint8Array > => {
67
+ const signature = await wallet . _signTypedData (
68
+ collectPaymentsDomain ,
69
+ collectPaymentsTypes ,
70
+ {
71
+ agreement_id : agreementId ,
72
+ allocation_id : toAddress ( allocationId ) ,
73
+ entity_count : entityCount ,
74
+ } ,
75
+ )
76
+ return arrayify (
77
+ defaultAbiCoder . encode (
78
+ [ 'tuple(bytes16, address, uint64)' , 'bytes' ] ,
79
+ [ [ agreementId , toAddress ( allocationId ) , entityCount ] , signature ] ,
80
+ ) ,
81
+ )
107
82
}
108
83
109
- const digest = _TypedDataEncoder . hash ( domain , types , {
110
- allocation_id : allocationId ,
111
- timestamp_ns : timestampNs ,
112
- nonce : nonce ,
113
- value : value ,
114
- } )
115
- const signerAddress = recoverAddress ( digest , signature )
116
- return {
117
- allocation_id : toAddress ( allocationId ) ,
118
- signer_address : toAddress ( signerAddress ) ,
119
- signature : signature ,
120
- timestamp_ns : timestampNs ,
121
- nonce : nonce ,
122
- value : value ,
84
+ static decodeTapReceipt = ( receipt : Uint8Array , verifyingContract : string ) => {
85
+ const [ message , signature ] = defaultAbiCoder . decode (
86
+ [ 'tuple(address,uint64,uint64,uint128)' , 'bytes' ] ,
87
+ receipt ,
88
+ )
89
+
90
+ const [ allocationId , timestampNs , nonce , value ] = message
91
+
92
+ // Recover the signer address from the signature
93
+ // compute the EIP-712 digest of the message
94
+ const domain = {
95
+ name : 'TAP' ,
96
+ version : '1' ,
97
+ chainId : chainId ,
98
+ verifyingContract,
99
+ }
100
+
101
+ const types = {
102
+ Receipt : [
103
+ { name : 'allocation_id' , type : 'address' } ,
104
+ { name : 'timestamp_ns' , type : 'uint64' } ,
105
+ { name : 'nonce' , type : 'uint64' } ,
106
+ { name : 'value' , type : 'uint128' } ,
107
+ ] ,
108
+ }
109
+
110
+ const digest = _TypedDataEncoder . hash ( domain , types , {
111
+ allocation_id : allocationId ,
112
+ timestamp_ns : timestampNs ,
113
+ nonce : nonce ,
114
+ value : value ,
115
+ } )
116
+ const signerAddress = recoverAddress ( digest , signature )
117
+ return {
118
+ allocation_id : toAddress ( allocationId ) ,
119
+ signer_address : toAddress ( signerAddress ) ,
120
+ signature : signature ,
121
+ timestamp_ns : timestampNs ,
122
+ nonce : nonce ,
123
+ value : value ,
124
+ }
123
125
}
124
126
}
125
127
0 commit comments