@lfdecentralizedtrust/paladin-sdk 0.13.0-rc.1
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/README.md +21 -0
- package/build/domains/abis/INoto.json +448 -0
- package/build/domains/abis/INotoPrivate.json +347 -0
- package/build/domains/abis/IZetoFungible.json +197 -0
- package/build/domains/abis/PentePrivacyGroup.json +613 -0
- package/build/domains/abis/Zeto_Anon.json +1263 -0
- package/build/domains/noto.d.ts +117 -0
- package/build/domains/noto.js +292 -0
- package/build/domains/pente.d.ts +84 -0
- package/build/domains/pente.js +191 -0
- package/build/domains/zeto.d.ts +83 -0
- package/build/domains/zeto.js +201 -0
- package/build/index.d.ts +9 -0
- package/build/index.js +28 -0
- package/build/interfaces/algorithms.d.ts +3 -0
- package/build/interfaces/algorithms.js +9 -0
- package/build/interfaces/blockchainevent.d.ts +15 -0
- package/build/interfaces/blockchainevent.js +2 -0
- package/build/interfaces/blockindex.d.ts +30 -0
- package/build/interfaces/blockindex.js +2 -0
- package/build/interfaces/domains.d.ts +9 -0
- package/build/interfaces/domains.js +2 -0
- package/build/interfaces/index.d.ts +15 -0
- package/build/interfaces/index.js +31 -0
- package/build/interfaces/keymanager.d.ts +32 -0
- package/build/interfaces/keymanager.js +2 -0
- package/build/interfaces/logger.d.ts +8 -0
- package/build/interfaces/logger.js +2 -0
- package/build/interfaces/paladin.d.ts +14 -0
- package/build/interfaces/paladin.js +2 -0
- package/build/interfaces/privacygroups.d.ts +76 -0
- package/build/interfaces/privacygroups.js +2 -0
- package/build/interfaces/query.d.ts +33 -0
- package/build/interfaces/query.js +2 -0
- package/build/interfaces/registry.d.ts +26 -0
- package/build/interfaces/registry.js +2 -0
- package/build/interfaces/states.d.ts +61 -0
- package/build/interfaces/states.js +2 -0
- package/build/interfaces/transaction.d.ts +159 -0
- package/build/interfaces/transaction.js +12 -0
- package/build/interfaces/transport.d.ts +32 -0
- package/build/interfaces/transport.js +2 -0
- package/build/interfaces/verifiers.d.ts +6 -0
- package/build/interfaces/verifiers.js +10 -0
- package/build/interfaces/websocket.d.ts +57 -0
- package/build/interfaces/websocket.js +2 -0
- package/build/paladin.d.ts +265 -0
- package/build/paladin.js +739 -0
- package/build/transaction.d.ts +8 -0
- package/build/transaction.js +17 -0
- package/build/utils.d.ts +5 -0
- package/build/utils.js +49 -0
- package/build/verifier.d.ts +16 -0
- package/build/verifier.js +24 -0
- package/build/websocket.d.ts +35 -0
- package/build/websocket.js +177 -0
- package/build.gradle +75 -0
- package/package.json +32 -0
- package/scripts/abi.mjs +19 -0
- package/scripts/contracts.mjs +20 -0
- package/scripts/download.mjs +27 -0
- package/scripts/util.mjs +42 -0
- package/src/domains/noto.ts +420 -0
- package/src/domains/pente.ts +287 -0
- package/src/domains/zeto.ts +282 -0
- package/src/index.ts +10 -0
- package/src/interfaces/algorithms.ts +6 -0
- package/src/interfaces/blockchainevent.ts +18 -0
- package/src/interfaces/blockindex.ts +33 -0
- package/src/interfaces/domains.ts +10 -0
- package/src/interfaces/index.ts +15 -0
- package/src/interfaces/keymanager.ts +35 -0
- package/src/interfaces/logger.ts +8 -0
- package/src/interfaces/paladin.ts +17 -0
- package/src/interfaces/privacygroups.ts +86 -0
- package/src/interfaces/query.ts +37 -0
- package/src/interfaces/registry.ts +27 -0
- package/src/interfaces/states.ts +77 -0
- package/src/interfaces/transaction.ts +179 -0
- package/src/interfaces/transport.ts +35 -0
- package/src/interfaces/verifiers.ts +6 -0
- package/src/interfaces/websocket.ts +67 -0
- package/src/paladin.ts +1295 -0
- package/src/transaction.ts +17 -0
- package/src/utils.ts +24 -0
- package/src/verifier.ts +27 -0
- package/src/websocket.ts +217 -0
- package/tsconfig.json +14 -0
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
import { ethers } from "ethers";
|
|
2
|
+
import { IStateEncoded, TransactionType } from "../interfaces";
|
|
3
|
+
import PaladinClient from "../paladin";
|
|
4
|
+
import { TransactionFuture } from "../transaction";
|
|
5
|
+
import { PaladinVerifier } from "../verifier";
|
|
6
|
+
import * as notoJSON from "./abis/INoto.json";
|
|
7
|
+
import * as notoPrivateJSON from "./abis/INotoPrivate.json";
|
|
8
|
+
|
|
9
|
+
export const notoConstructorABI = (
|
|
10
|
+
withHooks: boolean
|
|
11
|
+
): ethers.JsonFragment => ({
|
|
12
|
+
type: "constructor",
|
|
13
|
+
inputs: [
|
|
14
|
+
{ name: "name", type: "string" },
|
|
15
|
+
{ name: "symbol", type: "string" },
|
|
16
|
+
{ name: "notary", type: "string" },
|
|
17
|
+
{ name: "notaryMode", type: "string" },
|
|
18
|
+
{
|
|
19
|
+
name: "options",
|
|
20
|
+
type: "tuple",
|
|
21
|
+
components: [
|
|
22
|
+
...(withHooks
|
|
23
|
+
? [
|
|
24
|
+
{
|
|
25
|
+
name: "hooks",
|
|
26
|
+
type: "tuple",
|
|
27
|
+
components: [
|
|
28
|
+
{
|
|
29
|
+
name: "privateGroup",
|
|
30
|
+
type: "tuple",
|
|
31
|
+
components: [
|
|
32
|
+
{ name: "salt", type: "bytes32" },
|
|
33
|
+
{ name: "members", type: "string[]" },
|
|
34
|
+
],
|
|
35
|
+
},
|
|
36
|
+
{ name: "publicAddress", type: "address" },
|
|
37
|
+
{ name: "privateAddress", type: "address" },
|
|
38
|
+
],
|
|
39
|
+
},
|
|
40
|
+
]
|
|
41
|
+
: [
|
|
42
|
+
{
|
|
43
|
+
name: "basic",
|
|
44
|
+
type: "tuple",
|
|
45
|
+
components: [
|
|
46
|
+
{ name: "restrictMint", type: "bool" },
|
|
47
|
+
{ name: "allowBurn", type: "bool" },
|
|
48
|
+
{ name: "allowLock", type: "bool" },
|
|
49
|
+
],
|
|
50
|
+
},
|
|
51
|
+
]),
|
|
52
|
+
],
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
export interface IGroupInfo {
|
|
58
|
+
salt: string;
|
|
59
|
+
members: string[];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface NotoConstructorParams {
|
|
63
|
+
// Added in NotoFactory V1 (will be ignored in V0)
|
|
64
|
+
name?: string;
|
|
65
|
+
|
|
66
|
+
// Added in NotoFactory V1 (will be ignored in V0)
|
|
67
|
+
symbol?: string;
|
|
68
|
+
|
|
69
|
+
notary: PaladinVerifier;
|
|
70
|
+
notaryMode: "basic" | "hooks";
|
|
71
|
+
options?: {
|
|
72
|
+
basic?: {
|
|
73
|
+
restrictMint: boolean;
|
|
74
|
+
allowBurn: boolean;
|
|
75
|
+
allowLock: boolean;
|
|
76
|
+
};
|
|
77
|
+
hooks?: {
|
|
78
|
+
publicAddress: string;
|
|
79
|
+
privateGroup?: IGroupInfo;
|
|
80
|
+
privateAddress?: string;
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export interface NotoMintParams {
|
|
86
|
+
to: PaladinVerifier;
|
|
87
|
+
amount: string | number;
|
|
88
|
+
data: string;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export interface NotoBurnParams {
|
|
92
|
+
amount: string | number;
|
|
93
|
+
data: string;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export interface NotoBurnFromParams {
|
|
97
|
+
from: PaladinVerifier;
|
|
98
|
+
amount: string | number;
|
|
99
|
+
data: string;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export interface NotoTransferParams {
|
|
103
|
+
to: PaladinVerifier;
|
|
104
|
+
amount: string | number;
|
|
105
|
+
data: string;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export interface NotoTransferFromParams {
|
|
109
|
+
from: PaladinVerifier;
|
|
110
|
+
to: PaladinVerifier;
|
|
111
|
+
amount: string | number;
|
|
112
|
+
data: string;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export interface NotoLockParams {
|
|
116
|
+
amount: string | number;
|
|
117
|
+
data: string;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export interface NotoUnlockParams {
|
|
121
|
+
lockId: string;
|
|
122
|
+
from: PaladinVerifier;
|
|
123
|
+
recipients: UnlockRecipient[];
|
|
124
|
+
data: string;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export interface UnlockRecipient {
|
|
128
|
+
to: PaladinVerifier;
|
|
129
|
+
amount: string | number;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export interface NotoDelegateLockParams {
|
|
133
|
+
lockId: string;
|
|
134
|
+
unlock: NotoUnlockPublicParams;
|
|
135
|
+
delegate: string;
|
|
136
|
+
data: string;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export interface NotoUnlockPublicParams {
|
|
140
|
+
txId: string;
|
|
141
|
+
lockedInputs: string[];
|
|
142
|
+
lockedOutputs: string[];
|
|
143
|
+
outputs: string[];
|
|
144
|
+
signature: string;
|
|
145
|
+
data: string;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export interface NotoBalanceOfParams {
|
|
149
|
+
account: string;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export interface NotoBalanceOfResult {
|
|
153
|
+
totalBalance: string;
|
|
154
|
+
totalStates: string;
|
|
155
|
+
overflow: boolean;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Represents an in-flight Noto deployment
|
|
159
|
+
export class NotoFuture extends TransactionFuture {
|
|
160
|
+
async waitForDeploy(waitMs?: number) {
|
|
161
|
+
const receipt = await this.waitForReceipt(waitMs);
|
|
162
|
+
return receipt?.contractAddress
|
|
163
|
+
? new NotoInstance(this.paladin, receipt.contractAddress)
|
|
164
|
+
: undefined;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export class NotoFactory {
|
|
169
|
+
constructor(private paladin: PaladinClient, public readonly domain: string) {}
|
|
170
|
+
|
|
171
|
+
using(paladin: PaladinClient) {
|
|
172
|
+
return new NotoFactory(paladin, this.domain);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
newNoto(from: PaladinVerifier, data: NotoConstructorParams) {
|
|
176
|
+
return new NotoFuture(
|
|
177
|
+
this.paladin,
|
|
178
|
+
this.paladin.ptx.sendTransaction({
|
|
179
|
+
type: TransactionType.PRIVATE,
|
|
180
|
+
domain: this.domain,
|
|
181
|
+
abi: [notoConstructorABI(!!data.options?.hooks)],
|
|
182
|
+
function: "",
|
|
183
|
+
from: from.lookup,
|
|
184
|
+
data: {
|
|
185
|
+
...data,
|
|
186
|
+
name: data.name ?? "",
|
|
187
|
+
symbol: data.symbol ?? "",
|
|
188
|
+
notary: data.notary.lookup,
|
|
189
|
+
options: {
|
|
190
|
+
basic: {
|
|
191
|
+
restrictMint: true,
|
|
192
|
+
allowBurn: true,
|
|
193
|
+
allowLock: true,
|
|
194
|
+
...data.options?.basic,
|
|
195
|
+
},
|
|
196
|
+
...data.options,
|
|
197
|
+
},
|
|
198
|
+
},
|
|
199
|
+
})
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export class NotoInstance {
|
|
205
|
+
constructor(
|
|
206
|
+
private paladin: PaladinClient,
|
|
207
|
+
public readonly address: string
|
|
208
|
+
) {}
|
|
209
|
+
|
|
210
|
+
using(paladin: PaladinClient) {
|
|
211
|
+
return new NotoInstance(paladin, this.address);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
mint(from: PaladinVerifier, data: NotoMintParams) {
|
|
215
|
+
return new TransactionFuture(
|
|
216
|
+
this.paladin,
|
|
217
|
+
this.paladin.sendTransaction({
|
|
218
|
+
type: TransactionType.PRIVATE,
|
|
219
|
+
abi: notoPrivateJSON.abi,
|
|
220
|
+
function: "mint",
|
|
221
|
+
to: this.address,
|
|
222
|
+
from: from.lookup,
|
|
223
|
+
data: {
|
|
224
|
+
...data,
|
|
225
|
+
to: data.to.lookup,
|
|
226
|
+
},
|
|
227
|
+
})
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
transfer(from: PaladinVerifier, data: NotoTransferParams) {
|
|
232
|
+
return new TransactionFuture(
|
|
233
|
+
this.paladin,
|
|
234
|
+
this.paladin.sendTransaction({
|
|
235
|
+
type: TransactionType.PRIVATE,
|
|
236
|
+
abi: notoPrivateJSON.abi,
|
|
237
|
+
function: "transfer",
|
|
238
|
+
to: this.address,
|
|
239
|
+
from: from.lookup,
|
|
240
|
+
data: {
|
|
241
|
+
...data,
|
|
242
|
+
to: data.to.lookup,
|
|
243
|
+
},
|
|
244
|
+
})
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
transferFrom(from: PaladinVerifier, data: NotoTransferFromParams) {
|
|
249
|
+
return new TransactionFuture(
|
|
250
|
+
this.paladin,
|
|
251
|
+
this.paladin.sendTransaction({
|
|
252
|
+
type: TransactionType.PRIVATE,
|
|
253
|
+
abi: notoPrivateJSON.abi,
|
|
254
|
+
function: "transferFrom",
|
|
255
|
+
to: this.address,
|
|
256
|
+
from: from.lookup,
|
|
257
|
+
data: {
|
|
258
|
+
...data,
|
|
259
|
+
from: data.from.lookup,
|
|
260
|
+
to: data.to.lookup,
|
|
261
|
+
},
|
|
262
|
+
})
|
|
263
|
+
);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
prepareTransfer(from: PaladinVerifier, data: NotoTransferParams) {
|
|
267
|
+
return this.paladin.prepareTransaction({
|
|
268
|
+
type: TransactionType.PRIVATE,
|
|
269
|
+
abi: notoPrivateJSON.abi,
|
|
270
|
+
function: "transfer",
|
|
271
|
+
to: this.address,
|
|
272
|
+
from: from.lookup,
|
|
273
|
+
data: {
|
|
274
|
+
...data,
|
|
275
|
+
to: data.to.lookup,
|
|
276
|
+
},
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
burn(from: PaladinVerifier, data: NotoBurnParams) {
|
|
281
|
+
return new TransactionFuture(
|
|
282
|
+
this.paladin,
|
|
283
|
+
this.paladin.sendTransaction({
|
|
284
|
+
type: TransactionType.PRIVATE,
|
|
285
|
+
abi: notoPrivateJSON.abi,
|
|
286
|
+
function: "burn",
|
|
287
|
+
to: this.address,
|
|
288
|
+
from: from.lookup,
|
|
289
|
+
data,
|
|
290
|
+
})
|
|
291
|
+
);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
burnFrom(from: PaladinVerifier, data: NotoBurnFromParams) {
|
|
295
|
+
return new TransactionFuture(
|
|
296
|
+
this.paladin,
|
|
297
|
+
this.paladin.sendTransaction({
|
|
298
|
+
type: TransactionType.PRIVATE,
|
|
299
|
+
abi: notoPrivateJSON.abi,
|
|
300
|
+
function: "burnFrom",
|
|
301
|
+
to: this.address,
|
|
302
|
+
from: from.lookup,
|
|
303
|
+
data: {
|
|
304
|
+
...data,
|
|
305
|
+
from: data.from.lookup,
|
|
306
|
+
}
|
|
307
|
+
})
|
|
308
|
+
);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
lock(from: PaladinVerifier, data: NotoLockParams) {
|
|
312
|
+
return new TransactionFuture(
|
|
313
|
+
this.paladin,
|
|
314
|
+
this.paladin.sendTransaction({
|
|
315
|
+
type: TransactionType.PRIVATE,
|
|
316
|
+
abi: notoPrivateJSON.abi,
|
|
317
|
+
function: "lock",
|
|
318
|
+
to: this.address,
|
|
319
|
+
from: from.lookup,
|
|
320
|
+
data,
|
|
321
|
+
})
|
|
322
|
+
);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
unlock(from: PaladinVerifier, data: NotoUnlockParams) {
|
|
326
|
+
return new TransactionFuture(
|
|
327
|
+
this.paladin,
|
|
328
|
+
this.paladin.sendTransaction({
|
|
329
|
+
type: TransactionType.PRIVATE,
|
|
330
|
+
abi: notoPrivateJSON.abi,
|
|
331
|
+
function: "unlock",
|
|
332
|
+
to: this.address,
|
|
333
|
+
from: from.lookup,
|
|
334
|
+
data: {
|
|
335
|
+
...data,
|
|
336
|
+
from: data.from.lookup,
|
|
337
|
+
recipients: data.recipients.map((recipient) => ({
|
|
338
|
+
to: recipient.to.lookup,
|
|
339
|
+
amount: recipient.amount,
|
|
340
|
+
})),
|
|
341
|
+
},
|
|
342
|
+
})
|
|
343
|
+
);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
unlockAsDelegate(from: PaladinVerifier, data: NotoUnlockPublicParams) {
|
|
347
|
+
return new TransactionFuture(
|
|
348
|
+
this.paladin,
|
|
349
|
+
this.paladin.sendTransaction({
|
|
350
|
+
type: TransactionType.PUBLIC,
|
|
351
|
+
abi: notoJSON.abi,
|
|
352
|
+
function: "unlock",
|
|
353
|
+
to: this.address,
|
|
354
|
+
from: from.lookup,
|
|
355
|
+
data,
|
|
356
|
+
})
|
|
357
|
+
);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
prepareUnlock(from: PaladinVerifier, data: NotoUnlockParams) {
|
|
361
|
+
return new TransactionFuture(
|
|
362
|
+
this.paladin,
|
|
363
|
+
this.paladin.sendTransaction({
|
|
364
|
+
type: TransactionType.PRIVATE,
|
|
365
|
+
abi: notoPrivateJSON.abi,
|
|
366
|
+
function: "prepareUnlock",
|
|
367
|
+
to: this.address,
|
|
368
|
+
from: from.lookup,
|
|
369
|
+
data: {
|
|
370
|
+
...data,
|
|
371
|
+
from: data.from.lookup,
|
|
372
|
+
recipients: data.recipients.map((recipient) => ({
|
|
373
|
+
to: recipient.to.lookup,
|
|
374
|
+
amount: recipient.amount,
|
|
375
|
+
})),
|
|
376
|
+
},
|
|
377
|
+
})
|
|
378
|
+
);
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
delegateLock(from: PaladinVerifier, data: NotoDelegateLockParams) {
|
|
382
|
+
return new TransactionFuture(
|
|
383
|
+
this.paladin,
|
|
384
|
+
this.paladin.sendTransaction({
|
|
385
|
+
type: TransactionType.PRIVATE,
|
|
386
|
+
abi: notoPrivateJSON.abi,
|
|
387
|
+
function: "delegateLock",
|
|
388
|
+
to: this.address,
|
|
389
|
+
from: from.lookup,
|
|
390
|
+
data,
|
|
391
|
+
})
|
|
392
|
+
);
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
encodeUnlock(data: NotoUnlockPublicParams) {
|
|
396
|
+
return new ethers.Interface(notoJSON.abi).encodeFunctionData("unlock", [
|
|
397
|
+
data.txId,
|
|
398
|
+
data.lockedInputs,
|
|
399
|
+
data.lockedOutputs,
|
|
400
|
+
data.outputs,
|
|
401
|
+
data.signature,
|
|
402
|
+
data.data,
|
|
403
|
+
]);
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
balanceOf(
|
|
407
|
+
from: PaladinVerifier,
|
|
408
|
+
data: NotoBalanceOfParams
|
|
409
|
+
): Promise<NotoBalanceOfResult> {
|
|
410
|
+
return this.paladin.call({
|
|
411
|
+
type: TransactionType.PRIVATE,
|
|
412
|
+
domain: "noto",
|
|
413
|
+
abi: notoPrivateJSON.abi,
|
|
414
|
+
function: "balanceOf",
|
|
415
|
+
to: this.address,
|
|
416
|
+
from: from.lookup,
|
|
417
|
+
data,
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
}
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
import { ethers } from "ethers";
|
|
2
|
+
import { TransactionType } from "../interfaces";
|
|
3
|
+
import {
|
|
4
|
+
IPrivacyGroup,
|
|
5
|
+
IPrivacyGroupEVMCall,
|
|
6
|
+
IPrivacyGroupEVMTXInput,
|
|
7
|
+
IPrivacyGroupResume,
|
|
8
|
+
} from "../interfaces/privacygroups";
|
|
9
|
+
import PaladinClient from "../paladin";
|
|
10
|
+
import { TransactionFuture } from "../transaction";
|
|
11
|
+
import { PaladinVerifier } from "../verifier";
|
|
12
|
+
import * as penteJSON from "./abis/PentePrivacyGroup.json";
|
|
13
|
+
|
|
14
|
+
export interface PenteGroupTransactionInput {
|
|
15
|
+
from: string;
|
|
16
|
+
methodAbi: ethers.JsonFragment;
|
|
17
|
+
to: string;
|
|
18
|
+
data: {
|
|
19
|
+
[key: string]: any;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface PenteContractTransactionInput {
|
|
24
|
+
from: string;
|
|
25
|
+
function: string;
|
|
26
|
+
data?: {
|
|
27
|
+
[key: string]: any;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface PenteDeploy {
|
|
32
|
+
abi: ReadonlyArray<ethers.JsonFragment>;
|
|
33
|
+
bytecode: string;
|
|
34
|
+
from: string;
|
|
35
|
+
inputs?: any;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface PentePrivacyGroupParams {
|
|
39
|
+
name?: string;
|
|
40
|
+
members: (string | PaladinVerifier)[];
|
|
41
|
+
salt?: string;
|
|
42
|
+
evmVersion?: string;
|
|
43
|
+
endorsementType?: string;
|
|
44
|
+
externalCallsEnabled?: boolean;
|
|
45
|
+
additionalProperties?: {
|
|
46
|
+
[x: string]: unknown;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface PenteApproveTransitionParams {
|
|
51
|
+
txId: string;
|
|
52
|
+
delegate: string;
|
|
53
|
+
transitionHash: string;
|
|
54
|
+
signatures: string[];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Represents an in-flight Pente privacy group deployment
|
|
58
|
+
export class PentePrivacyGroupFuture {
|
|
59
|
+
public tx: Promise<TransactionFuture | undefined>;
|
|
60
|
+
|
|
61
|
+
constructor(
|
|
62
|
+
private paladin: PaladinClient,
|
|
63
|
+
private group: IPrivacyGroup | Promise<IPrivacyGroup>
|
|
64
|
+
) {
|
|
65
|
+
this.tx = Promise.resolve(group).then((group) =>
|
|
66
|
+
group.genesisTransaction
|
|
67
|
+
? new TransactionFuture(paladin, group.genesisTransaction)
|
|
68
|
+
: undefined
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async waitForReceipt(waitMs?: number, full = false) {
|
|
73
|
+
const tx = await this.tx;
|
|
74
|
+
return tx?.waitForReceipt(waitMs, full);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async waitForDeploy(waitMs?: number) {
|
|
78
|
+
const group = await this.group;
|
|
79
|
+
const receipt = await this.waitForReceipt(waitMs);
|
|
80
|
+
group.contractAddress = receipt?.contractAddress;
|
|
81
|
+
return group.contractAddress
|
|
82
|
+
? new PentePrivacyGroup(this.paladin, group)
|
|
83
|
+
: undefined;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export class PenteFactory {
|
|
88
|
+
constructor(private paladin: PaladinClient, public readonly domain: string) {}
|
|
89
|
+
|
|
90
|
+
using(paladin: PaladinClient) {
|
|
91
|
+
return new PenteFactory(paladin, this.domain);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
newPrivacyGroup(input: PentePrivacyGroupParams) {
|
|
95
|
+
return new PentePrivacyGroupFuture(
|
|
96
|
+
this.paladin,
|
|
97
|
+
this.paladin.pgroup.createGroup({
|
|
98
|
+
domain: this.domain,
|
|
99
|
+
name: input.name,
|
|
100
|
+
members: input.members.map((m) => m.toString()),
|
|
101
|
+
configuration: {
|
|
102
|
+
evmVersion: input.evmVersion,
|
|
103
|
+
endorsementType: input.endorsementType,
|
|
104
|
+
externalCallsEnabled:
|
|
105
|
+
input.externalCallsEnabled === true
|
|
106
|
+
? "true"
|
|
107
|
+
: input.externalCallsEnabled === false
|
|
108
|
+
? "false"
|
|
109
|
+
: undefined,
|
|
110
|
+
},
|
|
111
|
+
})
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
async resumePrivacyGroup(input: IPrivacyGroupResume) {
|
|
116
|
+
const existingGroup = await this.paladin.getPrivacyGroupById(
|
|
117
|
+
this.domain,
|
|
118
|
+
input.id
|
|
119
|
+
);
|
|
120
|
+
return existingGroup?.contractAddress
|
|
121
|
+
? new PentePrivacyGroup(this.paladin, existingGroup)
|
|
122
|
+
: undefined;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export class PentePrivacyGroup {
|
|
127
|
+
public readonly address: string;
|
|
128
|
+
public readonly salt: string;
|
|
129
|
+
public readonly members: string[];
|
|
130
|
+
|
|
131
|
+
constructor(
|
|
132
|
+
private paladin: PaladinClient,
|
|
133
|
+
public readonly group: IPrivacyGroup
|
|
134
|
+
) {
|
|
135
|
+
if (group.contractAddress === undefined) {
|
|
136
|
+
throw new Error(
|
|
137
|
+
`Supplied group '${group.id}' is missing a contract address. Check transaction ${group.genesisTransaction}`
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
this.address = group.contractAddress;
|
|
141
|
+
this.salt = group.id; // when bypassing privacy group helper functionality, and directly building Pente private transactions
|
|
142
|
+
this.members = group.members;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
using(paladin: PaladinClient) {
|
|
146
|
+
return new PentePrivacyGroup(paladin, this.group);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
deploy(params: PenteDeploy, txOptions?: Partial<IPrivacyGroupEVMTXInput>) {
|
|
150
|
+
// Find the constructor in the ABI
|
|
151
|
+
const constructor: ethers.JsonFragment = params.abi.find(
|
|
152
|
+
(entry) => entry.type === "constructor"
|
|
153
|
+
) || { type: "constructor", inputs: [] };
|
|
154
|
+
|
|
155
|
+
const transaction: IPrivacyGroupEVMTXInput = {
|
|
156
|
+
...txOptions,
|
|
157
|
+
domain: this.group.domain,
|
|
158
|
+
group: this.group.id,
|
|
159
|
+
from: params.from,
|
|
160
|
+
input: params.inputs,
|
|
161
|
+
bytecode: params.bytecode,
|
|
162
|
+
function: constructor,
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
return new PentePrivateDeployFuture(
|
|
166
|
+
this.paladin,
|
|
167
|
+
this.paladin.sendPrivacyGroupTransaction(transaction)
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// sendTransaction functions in the contract (write)
|
|
172
|
+
sendTransaction(
|
|
173
|
+
transaction: PenteGroupTransactionInput,
|
|
174
|
+
txOptions?: Partial<IPrivacyGroupEVMTXInput>
|
|
175
|
+
) {
|
|
176
|
+
return new TransactionFuture(
|
|
177
|
+
this.paladin,
|
|
178
|
+
this.paladin.sendPrivacyGroupTransaction({
|
|
179
|
+
...txOptions,
|
|
180
|
+
domain: this.group.domain,
|
|
181
|
+
group: this.group.id,
|
|
182
|
+
from: transaction.from,
|
|
183
|
+
to: transaction.to,
|
|
184
|
+
input: transaction.data,
|
|
185
|
+
function: transaction.methodAbi,
|
|
186
|
+
})
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// call functions in the contract (read-only)
|
|
191
|
+
async call(
|
|
192
|
+
transaction: PenteGroupTransactionInput,
|
|
193
|
+
txOptions?: Partial<IPrivacyGroupEVMCall>
|
|
194
|
+
) {
|
|
195
|
+
return this.paladin.callPrivacyGroup({
|
|
196
|
+
...txOptions,
|
|
197
|
+
domain: this.group.domain,
|
|
198
|
+
group: this.group.id,
|
|
199
|
+
from: transaction.from || "sdk.default",
|
|
200
|
+
to: transaction.to,
|
|
201
|
+
input: transaction.data,
|
|
202
|
+
function: transaction.methodAbi,
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
approveTransition(
|
|
207
|
+
from: PaladinVerifier,
|
|
208
|
+
data: PenteApproveTransitionParams
|
|
209
|
+
) {
|
|
210
|
+
return new TransactionFuture(
|
|
211
|
+
this.paladin,
|
|
212
|
+
this.paladin.sendTransaction({
|
|
213
|
+
type: TransactionType.PUBLIC,
|
|
214
|
+
abi: penteJSON.abi,
|
|
215
|
+
function: "approveTransition",
|
|
216
|
+
to: this.address,
|
|
217
|
+
from: from.lookup,
|
|
218
|
+
data,
|
|
219
|
+
})
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// Represents an in-flight contract deployment within a privacy group
|
|
225
|
+
export class PentePrivateDeployFuture extends TransactionFuture {
|
|
226
|
+
async waitForDeploy(waitMs?: number) {
|
|
227
|
+
const receipt = await this.waitForReceipt(waitMs, true);
|
|
228
|
+
return receipt?.domainReceipt !== undefined &&
|
|
229
|
+
"receipt" in receipt.domainReceipt
|
|
230
|
+
? receipt.domainReceipt.receipt.contractAddress
|
|
231
|
+
: undefined;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
export abstract class PentePrivateContract<ConstructorParams> {
|
|
236
|
+
constructor(
|
|
237
|
+
protected evm: PentePrivacyGroup,
|
|
238
|
+
protected abi: ReadonlyArray<ethers.JsonFragment>,
|
|
239
|
+
public readonly address: string
|
|
240
|
+
) {}
|
|
241
|
+
|
|
242
|
+
abstract using(
|
|
243
|
+
paladin: PaladinClient
|
|
244
|
+
): PentePrivateContract<ConstructorParams>;
|
|
245
|
+
|
|
246
|
+
sendTransaction(
|
|
247
|
+
transaction: PenteContractTransactionInput,
|
|
248
|
+
txOptions?: Partial<IPrivacyGroupEVMTXInput>
|
|
249
|
+
) {
|
|
250
|
+
const method = this.abi.find(
|
|
251
|
+
(entry) => entry.name === transaction.function
|
|
252
|
+
);
|
|
253
|
+
if (method === undefined) {
|
|
254
|
+
throw new Error(`Method '${transaction.function}' not found`);
|
|
255
|
+
}
|
|
256
|
+
return this.evm.sendTransaction(
|
|
257
|
+
{
|
|
258
|
+
from: transaction.from,
|
|
259
|
+
to: this.address,
|
|
260
|
+
methodAbi: method,
|
|
261
|
+
data: transaction.data ?? [],
|
|
262
|
+
},
|
|
263
|
+
txOptions
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
call(
|
|
268
|
+
transaction: PenteContractTransactionInput,
|
|
269
|
+
txOptions?: Partial<IPrivacyGroupEVMCall>
|
|
270
|
+
) {
|
|
271
|
+
const method = this.abi.find(
|
|
272
|
+
(entry) => entry.name === transaction.function
|
|
273
|
+
);
|
|
274
|
+
if (method === undefined) {
|
|
275
|
+
throw new Error(`Method '${transaction.function}' not found`);
|
|
276
|
+
}
|
|
277
|
+
return this.evm.call(
|
|
278
|
+
{
|
|
279
|
+
from: transaction.from,
|
|
280
|
+
to: this.address,
|
|
281
|
+
methodAbi: method,
|
|
282
|
+
data: transaction.data ?? [],
|
|
283
|
+
},
|
|
284
|
+
txOptions
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
}
|