-
Notifications
You must be signed in to change notification settings - Fork 7
/
iam-base.ts
711 lines (645 loc) · 26.3 KB
/
iam-base.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
import { providers, Signer, utils, Wallet, BigNumber, ethers } from "ethers";
import {
DomainReader,
DomainTransactionFactory,
DomainHierarchy,
ResolverContractType,
} from "@energyweb/iam-contracts";
import { EwSigner, Operator, Resolver } from "@ew-did-registry/did-ethr-resolver";
import { labelhash, namehash } from "../utils/ENS_hash";
import {
IServiceEndpoint,
RegistrySettings,
KeyTags,
IPublicKey,
ProviderTypes,
} from "@ew-did-registry/did-resolver-interface";
import { Methods } from "@ew-did-registry/did";
import { DIDDocumentFull } from "@ew-did-registry/did-document";
import { ClaimsIssuer, ClaimsUser, ClaimsVerifier } from "@ew-did-registry/claims";
import { DidStore } from "@ew-did-registry/did-ipfs-store";
import { ENSRegistry } from "../../ethers/ENSRegistry";
import { ENSRegistry__factory } from "../../ethers/factories/ENSRegistry__factory";
import { ClaimManager__factory } from "../../ethers/factories/ClaimManager__factory";
import { ClaimManager } from "../../ethers/ClaimManager";
import { JWT } from "@ew-did-registry/jwt";
import { ICacheServerClient } from "../cacheServerClient/ICacheServerClient";
import { detectExecutionEnvironment, ExecutionEnvironment } from "../utils/detectEnvironment";
import { connect, NatsConnection, Codec, JSONCodec } from "../../node_modules/nats.ws/lib/src/mod.js";
import { ERROR_MESSAGES } from "../errors";
import { ClaimData } from "../cacheServerClient/cacheServerClient.types";
import difference from "lodash.difference";
import detectMetamask from "@metamask/detect-provider";
import { WalletProvider } from "../types/WalletProvider";
import { CacheServerClient } from "../cacheServerClient/cacheServerClient";
import { emptyAddress, MessagingMethod, PUBLIC_KEY, WALLET_PROVIDER } from "../utils/constants";
import { cacheServerClientOptions, chainConfigs, messagingOptions, MessagingOptions } from "./chainConfig";
import { WalletConnectService } from "../walletconnect/WalletConnectService";
import { OfferableIdentity__factory } from "../../ethers/factories/OfferableIdentity__factory";
import { IdentityManager__factory } from "../../ethers/factories/IdentityManager__factory";
import { IdentityManager } from "../../ethers/IdentityManager";
import { getPublicKeyAndIdentityToken, IPubKeyAndIdentityToken } from "../utils/getPublicKeyAndIdentityToken";
import { AccountInfo } from "../iam";
const { parseUnits } = utils;
const { JsonRpcProvider } = providers;
export type ConnectionOptions = {
/** only required in node env */
rpcUrl?: string;
infuraId?: string;
ipfsUrl?: string;
bridgeUrl?: string;
privateKey?: string;
ewKeyManagerUrl?: string;
};
export type EncodedCall = {
to: string;
data: string;
value?: string;
};
export type Transaction = {
calls: EncodedCall[];
from: string;
};
/**
* @class
*/
export class IAMBase {
protected _executionEnvironment: ExecutionEnvironment;
protected _connectionOptions: ConnectionOptions;
protected _did: string | undefined;
protected _provider: providers.JsonRpcProvider;
protected _metamaskProvider: { on: any; request: any } | undefined;
protected _walletConnectService: WalletConnectService;
protected _address: string | undefined;
protected _signer: Signer | undefined;
protected _safeAddress: string | undefined;
protected _didSigner: EwSigner | undefined;
protected _identityToken: string | undefined;
protected _transactionOverrides: utils.Deferrable<providers.TransactionRequest> = {};
protected _providerType: WalletProvider | undefined;
protected _publicKey: string | undefined | null;
protected _registrySetting: RegistrySettings;
protected _resolver: Resolver;
protected _document: DIDDocumentFull | undefined;
protected _userClaims: ClaimsUser | undefined;
protected _issuerClaims: ClaimsIssuer | undefined;
protected _verifierClaims: ClaimsVerifier | undefined;
protected _ipfsStore: DidStore;
protected _jwt: JWT | undefined;
protected _ensRegistry: ENSRegistry;
protected _domainDefinitionTransactionFactory: DomainTransactionFactory;
protected _domainDefinitionReader: DomainReader;
protected _domainHierarchy: DomainHierarchy;
protected _ensResolverAddress: string;
protected _ensRegistryAddress: string;
protected _assetManager: IdentityManager;
protected _claimManager: ClaimManager;
protected _cacheClient: ICacheServerClient;
protected _messagingOptions: MessagingOptions;
protected _natsConnection: NatsConnection | undefined;
protected _jsonCodec: Codec<any> | undefined;
private ttl = BigNumber.from(0);
/**
* IAM Constructor
*
*/
public constructor({
rpcUrl,
infuraId,
ipfsUrl = "https://ipfs.infura.io:5001/api/v0/",
bridgeUrl = "https://walletconnect.energyweb.org",
privateKey,
ewKeyManagerUrl = "https://km.aws.energyweb.org/connect/new",
}: ConnectionOptions = {}) {
this._executionEnvironment = detectExecutionEnvironment();
ethers.utils.Logger.setLogLevel(utils.Logger.levels.ERROR);
this._connectionOptions = {
privateKey,
rpcUrl,
bridgeUrl,
infuraId,
};
this._ipfsStore = new DidStore(ipfsUrl);
// Need to get providerType and publicKey in constructor because they are used
// to infer if the session is active.
if (this._executionEnvironment === ExecutionEnvironment.BROWSER) {
this._providerType = localStorage.getItem(WALLET_PROVIDER) as WalletProvider;
this._publicKey = localStorage.getItem(PUBLIC_KEY);
}
this._walletConnectService = new WalletConnectService(bridgeUrl, infuraId, ewKeyManagerUrl);
}
// INITIAL
protected async init({
initializeMetamask,
walletProvider: walletProvider,
}: {
initializeMetamask?: boolean;
walletProvider?: WalletProvider;
}): Promise<AccountInfo | undefined> {
const accountInfo = await this.initSigner({ walletProvider, initializeMetamask });
await this.setAddress();
this.setDid();
await this.initChain();
this.initEventHandlers();
if (this._executionEnvironment === ExecutionEnvironment.BROWSER) {
await this.setupMessaging();
}
this.setResolver();
this.setJWT();
return accountInfo;
}
private async initSigner({
initializeMetamask,
walletProvider,
}: {
useMetamask?: boolean;
initializeMetamask?: boolean;
walletProvider?: WalletProvider;
}): Promise<AccountInfo | undefined> {
const { privateKey, rpcUrl } = this._connectionOptions;
if (this._executionEnvironment === ExecutionEnvironment.NODE) {
if (!privateKey) {
throw new Error(ERROR_MESSAGES.PRIVATE_KEY_NOT_PROVIDED);
}
if (!rpcUrl) {
throw new Error(ERROR_MESSAGES.RPC_URL_NOT_PROVIDED);
}
this._provider = new JsonRpcProvider({ url: rpcUrl });
this._signer = new Wallet(privateKey, this._provider);
return;
}
if (walletProvider === WalletProvider.MetaMask) {
const metamaskProvider: any = await detectMetamask({
mustBeMetaMask: true,
});
if (!metamaskProvider) {
throw new Error(ERROR_MESSAGES.METAMASK_EXTENSION_NOT_AVAILABLE);
}
this._metamaskProvider = metamaskProvider;
const requestObject = {
method: initializeMetamask ? "wallet_requestPermissions" : "eth_accounts",
params: [
{
eth_accounts: {},
},
],
};
const accounts: string[] = await metamaskProvider.request(requestObject);
if (!initializeMetamask && accounts.length < 1) {
await metamaskProvider.request({
method: "wallet_requestPermissions",
params: [
{
eth_accounts: {},
},
],
});
}
this._providerType = walletProvider;
this._provider = new providers.Web3Provider(metamaskProvider);
this._signer = this._provider.getSigner();
const { chainId } = await this._provider.getNetwork();
console.log("metamask chain id:", chainId);
return {
account: accounts[0],
chainId: chainId,
chainName: chainConfigs[chainId].chainName,
};
}
if (walletProvider && [WalletProvider.EwKeyManager, WalletProvider.WalletConnect].includes(walletProvider)) {
this._transactionOverrides = {
gasLimit: BigNumber.from(4900000),
gasPrice: parseUnits("0.01", "gwei"),
};
await this._walletConnectService.initialize(walletProvider);
const wcProvider = this._walletConnectService.getProvider();
this._provider = new providers.Web3Provider(wcProvider);
this._signer = this._provider.getSigner();
this._providerType = walletProvider;
return;
}
throw new Error(ERROR_MESSAGES.WALLET_TYPE_NOT_PROVIDED);
}
/**
* @description Establishes connection to the cache serverand sets public key and identity token
*/
async connectToCacheServer() {
const { chainId } = await this._provider.getNetwork();
const cacheOptions = cacheServerClientOptions[chainId];
if (!this._signer) {
throw new Error(ERROR_MESSAGES.SIGNER_NOT_INITIALIZED);
}
if (!cacheOptions.url) {
throw new Error(ERROR_MESSAGES.CACHE_SERVER_NOT_REGISTERED);
}
this._cacheClient = new CacheServerClient(cacheOptions, this._signer);
const fromCacheLogin = await this.loginToCacheServer();
this._publicKey = fromCacheLogin?.publicKey ?? this._publicKey;
this._identityToken = fromCacheLogin?.identityToken;
}
/**
* @description Creates the signer's DID document if it does not exist
*/
async connectToDIDRegistry() {
if (!this._signer) {
throw new Error(ERROR_MESSAGES.SIGNER_NOT_INITIALIZED);
}
if (!this._publicKey) {
const { publicKey, identityToken } = await getPublicKeyAndIdentityToken(this._signer);
this._publicKey = publicKey;
this._identityToken = identityToken;
}
if (this._signer instanceof Wallet) {
this._didSigner = EwSigner.fromPrivateKey(this._signer.privateKey, {
type: ProviderTypes.HTTP,
uriOrInfo: this._provider.connection.url,
});
} else if (this._signer instanceof providers.JsonRpcSigner) {
this._didSigner = EwSigner.fromEthersProvider(this._signer.provider, this._publicKey);
} else {
throw new Error(ERROR_MESSAGES.PROVIDER_NOT_INITIALIZED);
}
await this.setDocument();
this.setClaims();
this.storeSession();
}
/**
* @description Checks if the session is active
* @returns boolean that indicates the session state
*/
public isSessionActive() {
return Boolean(this._publicKey) && Boolean(this._providerType);
}
private storeSession() {
if (this._executionEnvironment === ExecutionEnvironment.BROWSER && this._didSigner) {
this._providerType && localStorage.setItem(WALLET_PROVIDER, this._providerType as string);
this._didSigner.publicKey && localStorage.setItem(PUBLIC_KEY, this._didSigner.publicKey);
}
}
protected clearSession() {
if (this._executionEnvironment === ExecutionEnvironment.BROWSER) {
localStorage.removeItem(WALLET_PROVIDER);
localStorage.removeItem(PUBLIC_KEY);
}
}
/**
* @description Defines event handlers for change of account, change of network, disconnection
* @requires to be called after the connection to wallet was initialized
*/
on(event: "accountChanged" | "networkChanged" | "disconnected", eventHandler: () => void) {
if (!this._providerType) return;
const isMetamask = this._providerType === WalletProvider.MetaMask;
switch (event) {
case "accountChanged": {
isMetamask
? this._metamaskProvider?.on("accountsChanged", eventHandler)
: this._walletConnectService.getProvider().wc.on("session_update", eventHandler);
break;
}
case "disconnected": {
isMetamask === false && this._walletConnectService.getProvider()?.wc.on("disconnect", eventHandler);
break;
}
case "networkChanged": {
isMetamask
? this._metamaskProvider?.on("networkChanged", eventHandler)
: this._walletConnectService.getProvider().wc.on("session_update", eventHandler);
break;
}
default:
throw new Error("Event not supported");
}
}
private initEventHandlers() {
this.on("accountChanged", () => {
this.closeConnection();
});
this.on("disconnected", () => {
this.closeConnection();
});
this.on("networkChanged", () => {
this.closeConnection();
});
}
/**
* @description Closes the connection between application and the signer's wallet
*/
async closeConnection() {
await this._walletConnectService.closeConnection();
this.clearSession();
this._did = undefined;
this._address = undefined;
this._signer = undefined;
}
private async loginToCacheServer(): Promise<IPubKeyAndIdentityToken | undefined> {
if (this._signer && this._cacheClient && this._cacheClient.isAuthEnabled()) {
// If session isn't active then assume that user has never signed in or has signed out
if (!this.isSessionActive()) {
const { pubKeyAndIdentityToken } = await this._cacheClient.login();
return pubKeyAndIdentityToken;
}
// session is active so maybe user has signed in before.
// Test cache-server login to confirm that their tokens are still valid
else {
await this._cacheClient.testLogin();
// Expect that if login generated pubKey&IdToken, then will be accessible as property of cacheClient
return this._cacheClient.pubKeyAndIdentityToken;
}
}
return undefined;
}
protected async setAddress() {
if (this._signer) {
this._address = await this._signer.getAddress();
}
}
get address() {
return this._address;
}
private setResolver() {
if (this._registrySetting) {
this._resolver = new Resolver(this._provider as providers.Provider, this._registrySetting);
}
}
private setDid() {
if (this._address) {
this._did = `did:${Methods.Erc1056}:${this._address}`;
}
}
private async setDocument() {
if (this._did && this._didSigner) {
this._document = new DIDDocumentFull(this._did, new Operator(this._didSigner, this._registrySetting));
let pubKey: IPublicKey | undefined;
if (this._cacheClient) {
const cachedDoc = await this._cacheClient.getDidDocument({ did: this._did });
pubKey = cachedDoc.publicKey.find((pk) => pk.id.endsWith(KeyTags.OWNER));
}
if (!pubKey) {
await this._document.create();
}
}
}
private setClaims() {
if (this._didSigner && this._document) {
this._userClaims = new ClaimsUser(this._didSigner, this._document, this._ipfsStore);
this._issuerClaims = new ClaimsIssuer(this._didSigner, this._document, this._ipfsStore);
this._verifierClaims = new ClaimsVerifier(this._didSigner, this._document, this._ipfsStore);
}
}
private setJWT() {
if (this._signer) {
this._jwt = new JWT(this._signer);
return;
}
throw new Error(ERROR_MESSAGES.SIGNER_NOT_INITIALIZED);
}
private async setupMessaging() {
const { messagingMethod, natsServerUrl } = this._messagingOptions || {};
if (natsServerUrl && messagingMethod === MessagingMethod.Nats) {
this._jsonCodec = JSONCodec();
try {
let protocol = "ws";
if (natsServerUrl.indexOf("https://") === 0) {
protocol = "wss";
}
const timeout = 3000;
// this race condition duplicate timeout is there because unable to catch the error that occurs when NATS.ws timeouts
const connection = await Promise.race<NatsConnection | undefined>([
connect({
servers: `${protocol}://${natsServerUrl}`,
timeout,
pingInterval: 50 * 1000,
}),
new Promise<undefined>((resolve) => setTimeout(resolve, timeout)),
]);
if (!connection) return;
this._natsConnection = connection;
} catch (err) {
console.log(err);
}
}
}
protected async downloadClaims({ services }: { services: IServiceEndpoint[] }) {
return Promise.all(
services.map(async ({ serviceEndpoint, ...rest }) => {
const data = await this._ipfsStore.get(serviceEndpoint);
const { claimData, ...claimRest } = this._jwt?.decode(data) as {
claimData: ClaimData;
};
return {
serviceEndpoint,
...rest,
...claimData,
...claimRest,
} as IServiceEndpoint & ClaimData;
}),
);
}
protected createSubdomainTx({
domain,
nodeName,
owner = this._address as string,
}: {
domain: string;
nodeName: string;
owner?: string;
}): EncodedCall {
return {
to: this._ensRegistryAddress,
data: this._ensRegistry.interface.encodeFunctionData("setSubnodeRecord", [
namehash(domain),
labelhash(nodeName),
owner,
this._ensResolverAddress,
this.ttl,
]),
};
}
protected changeSubdomainOwnerTx({
newOwner,
label,
namespace,
}: {
newOwner: string;
namespace: string;
label: string;
}): EncodedCall {
return {
to: this._ensRegistryAddress,
data: this._ensRegistry.interface.encodeFunctionData("setSubnodeOwner", [
namehash(namespace),
labelhash(label),
newOwner,
]),
};
}
protected changeDomainOwnerTx({ newOwner, namespace }: { newOwner: string; namespace: string }): EncodedCall {
return {
to: this._ensRegistryAddress,
data: this._ensRegistry.interface.encodeFunctionData("setOwner", [namehash(namespace), newOwner]),
};
}
protected async validateIssuers({ issuer, namespace }: { issuer: string[]; namespace: string }) {
const roleHash = namehash(namespace);
const definition = await this._domainDefinitionReader.read({ node: roleHash });
if (!DomainReader.isRoleDefinition(definition)) {
throw new Error("Domain is not a role definition");
}
const diff = difference(issuer, definition.issuer.did || []);
if (diff.length > 0) {
throw new Error(`Issuer validation failed for: ${diff.join(", ")}`);
}
}
protected deleteSubdomainTx({ namespace }: { namespace: string }): EncodedCall {
const namespaceArray = namespace.split(".");
const node = namespaceArray.slice(1).join(".");
const label = namespaceArray[0];
return {
to: this._ensRegistryAddress,
data: this._ensRegistry.interface.encodeFunctionData("setSubnodeRecord", [
namehash(node),
labelhash(label),
emptyAddress,
emptyAddress,
this.ttl,
]),
};
}
protected async deleteDomain({ namespace }: { namespace: string }) {
if (!this._signer) {
throw new Error(ERROR_MESSAGES.SIGNER_NOT_INITIALIZED);
}
await this.send({
calls: [this.deleteDomainTx({ namespace })],
from: await this.getOwner({ namespace }),
});
}
protected async getOwner({ namespace }: { namespace: string }) {
const node = namehash(namespace);
return this._ensRegistry.owner(node);
}
protected async send(tx: Transaction) {
if (!this._signer) {
throw new Error(ERROR_MESSAGES.SIGNER_NOT_INITIALIZED);
}
for await (const call of tx.calls) {
await (await this._signer.sendTransaction({ ...call, ...this._transactionOverrides })).wait();
}
}
protected deleteDomainTx({ namespace }: { namespace: string }): EncodedCall {
return {
to: this._ensRegistryAddress,
data: this._ensRegistry.interface.encodeFunctionData("setRecord", [
namehash(namespace),
emptyAddress,
emptyAddress,
this.ttl,
]),
};
}
protected async deleteSubdomain({ namespace }: { namespace: string }) {
if (!this._signer) {
throw new Error(ERROR_MESSAGES.SIGNER_NOT_INITIALIZED);
}
await this.send({
calls: [this.deleteSubdomainTx({ namespace })],
from: await this.getOwner({
namespace: namespace.split(".").slice(1).join(""),
}),
});
}
private async initChain() {
const { chainId } = await this._provider.getNetwork();
const {
ensRegistryAddress,
ensResolverAddress,
ensPublicResolverAddress,
domainNotifierAddress,
didContractAddress,
assetManagerAddress,
claimManagerAddress,
} = chainConfigs[chainId];
if (!ensRegistryAddress)
throw new Error(`Chain config for chainId: ${chainId} does not contain ensRegistryAddress`);
if (!ensResolverAddress)
throw new Error(`Chain config for chainId: ${chainId} does not contain ensResolverAddress`);
if (!didContractAddress)
throw new Error(`Chain config for chainId: ${chainId} does not contain didContractAddress`);
if (!assetManagerAddress)
throw new Error(`Chain config for chainId: ${chainId} does not contain assetManagerContractAddress`);
if (!claimManagerAddress) {
throw new Error(`Chain config for chainId: ${chainId} does not contain claimManagerAddress`);
}
if (!this._signer) {
throw new Error(ERROR_MESSAGES.SIGNER_NOT_INITIALIZED);
}
this._registrySetting = {
address: didContractAddress,
method: Methods.Erc1056,
};
this._ensRegistryAddress = ensRegistryAddress;
this._ensResolverAddress = ensResolverAddress;
this._assetManager = IdentityManager__factory.connect(assetManagerAddress, this._signer);
this._ensRegistry = ENSRegistry__factory.connect(ensRegistryAddress, this._provider);
this._domainDefinitionReader = new DomainReader({ ensRegistryAddress, provider: this._provider });
ensPublicResolverAddress &&
this._domainDefinitionReader.addKnownResolver({
chainId,
address: ensPublicResolverAddress,
type: ResolverContractType.PublicResolver,
});
ensResolverAddress &&
this._domainDefinitionReader.addKnownResolver({
chainId,
address: ensResolverAddress,
type: ResolverContractType.RoleDefinitionResolver_v1,
});
this._domainDefinitionTransactionFactory = new DomainTransactionFactory({
domainResolverAddress: ensResolverAddress,
});
this._domainHierarchy = new DomainHierarchy({
domainReader: this._domainDefinitionReader,
ensRegistryAddress: this._ensRegistry.address,
provider: this._provider,
domainNotifierAddress: domainNotifierAddress,
publicResolverAddress: ensPublicResolverAddress,
});
this._claimManager = ClaimManager__factory.connect(claimManagerAddress, this._signer);
this._messagingOptions = messagingOptions[chainId];
}
// ### ASSETS ###
protected offerAssetTx({
offerTo,
assetContractAddress,
}: {
offerTo: string;
assetContractAddress: string;
}): EncodedCall {
const asset = OfferableIdentity__factory.connect(assetContractAddress, this._provider);
return {
data: asset.interface.encodeFunctionData("offer", [offerTo]),
to: assetContractAddress,
};
}
protected acceptOfferTx({ assetContractAddress }: { assetContractAddress: string }): EncodedCall {
const asset = OfferableIdentity__factory.connect(assetContractAddress, this._provider);
return {
data: asset.interface.encodeFunctionData("acceptOffer"),
to: assetContractAddress,
};
}
protected rejectOfferTx({ assetContractAddress }: { assetContractAddress: string }): EncodedCall {
const asset = OfferableIdentity__factory.connect(assetContractAddress, this._provider);
return {
data: asset.interface.encodeFunctionData("rejectOffer"),
to: assetContractAddress,
};
}
protected cancelOfferTx({ assetContractAddress }: { assetContractAddress: string }): EncodedCall {
const asset = OfferableIdentity__factory.connect(assetContractAddress, this._provider);
return {
data: asset.interface.encodeFunctionData("cancelOffer"),
to: assetContractAddress,
};
}
}