Skip to content

Commit f163c0c

Browse files
authored
Merge pull request #609 from LF-Decentralized-Trust-labs/pgroup_lookup
sdk: add methods for looking up privacy groups
2 parents 22c2477 + d0f0301 commit f163c0c

File tree

2 files changed

+97
-55
lines changed

2 files changed

+97
-55
lines changed

sdk/typescript/src/domains/pente.ts

Lines changed: 81 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@ import { ethers } from "ethers";
33
import {
44
IGroupInfo,
55
IGroupInfoUnresolved,
6-
TransactionType
6+
TransactionType,
77
} from "../interfaces";
8-
import { IPrivacyGroup, IPrivacyGroupEVMCall, IPrivacyGroupEVMTXInput } from "../interfaces/privacygroups";
8+
import {
9+
IPrivacyGroup,
10+
IPrivacyGroupEVMCall,
11+
IPrivacyGroupEVMTXInput,
12+
} from "../interfaces/privacygroups";
913
import PaladinClient from "../paladin";
1014
import { PaladinVerifier } from "../verifier";
1115
import * as penteJSON from "./abis/PentePrivacyGroup.json";
@@ -31,10 +35,10 @@ export interface PenteContractTransactionInput {
3135

3236
export interface PenteDeploy {
3337
abi: ReadonlyArray<ethers.JsonFragment>;
34-
bytecode: string,
38+
bytecode: string;
3539
from: string;
3640
inputs?: any;
37-
}
41+
}
3842

3943
export interface PenteOptions {
4044
pollTimeout?: number;
@@ -50,14 +54,14 @@ export const penteGroupABI = {
5054
};
5155

5256
export interface PentePrivacyGroupParams {
53-
members: (string | PaladinVerifier)[]
57+
members: (string | PaladinVerifier)[];
5458
salt?: string;
5559
evmVersion?: string;
5660
endorsementType?: string;
57-
externalCallsEnabled?: boolean;
61+
externalCallsEnabled?: boolean;
5862
additionalProperties?: {
5963
[x: string]: unknown;
60-
}
64+
};
6165
}
6266

6367
export interface PenteApproveTransitionParams {
@@ -103,32 +107,33 @@ export class PenteFactory {
103107
}
104108

105109
async newPrivacyGroup(input: PentePrivacyGroupParams) {
106-
107110
const group = await this.paladin.createPrivacyGroup({
108111
domain: this.domain,
109-
members: input.members.map(m => m.toString()),
112+
members: input.members.map((m) => m.toString()),
110113
configuration: {
111114
evmVersion: input.evmVersion,
112115
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+
},
115123
});
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;
120130
group.contractAddress = receipt ? receipt.contractAddress : undefined;
121131
return group.contractAddress === undefined
122132
? undefined
123-
: new PentePrivacyGroup(
124-
this.paladin,
125-
group,
126-
this.options
127-
);
133+
: new PentePrivacyGroup(this.paladin, group, this.options);
128134
}
129135
}
130136

131-
132137
export class PentePrivacyGroup {
133138
private options: Required<PenteOptions>;
134139
public readonly address: string;
@@ -141,7 +146,9 @@ export class PentePrivacyGroup {
141146
options?: PenteOptions
142147
) {
143148
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+
);
145152
}
146153
this.address = group.contractAddress;
147154
this.salt = group.id; // when bypassing privacy group helper functionality, and directly building Pente private transactions
@@ -153,18 +160,17 @@ export class PentePrivacyGroup {
153160
}
154161

155162
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);
161164
}
162-
163-
async deploy(params: PenteDeploy, txOptions?: Partial<IPrivacyGroupEVMTXInput>) {
164165

166+
async deploy(
167+
params: PenteDeploy,
168+
txOptions?: Partial<IPrivacyGroupEVMTXInput>
169+
) {
165170
// 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: [] };
168174

169175
const transaction: IPrivacyGroupEVMTXInput = {
170176
...txOptions,
@@ -173,8 +179,8 @@ export class PentePrivacyGroup {
173179
from: params.from,
174180
input: params.inputs,
175181
bytecode: params.bytecode,
176-
function: constructor,
177-
}
182+
function: constructor,
183+
};
178184

179185
const txID = await this.paladin.sendPrivacyGroupTransaction(transaction);
180186
const receipt = await this.paladin.pollForReceipt(
@@ -189,7 +195,10 @@ export class PentePrivacyGroup {
189195
}
190196

191197
// 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+
) {
193202
const txID = await this.paladin.sendPrivacyGroupTransaction({
194203
...txOptions,
195204
domain: this.group.domain,
@@ -199,11 +208,14 @@ export class PentePrivacyGroup {
199208
input: transaction.data,
200209
function: transaction.methodAbi,
201210
});
202-
return this.paladin.pollForReceipt(txID, this.options.pollTimeout);
211+
return this.paladin.pollForReceipt(txID, this.options.pollTimeout);
203212
}
204213

205214
// 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+
) {
207219
return this.paladin.callPrivacyGroup({
208220
...txOptions,
209221
domain: this.group.domain,
@@ -229,44 +241,58 @@ export class PentePrivacyGroup {
229241
});
230242
return this.paladin.pollForReceipt(txID, this.options.pollTimeout);
231243
}
232-
233244
}
234245

235246
export abstract class PentePrivateContract<ConstructorParams> {
236247
constructor(
237248
protected evm: PentePrivacyGroup,
238249
protected abi: ReadonlyArray<ethers.JsonFragment>,
239250
public readonly address: string
240-
) {
241-
}
251+
) {}
242252

243253
abstract using(
244254
paladin: PaladinClient
245255
): PentePrivateContract<ConstructorParams>;
246256

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+
);
249264
if (method === undefined) {
250265
throw new Error(`Method '${transaction.function}' not found`);
251266
}
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+
);
258276
}
259277

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+
);
262285
if (method === undefined) {
263286
throw new Error(`Method '${transaction.function}' not found`);
264287
}
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+
);
271297
}
272298
}

sdk/typescript/src/paladin.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,22 @@ export default class PaladinClient {
307307
return res.data.result;
308308
}
309309

310+
async getPrivacyGroupById(domainName: string, id: string) {
311+
const res = await this.post<JsonRpcResult<IPrivacyGroup>>(
312+
"pgroup_getGroupById",
313+
[domainName, id]
314+
);
315+
return res.data.result;
316+
}
317+
318+
async getPrivacyGroupByAddress(address: string) {
319+
const res = await this.post<JsonRpcResult<IPrivacyGroup>>(
320+
"pgroup_getGroupByAddress",
321+
[address]
322+
);
323+
return res.data.result;
324+
}
325+
310326
async sendPrivacyGroupTransaction(txi: IPrivacyGroupEVMTXInput) {
311327
const res = await this.post<JsonRpcResult<string>>(
312328
"pgroup_sendTransaction",

0 commit comments

Comments
 (0)