@@ -3,9 +3,13 @@ import { ethers } from "ethers";
3
3
import {
4
4
IGroupInfo ,
5
5
IGroupInfoUnresolved ,
6
- TransactionType
6
+ TransactionType ,
7
7
} from "../interfaces" ;
8
- import { IPrivacyGroup , IPrivacyGroupEVMCall , IPrivacyGroupEVMTXInput } from "../interfaces/privacygroups" ;
8
+ import {
9
+ IPrivacyGroup ,
10
+ IPrivacyGroupEVMCall ,
11
+ IPrivacyGroupEVMTXInput ,
12
+ } from "../interfaces/privacygroups" ;
9
13
import PaladinClient from "../paladin" ;
10
14
import { PaladinVerifier } from "../verifier" ;
11
15
import * as penteJSON from "./abis/PentePrivacyGroup.json" ;
@@ -31,10 +35,10 @@ export interface PenteContractTransactionInput {
31
35
32
36
export interface PenteDeploy {
33
37
abi : ReadonlyArray < ethers . JsonFragment > ;
34
- bytecode : string ,
38
+ bytecode : string ;
35
39
from : string ;
36
40
inputs ?: any ;
37
- }
41
+ }
38
42
39
43
export interface PenteOptions {
40
44
pollTimeout ?: number ;
@@ -50,14 +54,14 @@ export const penteGroupABI = {
50
54
} ;
51
55
52
56
export interface PentePrivacyGroupParams {
53
- members : ( string | PaladinVerifier ) [ ]
57
+ members : ( string | PaladinVerifier ) [ ] ;
54
58
salt ?: string ;
55
59
evmVersion ?: string ;
56
60
endorsementType ?: string ;
57
- externalCallsEnabled ?: boolean ;
61
+ externalCallsEnabled ?: boolean ;
58
62
additionalProperties ?: {
59
63
[ x : string ] : unknown ;
60
- }
64
+ } ;
61
65
}
62
66
63
67
export interface PenteApproveTransitionParams {
@@ -103,32 +107,33 @@ export class PenteFactory {
103
107
}
104
108
105
109
async newPrivacyGroup ( input : PentePrivacyGroupParams ) {
106
-
107
110
const group = await this . paladin . createPrivacyGroup ( {
108
111
domain : this . domain ,
109
- members : input . members . map ( m => m . toString ( ) ) ,
112
+ members : input . members . map ( ( m ) => m . toString ( ) ) ,
110
113
configuration : {
111
114
evmVersion : input . evmVersion ,
112
115
endorsementType : input . endorsementType ,
113
- externalCallsEnabled : input . externalCallsEnabled === true ? 'true' : input . externalCallsEnabled === false ? 'false' : undefined ,
114
- }
116
+ externalCallsEnabled :
117
+ input . externalCallsEnabled === true
118
+ ? "true"
119
+ : input . externalCallsEnabled === false
120
+ ? "false"
121
+ : undefined ,
122
+ } ,
115
123
} ) ;
116
- const receipt = group . genesisTransaction ? await this . paladin . pollForReceipt (
117
- group . genesisTransaction ,
118
- this . options . pollTimeout
119
- ) : undefined ;
124
+ const receipt = group . genesisTransaction
125
+ ? await this . paladin . pollForReceipt (
126
+ group . genesisTransaction ,
127
+ this . options . pollTimeout
128
+ )
129
+ : undefined ;
120
130
group . contractAddress = receipt ? receipt . contractAddress : undefined ;
121
131
return group . contractAddress === undefined
122
132
? undefined
123
- : new PentePrivacyGroup (
124
- this . paladin ,
125
- group ,
126
- this . options
127
- ) ;
133
+ : new PentePrivacyGroup ( this . paladin , group , this . options ) ;
128
134
}
129
135
}
130
136
131
-
132
137
export class PentePrivacyGroup {
133
138
private options : Required < PenteOptions > ;
134
139
public readonly address : string ;
@@ -141,7 +146,9 @@ export class PentePrivacyGroup {
141
146
options ?: PenteOptions
142
147
) {
143
148
if ( group . contractAddress === undefined ) {
144
- throw new Error ( `Supplied group '${ group . id } ' is missing a contract address. Check transaction ${ group . genesisTransaction } ` ) ;
149
+ throw new Error (
150
+ `Supplied group '${ group . id } ' is missing a contract address. Check transaction ${ group . genesisTransaction } `
151
+ ) ;
145
152
}
146
153
this . address = group . contractAddress ;
147
154
this . salt = group . id ; // when bypassing privacy group helper functionality, and directly building Pente private transactions
@@ -153,18 +160,17 @@ export class PentePrivacyGroup {
153
160
}
154
161
155
162
using ( paladin : PaladinClient ) {
156
- return new PentePrivacyGroup (
157
- paladin ,
158
- this . group ,
159
- this . options
160
- ) ;
163
+ return new PentePrivacyGroup ( paladin , this . group , this . options ) ;
161
164
}
162
-
163
- async deploy ( params : PenteDeploy , txOptions ?: Partial < IPrivacyGroupEVMTXInput > ) {
164
165
166
+ async deploy (
167
+ params : PenteDeploy ,
168
+ txOptions ?: Partial < IPrivacyGroupEVMTXInput >
169
+ ) {
165
170
// Find the constructor in the ABI
166
- const constructor : ethers . JsonFragment = params . abi . find ( ( entry ) => entry . type === "constructor" ) ||
167
- { type : "constructor" , inputs : [ ] } ;
171
+ const constructor : ethers . JsonFragment = params . abi . find (
172
+ ( entry ) => entry . type === "constructor"
173
+ ) || { type : "constructor" , inputs : [ ] } ;
168
174
169
175
const transaction : IPrivacyGroupEVMTXInput = {
170
176
...txOptions ,
@@ -173,8 +179,8 @@ export class PentePrivacyGroup {
173
179
from : params . from ,
174
180
input : params . inputs ,
175
181
bytecode : params . bytecode ,
176
- function : constructor ,
177
- }
182
+ function : constructor ,
183
+ } ;
178
184
179
185
const txID = await this . paladin . sendPrivacyGroupTransaction ( transaction ) ;
180
186
const receipt = await this . paladin . pollForReceipt (
@@ -189,7 +195,10 @@ export class PentePrivacyGroup {
189
195
}
190
196
191
197
// sendTransaction functions in the contract (write)
192
- async sendTransaction ( transaction : PenteGroupTransactionInput , txOptions ?: Partial < IPrivacyGroupEVMTXInput > ) {
198
+ async sendTransaction (
199
+ transaction : PenteGroupTransactionInput ,
200
+ txOptions ?: Partial < IPrivacyGroupEVMTXInput >
201
+ ) {
193
202
const txID = await this . paladin . sendPrivacyGroupTransaction ( {
194
203
...txOptions ,
195
204
domain : this . group . domain ,
@@ -199,11 +208,14 @@ export class PentePrivacyGroup {
199
208
input : transaction . data ,
200
209
function : transaction . methodAbi ,
201
210
} ) ;
202
- return this . paladin . pollForReceipt ( txID , this . options . pollTimeout ) ;
211
+ return this . paladin . pollForReceipt ( txID , this . options . pollTimeout ) ;
203
212
}
204
213
205
214
// call functions in the contract (read-only)
206
- async call ( transaction : PenteGroupTransactionInput , txOptions ?: Partial < IPrivacyGroupEVMCall > ) {
215
+ async call (
216
+ transaction : PenteGroupTransactionInput ,
217
+ txOptions ?: Partial < IPrivacyGroupEVMCall >
218
+ ) {
207
219
return this . paladin . callPrivacyGroup ( {
208
220
...txOptions ,
209
221
domain : this . group . domain ,
@@ -229,44 +241,58 @@ export class PentePrivacyGroup {
229
241
} ) ;
230
242
return this . paladin . pollForReceipt ( txID , this . options . pollTimeout ) ;
231
243
}
232
-
233
244
}
234
245
235
246
export abstract class PentePrivateContract < ConstructorParams > {
236
247
constructor (
237
248
protected evm : PentePrivacyGroup ,
238
249
protected abi : ReadonlyArray < ethers . JsonFragment > ,
239
250
public readonly address : string
240
- ) {
241
- }
251
+ ) { }
242
252
243
253
abstract using (
244
254
paladin : PaladinClient
245
255
) : PentePrivateContract < ConstructorParams > ;
246
256
247
- async sendTransaction ( transaction : PenteContractTransactionInput , txOptions ?: Partial < IPrivacyGroupEVMTXInput > ) {
248
- const method = this . abi . find ( ( entry ) => entry . name === transaction . function ) ;
257
+ async sendTransaction (
258
+ transaction : PenteContractTransactionInput ,
259
+ txOptions ?: Partial < IPrivacyGroupEVMTXInput >
260
+ ) {
261
+ const method = this . abi . find (
262
+ ( entry ) => entry . name === transaction . function
263
+ ) ;
249
264
if ( method === undefined ) {
250
265
throw new Error ( `Method '${ transaction . function } ' not found` ) ;
251
266
}
252
- return this . evm . sendTransaction ( {
253
- from : transaction . from ,
254
- to : this . address ,
255
- methodAbi : method ,
256
- data : transaction . data ?? [ ]
257
- } , txOptions ) ;
267
+ return this . evm . sendTransaction (
268
+ {
269
+ from : transaction . from ,
270
+ to : this . address ,
271
+ methodAbi : method ,
272
+ data : transaction . data ?? [ ] ,
273
+ } ,
274
+ txOptions
275
+ ) ;
258
276
}
259
277
260
- async call ( transaction : PenteContractTransactionInput , txOptions ?: Partial < IPrivacyGroupEVMCall > ) {
261
- const method = this . abi . find ( ( entry ) => entry . name === transaction . function ) ;
278
+ async call (
279
+ transaction : PenteContractTransactionInput ,
280
+ txOptions ?: Partial < IPrivacyGroupEVMCall >
281
+ ) {
282
+ const method = this . abi . find (
283
+ ( entry ) => entry . name === transaction . function
284
+ ) ;
262
285
if ( method === undefined ) {
263
286
throw new Error ( `Method '${ transaction . function } ' not found` ) ;
264
287
}
265
- return this . evm . call ( {
266
- from : transaction . from ,
267
- to : this . address ,
268
- methodAbi : method ,
269
- data : transaction . data ?? [ ]
270
- } , txOptions ) ;
288
+ return this . evm . call (
289
+ {
290
+ from : transaction . from ,
291
+ to : this . address ,
292
+ methodAbi : method ,
293
+ data : transaction . data ?? [ ] ,
294
+ } ,
295
+ txOptions
296
+ ) ;
271
297
}
272
298
}
0 commit comments