@cheqd/did-provider-cheqd 4.2.0 → 4.3.0-develop.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/build/cjs/agent/ICheqd.d.ts +32 -2
- package/build/cjs/agent/ICheqd.d.ts.map +1 -1
- package/build/cjs/agent/ICheqd.js +110 -63
- package/build/cjs/agent/ICheqd.js.map +1 -1
- package/build/cjs/did-manager/cheqd-did-provider.d.ts +20 -2
- package/build/cjs/did-manager/cheqd-did-provider.d.ts.map +1 -1
- package/build/cjs/did-manager/cheqd-did-provider.js +71 -2
- package/build/cjs/did-manager/cheqd-did-provider.js.map +1 -1
- package/build/cjs/dkg-threshold/lit-protocol/v6.d.ts +50 -5
- package/build/cjs/dkg-threshold/lit-protocol/v6.d.ts.map +1 -1
- package/build/cjs/dkg-threshold/lit-protocol/v6.js +123 -8
- package/build/cjs/dkg-threshold/lit-protocol/v6.js.map +1 -1
- package/build/esm/agent/ICheqd.d.ts +32 -2
- package/build/esm/agent/ICheqd.d.ts.map +1 -1
- package/build/esm/agent/ICheqd.js +109 -62
- package/build/esm/agent/ICheqd.js.map +1 -1
- package/build/esm/did-manager/cheqd-did-provider.d.ts +20 -2
- package/build/esm/did-manager/cheqd-did-provider.d.ts.map +1 -1
- package/build/esm/did-manager/cheqd-did-provider.js +73 -4
- package/build/esm/did-manager/cheqd-did-provider.js.map +1 -1
- package/build/esm/dkg-threshold/lit-protocol/v6.d.ts +50 -5
- package/build/esm/dkg-threshold/lit-protocol/v6.d.ts.map +1 -1
- package/build/esm/dkg-threshold/lit-protocol/v6.js +98 -7
- package/build/esm/dkg-threshold/lit-protocol/v6.js.map +1 -1
- package/build/tsconfig.cjs.tsbuildinfo +1 -1
- package/build/tsconfig.esm.tsbuildinfo +1 -1
- package/build/tsconfig.types.tsbuildinfo +1 -1
- package/build/types/agent/ICheqd.d.ts +32 -2
- package/build/types/agent/ICheqd.d.ts.map +1 -1
- package/build/types/did-manager/cheqd-did-provider.d.ts +20 -2
- package/build/types/did-manager/cheqd-did-provider.d.ts.map +1 -1
- package/build/types/dkg-threshold/lit-protocol/v6.d.ts +50 -5
- package/build/types/dkg-threshold/lit-protocol/v6.d.ts.map +1 -1
- package/package.json +23 -18
- package/src/agent/ICheqd.ts +176 -64
- package/src/did-manager/cheqd-did-provider.ts +130 -5
- package/src/dkg-threshold/lit-protocol/v6.ts +147 -12
package/src/agent/ICheqd.ts
CHANGED
|
@@ -62,10 +62,12 @@ import fs from 'fs';
|
|
|
62
62
|
import Debug from 'debug';
|
|
63
63
|
import {
|
|
64
64
|
CosmosAccessControlCondition,
|
|
65
|
+
CreateCapacityDelegationAuthSignatureResult,
|
|
65
66
|
LitCompatibleCosmosChain,
|
|
66
67
|
LitCompatibleCosmosChains,
|
|
67
68
|
LitNetwork,
|
|
68
69
|
LitProtocol,
|
|
70
|
+
MintCapacityCreditsResult,
|
|
69
71
|
} from '../dkg-threshold/lit-protocol/v6.js';
|
|
70
72
|
import {
|
|
71
73
|
blobToHexString,
|
|
@@ -342,6 +344,16 @@ export type ObservationResult = {
|
|
|
342
344
|
error?: IError;
|
|
343
345
|
};
|
|
344
346
|
|
|
347
|
+
export type MintCapacityCreditResult = {
|
|
348
|
+
minted: boolean;
|
|
349
|
+
error?: IError;
|
|
350
|
+
} & Partial<MintCapacityCreditsResult>;
|
|
351
|
+
|
|
352
|
+
export type DelegateCapacityCreditResult = {
|
|
353
|
+
delegated: boolean;
|
|
354
|
+
error?: IError;
|
|
355
|
+
} & Partial<CreateCapacityDelegationAuthSignatureResult>;
|
|
356
|
+
|
|
345
357
|
export const AccessControlConditionTypes = {
|
|
346
358
|
timelockPayment: 'timelockPayment',
|
|
347
359
|
memoNonce: 'memoNonce',
|
|
@@ -383,6 +395,8 @@ export const UnsuspendCredentialMethodName = 'cheqdUnsuspendCredential';
|
|
|
383
395
|
export const UnsuspendCredentialsMethodName = 'cheqdUnsuspendCredentials';
|
|
384
396
|
export const TransactSendTokensMethodName = 'cheqdTransactSendTokens';
|
|
385
397
|
export const ObservePaymentConditionMethodName = 'cheqdObservePaymentCondition';
|
|
398
|
+
export const MintCapacityCreditMethodName = 'cheqdMintCapacityCredit';
|
|
399
|
+
export const DelegateCapacityCreditMethodName = 'cheqdDelegateCapacityCredit';
|
|
386
400
|
|
|
387
401
|
export const DidPrefix = 'did';
|
|
388
402
|
export const CheqdDidMethod = 'cheqd';
|
|
@@ -651,6 +665,23 @@ export interface ICheqdObservePaymentConditionArgs {
|
|
|
651
665
|
returnTxResponse?: boolean;
|
|
652
666
|
}
|
|
653
667
|
|
|
668
|
+
export interface ICheqdMintCapacityCreditArgs {
|
|
669
|
+
network: CheqdNetwork;
|
|
670
|
+
effectiveDays: number;
|
|
671
|
+
requestsPerDay?: number;
|
|
672
|
+
requestsPerSecond?: number;
|
|
673
|
+
requestsPerKilosecond?: number;
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
export interface ICheqdDelegateCapacityCreditArgs {
|
|
677
|
+
network: CheqdNetwork;
|
|
678
|
+
capacityTokenId: string;
|
|
679
|
+
delegateeAddresses: string[];
|
|
680
|
+
usesPermitted: number;
|
|
681
|
+
expiration?: string;
|
|
682
|
+
statement?: string;
|
|
683
|
+
}
|
|
684
|
+
|
|
654
685
|
export interface ICheqdStatusList2021Options {
|
|
655
686
|
statusListFile?: string;
|
|
656
687
|
statusListInlineBitstring?: string;
|
|
@@ -786,6 +817,14 @@ export interface ICheqd extends IPluginMethodMap {
|
|
|
786
817
|
args: ICheqdObservePaymentConditionArgs,
|
|
787
818
|
context: IContext
|
|
788
819
|
) => Promise<ObservationResult>;
|
|
820
|
+
[MintCapacityCreditMethodName]: (
|
|
821
|
+
args: ICheqdMintCapacityCreditArgs,
|
|
822
|
+
context: IContext
|
|
823
|
+
) => Promise<MintCapacityCreditResult>;
|
|
824
|
+
[DelegateCapacityCreditMethodName]: (
|
|
825
|
+
args: ICheqdDelegateCapacityCreditArgs,
|
|
826
|
+
context: IContext
|
|
827
|
+
) => Promise<DelegateCapacityCreditResult>;
|
|
789
828
|
}
|
|
790
829
|
|
|
791
830
|
export class Cheqd implements IAgentPlugin {
|
|
@@ -1238,6 +1277,8 @@ export class Cheqd implements IAgentPlugin {
|
|
|
1238
1277
|
[UnsuspendCredentialsMethodName]: this.UnsuspendBulkCredentialsWithStatusList2021.bind(this),
|
|
1239
1278
|
[TransactSendTokensMethodName]: this.TransactSendTokens.bind(this),
|
|
1240
1279
|
[ObservePaymentConditionMethodName]: this.ObservePaymentCondition.bind(this),
|
|
1280
|
+
[MintCapacityCreditMethodName]: this.MintCapacityCredit.bind(this),
|
|
1281
|
+
[DelegateCapacityCreditMethodName]: this.DelegateCapacityCredit.bind(this),
|
|
1241
1282
|
};
|
|
1242
1283
|
}
|
|
1243
1284
|
|
|
@@ -1257,7 +1298,7 @@ export class Cheqd implements IAgentPlugin {
|
|
|
1257
1298
|
throw new Error('[did-provider-cheqd]: document object is required');
|
|
1258
1299
|
}
|
|
1259
1300
|
|
|
1260
|
-
const provider = await Cheqd.
|
|
1301
|
+
const provider = await Cheqd.getProviderFromDidUrl(args.document.id, this.supportedDidProviders);
|
|
1261
1302
|
|
|
1262
1303
|
this.didProvider = provider;
|
|
1263
1304
|
this.providerId = Cheqd.generateProviderId(this.didProvider.network);
|
|
@@ -1287,7 +1328,7 @@ export class Cheqd implements IAgentPlugin {
|
|
|
1287
1328
|
throw new Error('[did-provider-cheqd]: document object is required');
|
|
1288
1329
|
}
|
|
1289
1330
|
|
|
1290
|
-
const provider = await Cheqd.
|
|
1331
|
+
const provider = await Cheqd.getProviderFromDidUrl(args.document.id, this.supportedDidProviders);
|
|
1291
1332
|
|
|
1292
1333
|
this.didProvider = provider;
|
|
1293
1334
|
this.providerId = Cheqd.generateProviderId(this.didProvider.network);
|
|
@@ -1313,7 +1354,7 @@ export class Cheqd implements IAgentPlugin {
|
|
|
1313
1354
|
throw new Error('[did-provider-cheqd]: document object is required');
|
|
1314
1355
|
}
|
|
1315
1356
|
|
|
1316
|
-
const provider = await Cheqd.
|
|
1357
|
+
const provider = await Cheqd.getProviderFromDidUrl(args.document.id, this.supportedDidProviders);
|
|
1317
1358
|
|
|
1318
1359
|
this.didProvider = provider;
|
|
1319
1360
|
this.providerId = Cheqd.generateProviderId(this.didProvider.network);
|
|
@@ -1353,7 +1394,7 @@ export class Cheqd implements IAgentPlugin {
|
|
|
1353
1394
|
}
|
|
1354
1395
|
|
|
1355
1396
|
this.providerId = Cheqd.generateProviderId(args.network);
|
|
1356
|
-
this.didProvider = await Cheqd.
|
|
1397
|
+
this.didProvider = await Cheqd.getProviderFromNetwork(args.network, this.supportedDidProviders);
|
|
1357
1398
|
|
|
1358
1399
|
return await this.didProvider.createResource(
|
|
1359
1400
|
{
|
|
@@ -1485,6 +1526,17 @@ export class Cheqd implements IAgentPlugin {
|
|
|
1485
1526
|
// get network
|
|
1486
1527
|
const network = args.issuerDid.split(':')[2];
|
|
1487
1528
|
|
|
1529
|
+
// define provider
|
|
1530
|
+
const provider = (function (that) {
|
|
1531
|
+
// switch on network
|
|
1532
|
+
return (
|
|
1533
|
+
that.supportedDidProviders.find((provider) => provider.network === network) ||
|
|
1534
|
+
(function () {
|
|
1535
|
+
throw new Error(`[did-provider-cheqd]: no relevant providers found`);
|
|
1536
|
+
})()
|
|
1537
|
+
);
|
|
1538
|
+
})(this);
|
|
1539
|
+
|
|
1488
1540
|
// generate bitstring
|
|
1489
1541
|
const bitstring = await context.agent[GenerateStatusList2021MethodName]({
|
|
1490
1542
|
length: args?.statusListLength || Cheqd.defaultStatusList2021Length,
|
|
@@ -1501,10 +1553,7 @@ export class Cheqd implements IAgentPlugin {
|
|
|
1501
1553
|
);
|
|
1502
1554
|
|
|
1503
1555
|
// instantiate dkg-threshold client, in which case lit-protocol is used
|
|
1504
|
-
const lit = await
|
|
1505
|
-
chain: args?.dkgOptions?.chain || that.didProvider.dkgOptions.chain,
|
|
1506
|
-
litNetwork: args?.dkgOptions?.network || that.didProvider.dkgOptions.network,
|
|
1507
|
-
});
|
|
1556
|
+
const lit = await provider.instantiateDkgThresholdProtocolClient({});
|
|
1508
1557
|
|
|
1509
1558
|
// construct access control conditions
|
|
1510
1559
|
const unifiedAccessControlConditions = await Promise.all(
|
|
@@ -1702,7 +1751,7 @@ export class Cheqd implements IAgentPlugin {
|
|
|
1702
1751
|
}
|
|
1703
1752
|
|
|
1704
1753
|
this.providerId = Cheqd.generateProviderId(args.network);
|
|
1705
|
-
this.didProvider = await Cheqd.
|
|
1754
|
+
this.didProvider = await Cheqd.getProviderFromNetwork(args.network, this.supportedDidProviders);
|
|
1706
1755
|
|
|
1707
1756
|
return await this.didProvider.createResource(
|
|
1708
1757
|
{
|
|
@@ -1998,7 +2047,7 @@ export class Cheqd implements IAgentPlugin {
|
|
|
1998
2047
|
typeof credential.issuer === 'string' ? credential.issuer : (credential.issuer as { id: string }).id;
|
|
1999
2048
|
|
|
2000
2049
|
// define provider, if applicable
|
|
2001
|
-
this.didProvider = await Cheqd.
|
|
2050
|
+
this.didProvider = await Cheqd.getProviderFromDidUrl(issuer, this.supportedDidProviders);
|
|
2002
2051
|
|
|
2003
2052
|
// define provider id, if applicable
|
|
2004
2053
|
this.providerId = Cheqd.generateProviderId(issuer);
|
|
@@ -2058,7 +2107,7 @@ export class Cheqd implements IAgentPlugin {
|
|
|
2058
2107
|
typeof credential.issuer === 'string' ? credential.issuer : (credential.issuer as { id: string }).id;
|
|
2059
2108
|
|
|
2060
2109
|
// define provider, if applicable
|
|
2061
|
-
this.didProvider = await Cheqd.
|
|
2110
|
+
this.didProvider = await Cheqd.getProviderFromDidUrl(issuer, this.supportedDidProviders);
|
|
2062
2111
|
|
|
2063
2112
|
// define provider id, if applicable
|
|
2064
2113
|
this.providerId = Cheqd.generateProviderId(issuer);
|
|
@@ -2162,7 +2211,7 @@ export class Cheqd implements IAgentPlugin {
|
|
|
2162
2211
|
typeof credential.issuer === 'string' ? credential.issuer : (credential.issuer as { id: string }).id;
|
|
2163
2212
|
|
|
2164
2213
|
// define provider, if applicable
|
|
2165
|
-
this.didProvider = await Cheqd.
|
|
2214
|
+
this.didProvider = await Cheqd.getProviderFromDidUrl(issuer, this.supportedDidProviders);
|
|
2166
2215
|
|
|
2167
2216
|
// define provider id, if applicable
|
|
2168
2217
|
this.providerId = Cheqd.generateProviderId(issuer);
|
|
@@ -2276,7 +2325,7 @@ export class Cheqd implements IAgentPlugin {
|
|
|
2276
2325
|
typeof credential.issuer === 'string' ? credential.issuer : (credential.issuer as { id: string }).id;
|
|
2277
2326
|
|
|
2278
2327
|
// define provider, if applicable
|
|
2279
|
-
this.didProvider = await Cheqd.
|
|
2328
|
+
this.didProvider = await Cheqd.getProviderFromDidUrl(issuer, this.supportedDidProviders);
|
|
2280
2329
|
|
|
2281
2330
|
// define provider id, if applicable
|
|
2282
2331
|
this.providerId = Cheqd.generateProviderId(issuer);
|
|
@@ -2413,7 +2462,7 @@ export class Cheqd implements IAgentPlugin {
|
|
|
2413
2462
|
: (credentials[0].issuer as { id: string }).id;
|
|
2414
2463
|
|
|
2415
2464
|
// define provider, if applicable
|
|
2416
|
-
this.didProvider = await Cheqd.
|
|
2465
|
+
this.didProvider = await Cheqd.getProviderFromDidUrl(issuer, this.supportedDidProviders);
|
|
2417
2466
|
|
|
2418
2467
|
// define provider id, if applicable
|
|
2419
2468
|
this.providerId = Cheqd.generateProviderId(issuer);
|
|
@@ -2530,7 +2579,7 @@ export class Cheqd implements IAgentPlugin {
|
|
|
2530
2579
|
typeof credential.issuer === 'string' ? credential.issuer : (credential.issuer as { id: string }).id;
|
|
2531
2580
|
|
|
2532
2581
|
// define provider, if applicable
|
|
2533
|
-
this.didProvider = await Cheqd.
|
|
2582
|
+
this.didProvider = await Cheqd.getProviderFromDidUrl(issuer, this.supportedDidProviders);
|
|
2534
2583
|
|
|
2535
2584
|
// define provider id, if applicable
|
|
2536
2585
|
this.providerId = Cheqd.generateProviderId(issuer);
|
|
@@ -2667,7 +2716,7 @@ export class Cheqd implements IAgentPlugin {
|
|
|
2667
2716
|
: (credentials[0].issuer as { id: string }).id;
|
|
2668
2717
|
|
|
2669
2718
|
// define provider, if applicable
|
|
2670
|
-
this.didProvider = await Cheqd.
|
|
2719
|
+
this.didProvider = await Cheqd.getProviderFromDidUrl(issuer, this.supportedDidProviders);
|
|
2671
2720
|
|
|
2672
2721
|
// define provider id, if applicable
|
|
2673
2722
|
this.providerId = Cheqd.generateProviderId(issuer);
|
|
@@ -2784,7 +2833,7 @@ export class Cheqd implements IAgentPlugin {
|
|
|
2784
2833
|
typeof credential.issuer === 'string' ? credential.issuer : (credential.issuer as { id: string }).id;
|
|
2785
2834
|
|
|
2786
2835
|
// define provider, if applicable
|
|
2787
|
-
this.didProvider = await Cheqd.
|
|
2836
|
+
this.didProvider = await Cheqd.getProviderFromDidUrl(issuer, this.supportedDidProviders);
|
|
2788
2837
|
|
|
2789
2838
|
// define provider id, if applicable
|
|
2790
2839
|
this.providerId = Cheqd.generateProviderId(issuer);
|
|
@@ -2921,7 +2970,7 @@ export class Cheqd implements IAgentPlugin {
|
|
|
2921
2970
|
: (credentials[0].issuer as { id: string }).id;
|
|
2922
2971
|
|
|
2923
2972
|
// define provider, if applicable
|
|
2924
|
-
this.didProvider = await Cheqd.
|
|
2973
|
+
this.didProvider = await Cheqd.getProviderFromDidUrl(issuer, this.supportedDidProviders);
|
|
2925
2974
|
|
|
2926
2975
|
// define provider id, if applicable
|
|
2927
2976
|
this.providerId = Cheqd.generateProviderId(issuer);
|
|
@@ -2949,15 +2998,7 @@ export class Cheqd implements IAgentPlugin {
|
|
|
2949
2998
|
context: IContext
|
|
2950
2999
|
): Promise<TransactionResult> {
|
|
2951
3000
|
// define provider
|
|
2952
|
-
const provider = (
|
|
2953
|
-
// switch on network
|
|
2954
|
-
return (
|
|
2955
|
-
that.supportedDidProviders.find((provider) => provider.network === args.network) ||
|
|
2956
|
-
(function () {
|
|
2957
|
-
throw new Error(`[did-provider-cheqd]: transact: no relevant providers found`);
|
|
2958
|
-
})()
|
|
2959
|
-
);
|
|
2960
|
-
})(this);
|
|
3001
|
+
const provider = await Cheqd.getProviderFromNetwork(args.network, this.supportedDidProviders);
|
|
2961
3002
|
|
|
2962
3003
|
try {
|
|
2963
3004
|
// delegate to provider
|
|
@@ -3230,6 +3271,67 @@ export class Cheqd implements IAgentPlugin {
|
|
|
3230
3271
|
}
|
|
3231
3272
|
}
|
|
3232
3273
|
|
|
3274
|
+
private async MintCapacityCredit(
|
|
3275
|
+
args: ICheqdMintCapacityCreditArgs,
|
|
3276
|
+
context: IContext
|
|
3277
|
+
): Promise<MintCapacityCreditResult> {
|
|
3278
|
+
// define provider
|
|
3279
|
+
const provider = await Cheqd.getProviderFromNetwork(args.network, this.supportedDidProviders);
|
|
3280
|
+
|
|
3281
|
+
try {
|
|
3282
|
+
// delegate to provider
|
|
3283
|
+
const mintingResult = await provider.mintCapacityCredit({
|
|
3284
|
+
effectiveDays: args.effectiveDays,
|
|
3285
|
+
requestsPerDay: args.requestsPerDay,
|
|
3286
|
+
requestsPerSecond: args.requestsPerSecond,
|
|
3287
|
+
requestsPerKilosecond: args.requestsPerKilosecond,
|
|
3288
|
+
});
|
|
3289
|
+
|
|
3290
|
+
// return mint result
|
|
3291
|
+
return {
|
|
3292
|
+
minted: true,
|
|
3293
|
+
...mintingResult,
|
|
3294
|
+
} satisfies MintCapacityCreditResult;
|
|
3295
|
+
} catch (error) {
|
|
3296
|
+
// return error
|
|
3297
|
+
return {
|
|
3298
|
+
minted: false,
|
|
3299
|
+
error: error as IError,
|
|
3300
|
+
} satisfies MintCapacityCreditResult;
|
|
3301
|
+
}
|
|
3302
|
+
}
|
|
3303
|
+
|
|
3304
|
+
private async DelegateCapacityCredit(
|
|
3305
|
+
args: ICheqdDelegateCapacityCreditArgs,
|
|
3306
|
+
context: IContext
|
|
3307
|
+
): Promise<DelegateCapacityCreditResult> {
|
|
3308
|
+
// define provider
|
|
3309
|
+
const provider = await Cheqd.getProviderFromNetwork(args.network, this.supportedDidProviders);
|
|
3310
|
+
|
|
3311
|
+
try {
|
|
3312
|
+
// delegate to provider
|
|
3313
|
+
const delegationResult = await provider.delegateCapacityCredit({
|
|
3314
|
+
capacityTokenId: args.capacityTokenId,
|
|
3315
|
+
delegateeAddresses: args.delegateeAddresses,
|
|
3316
|
+
uses: args.usesPermitted,
|
|
3317
|
+
expiration: args.expiration,
|
|
3318
|
+
statement: args.statement,
|
|
3319
|
+
});
|
|
3320
|
+
|
|
3321
|
+
// return delegation result
|
|
3322
|
+
return {
|
|
3323
|
+
delegated: true,
|
|
3324
|
+
...delegationResult,
|
|
3325
|
+
} satisfies DelegateCapacityCreditResult;
|
|
3326
|
+
} catch (error) {
|
|
3327
|
+
// return error
|
|
3328
|
+
return {
|
|
3329
|
+
delegated: false,
|
|
3330
|
+
error: error as IError,
|
|
3331
|
+
} satisfies DelegateCapacityCreditResult;
|
|
3332
|
+
}
|
|
3333
|
+
}
|
|
3334
|
+
|
|
3233
3335
|
static async revokeCredential(
|
|
3234
3336
|
credential: VerifiableCredential,
|
|
3235
3337
|
options?: ICheqdStatusList2021Options
|
|
@@ -3501,10 +3603,7 @@ export class Cheqd implements IAgentPlugin {
|
|
|
3501
3603
|
} = await LitProtocol.encryptDirect(fromString(bitstring, 'base64url'));
|
|
3502
3604
|
|
|
3503
3605
|
// instantiate dkg-threshold client, in which case lit-protocol is used
|
|
3504
|
-
const lit = await LitProtocol
|
|
3505
|
-
chain: topArgs?.dkgOptions?.chain,
|
|
3506
|
-
litNetwork: topArgs?.dkgOptions?.network,
|
|
3507
|
-
});
|
|
3606
|
+
const lit = (await options!.publishOptions.instantiateDkgClient) as LitProtocol;
|
|
3508
3607
|
|
|
3509
3608
|
// construct access control conditions and payment conditions tuple
|
|
3510
3609
|
const unifiedAccessControlConditionsTuple = publishedList.metadata.encrypted
|
|
@@ -4093,10 +4192,7 @@ export class Cheqd implements IAgentPlugin {
|
|
|
4093
4192
|
} = await LitProtocol.encryptDirect(fromString(bitstring, 'base64url'));
|
|
4094
4193
|
|
|
4095
4194
|
// instantiate dkg-threshold client, in which case lit-protocol is used
|
|
4096
|
-
const lit = await LitProtocol
|
|
4097
|
-
chain: topArgs?.dkgOptions?.chain,
|
|
4098
|
-
litNetwork: topArgs?.dkgOptions?.network,
|
|
4099
|
-
});
|
|
4195
|
+
const lit = (await options!.publishOptions.instantiateDkgClient) as LitProtocol;
|
|
4100
4196
|
|
|
4101
4197
|
// construct access control conditions and payment conditions tuple
|
|
4102
4198
|
const unifiedAccessControlConditionsTuple = publishedList.metadata.encrypted
|
|
@@ -4609,10 +4705,7 @@ export class Cheqd implements IAgentPlugin {
|
|
|
4609
4705
|
} = await LitProtocol.encryptDirect(fromString(bitstring, 'base64url'));
|
|
4610
4706
|
|
|
4611
4707
|
// instantiate dkg-threshold client, in which case lit-protocol is used
|
|
4612
|
-
const lit = await LitProtocol
|
|
4613
|
-
chain: topArgs?.dkgOptions?.chain,
|
|
4614
|
-
litNetwork: topArgs?.dkgOptions?.network,
|
|
4615
|
-
});
|
|
4708
|
+
const lit = (await options!.publishOptions.instantiateDkgClient) as LitProtocol;
|
|
4616
4709
|
|
|
4617
4710
|
// construct access control conditions and payment conditions tuple
|
|
4618
4711
|
const unifiedAccessControlConditionsTuple = publishedList.metadata.encrypted
|
|
@@ -5201,10 +5294,7 @@ export class Cheqd implements IAgentPlugin {
|
|
|
5201
5294
|
} = await LitProtocol.encryptDirect(fromString(bitstring, 'base64url'));
|
|
5202
5295
|
|
|
5203
5296
|
// instantiate dkg-threshold client, in which case lit-protocol is used
|
|
5204
|
-
const lit = await LitProtocol
|
|
5205
|
-
chain: topArgs?.dkgOptions?.chain,
|
|
5206
|
-
litNetwork: topArgs?.dkgOptions?.network,
|
|
5207
|
-
});
|
|
5297
|
+
const lit = (await options!.publishOptions.instantiateDkgClient) as LitProtocol;
|
|
5208
5298
|
|
|
5209
5299
|
// construct access control conditions and payment conditions tuple
|
|
5210
5300
|
const unifiedAccessControlConditionsTuple = publishedList.metadata.encrypted
|
|
@@ -5716,10 +5806,7 @@ export class Cheqd implements IAgentPlugin {
|
|
|
5716
5806
|
} = await LitProtocol.encryptDirect(fromString(bitstring, 'base64url'));
|
|
5717
5807
|
|
|
5718
5808
|
// instantiate dkg-threshold client, in which case lit-protocol is used
|
|
5719
|
-
const lit = await LitProtocol
|
|
5720
|
-
chain: topArgs?.dkgOptions?.chain,
|
|
5721
|
-
litNetwork: topArgs?.dkgOptions?.network,
|
|
5722
|
-
});
|
|
5809
|
+
const lit = (await options!.publishOptions.instantiateDkgClient) as LitProtocol;
|
|
5723
5810
|
|
|
5724
5811
|
// construct access control conditions and payment conditions tuple
|
|
5725
5812
|
const unifiedAccessControlConditionsTuple = publishedList.metadata.encrypted
|
|
@@ -6308,10 +6395,7 @@ export class Cheqd implements IAgentPlugin {
|
|
|
6308
6395
|
} = await LitProtocol.encryptDirect(fromString(bitstring, 'base64url'));
|
|
6309
6396
|
|
|
6310
6397
|
// instantiate dkg-threshold client, in which case lit-protocol is used
|
|
6311
|
-
const lit = await LitProtocol
|
|
6312
|
-
chain: topArgs?.dkgOptions?.chain,
|
|
6313
|
-
litNetwork: topArgs?.dkgOptions?.network,
|
|
6314
|
-
});
|
|
6398
|
+
const lit = (await options!.publishOptions.instantiateDkgClient) as LitProtocol;
|
|
6315
6399
|
|
|
6316
6400
|
// construct access control conditions and payment conditions tuple
|
|
6317
6401
|
const unifiedAccessControlConditionsTuple = publishedList.metadata.encrypted
|
|
@@ -6565,6 +6649,11 @@ export class Cheqd implements IAgentPlugin {
|
|
|
6565
6649
|
);
|
|
6566
6650
|
}
|
|
6567
6651
|
|
|
6652
|
+
// validate dkgOptions
|
|
6653
|
+
if (!options?.topArgs?.dkgOptions || !options.topArgs?.dkgOptions?.capacityDelegationAuthSignature) {
|
|
6654
|
+
throw new Error('[did-provider-cheqd]: dkgOptions is required');
|
|
6655
|
+
}
|
|
6656
|
+
|
|
6568
6657
|
// fetch status list 2021
|
|
6569
6658
|
const publishedList = (await Cheqd.fetchStatusList2021(credential)) as StatusList2021Revocation;
|
|
6570
6659
|
|
|
@@ -6602,10 +6691,7 @@ export class Cheqd implements IAgentPlugin {
|
|
|
6602
6691
|
)[1];
|
|
6603
6692
|
|
|
6604
6693
|
// instantiate dkg-threshold client, in which case lit-protocol is used
|
|
6605
|
-
const lit = await LitProtocol
|
|
6606
|
-
chain: options?.topArgs?.dkgOptions?.chain,
|
|
6607
|
-
litNetwork: options?.topArgs?.dkgOptions?.network,
|
|
6608
|
-
});
|
|
6694
|
+
const lit = (await options.instantiateDkgClient) as LitProtocol;
|
|
6609
6695
|
|
|
6610
6696
|
// construct access control conditions
|
|
6611
6697
|
const unifiedAccessControlConditions = await Promise.all(
|
|
@@ -6635,7 +6721,8 @@ export class Cheqd implements IAgentPlugin {
|
|
|
6635
6721
|
return await lit.decrypt(
|
|
6636
6722
|
thresholdEncryptionCiphertext,
|
|
6637
6723
|
publishedList.metadata.statusListHash!,
|
|
6638
|
-
unifiedAccessControlConditions
|
|
6724
|
+
unifiedAccessControlConditions,
|
|
6725
|
+
options?.topArgs?.dkgOptions?.capacityDelegationAuthSignature
|
|
6639
6726
|
);
|
|
6640
6727
|
})()
|
|
6641
6728
|
: await (async function () {
|
|
@@ -6739,6 +6826,11 @@ export class Cheqd implements IAgentPlugin {
|
|
|
6739
6826
|
);
|
|
6740
6827
|
}
|
|
6741
6828
|
|
|
6829
|
+
// validate dkgOptions
|
|
6830
|
+
if (!options?.topArgs?.dkgOptions || !options.topArgs?.dkgOptions?.capacityDelegationAuthSignature) {
|
|
6831
|
+
throw new Error('[did-provider-cheqd]: dkgOptions is required');
|
|
6832
|
+
}
|
|
6833
|
+
|
|
6742
6834
|
// fetch status list 2021
|
|
6743
6835
|
const publishedList = (await Cheqd.fetchStatusList2021(credential)) as StatusList2021Suspension;
|
|
6744
6836
|
|
|
@@ -6772,10 +6864,7 @@ export class Cheqd implements IAgentPlugin {
|
|
|
6772
6864
|
)[1];
|
|
6773
6865
|
|
|
6774
6866
|
// instantiate dkg-threshold client, in which case lit-protocol is used
|
|
6775
|
-
const lit = await LitProtocol
|
|
6776
|
-
chain: options?.topArgs?.dkgOptions?.chain,
|
|
6777
|
-
litNetwork: options?.topArgs?.dkgOptions?.network,
|
|
6778
|
-
});
|
|
6867
|
+
const lit = (await options.instantiateDkgClient) as LitProtocol;
|
|
6779
6868
|
|
|
6780
6869
|
// construct access control conditions
|
|
6781
6870
|
const unifiedAccessControlConditions = await Promise.all(
|
|
@@ -6805,7 +6894,8 @@ export class Cheqd implements IAgentPlugin {
|
|
|
6805
6894
|
return await lit.decrypt(
|
|
6806
6895
|
thresholdEncryptionCiphertext,
|
|
6807
6896
|
publishedList.metadata.statusListHash!,
|
|
6808
|
-
unifiedAccessControlConditions
|
|
6897
|
+
unifiedAccessControlConditions,
|
|
6898
|
+
options?.topArgs?.dkgOptions?.capacityDelegationAuthSignature
|
|
6809
6899
|
);
|
|
6810
6900
|
})()
|
|
6811
6901
|
: await (async function () {
|
|
@@ -7330,12 +7420,34 @@ export class Cheqd implements IAgentPlugin {
|
|
|
7330
7420
|
);
|
|
7331
7421
|
}
|
|
7332
7422
|
|
|
7333
|
-
static async
|
|
7423
|
+
static async getProviderFromDidUrl(
|
|
7424
|
+
didUrl: string,
|
|
7425
|
+
providers: CheqdDIDProvider[],
|
|
7426
|
+
message?: string
|
|
7427
|
+
): Promise<CheqdDIDProvider> {
|
|
7334
7428
|
const provider = providers.find((provider) =>
|
|
7335
|
-
didUrl.includes(`${DidPrefix}:${CheqdDidMethod}:${provider.network}
|
|
7429
|
+
didUrl.includes(`${DidPrefix}:${CheqdDidMethod}:${provider.network}:`)
|
|
7336
7430
|
);
|
|
7337
7431
|
if (!provider) {
|
|
7338
|
-
throw new Error(
|
|
7432
|
+
throw new Error(
|
|
7433
|
+
message ||
|
|
7434
|
+
`[did-provider-cheqd]: no relevant providers found for did url ${didUrl}: loaded providers: ${providers.map((provider) => `${DidPrefix}:${CheqdDidMethod}:${provider.network}`).join(', ')}`
|
|
7435
|
+
);
|
|
7436
|
+
}
|
|
7437
|
+
return provider;
|
|
7438
|
+
}
|
|
7439
|
+
|
|
7440
|
+
static async getProviderFromNetwork(
|
|
7441
|
+
network: CheqdNetwork,
|
|
7442
|
+
providers: CheqdDIDProvider[],
|
|
7443
|
+
message?: string
|
|
7444
|
+
): Promise<CheqdDIDProvider> {
|
|
7445
|
+
const provider = providers.find((provider) => provider.network === network);
|
|
7446
|
+
if (!provider) {
|
|
7447
|
+
throw new Error(
|
|
7448
|
+
message ||
|
|
7449
|
+
`[did-provider-cheqd]: no relevant providers found for network ${network}: loaded providers: ${providers.map((provider) => `${DidPrefix}:${CheqdDidMethod}:${provider.network}`).join(', ')}`
|
|
7450
|
+
);
|
|
7339
7451
|
}
|
|
7340
7452
|
return provider;
|
|
7341
7453
|
}
|
|
@@ -34,19 +34,24 @@ import {
|
|
|
34
34
|
import { AbstractIdentifierProvider } from '@veramo/did-manager';
|
|
35
35
|
import { base64ToBytes, extractPublicKeyHex } from '@veramo/utils';
|
|
36
36
|
import Debug from 'debug';
|
|
37
|
-
import { EnglishMnemonic as _, Ed25519 } from '@cosmjs/crypto';
|
|
37
|
+
import { EnglishMnemonic as _, Bip39, Ed25519, Random } from '@cosmjs/crypto';
|
|
38
38
|
import { fromString, toString } from 'uint8arrays';
|
|
39
39
|
import { MsgCreateDidDocPayload, MsgDeactivateDidDocPayload, SignInfo } from '@cheqd/ts-proto/cheqd/did/v2/index.js';
|
|
40
40
|
import { v4 } from 'uuid';
|
|
41
41
|
import {
|
|
42
|
+
CreateCapacityDelegationAuthSignatureResult,
|
|
42
43
|
LitCompatibleCosmosChain,
|
|
43
44
|
LitCompatibleCosmosChains,
|
|
44
45
|
LitNetwork,
|
|
45
46
|
LitNetworks,
|
|
47
|
+
LitProtocol,
|
|
48
|
+
LitContracts,
|
|
49
|
+
MintCapacityCreditsResult,
|
|
46
50
|
} from '../dkg-threshold/lit-protocol/v6.js';
|
|
47
|
-
import { IContext } from '../agent/ICheqd.js';
|
|
51
|
+
import { DkgOptions, IContext } from '../agent/ICheqd.js';
|
|
48
52
|
import { getControllers } from '../utils/helpers.js';
|
|
49
|
-
|
|
53
|
+
import { Secp256k1HdWallet, Secp256k1Wallet } from '@cosmjs/amino';
|
|
54
|
+
import { ethers } from 'ethers';
|
|
50
55
|
const debug = Debug('veramo:did-provider-cheqd');
|
|
51
56
|
|
|
52
57
|
export const DefaultRPCUrls = {
|
|
@@ -438,6 +443,8 @@ export class CheqdDIDProvider extends AbstractIdentifierProvider {
|
|
|
438
443
|
public readonly network: CheqdNetwork;
|
|
439
444
|
public readonly rpcUrl: string;
|
|
440
445
|
private readonly cosmosPayerWallet: Promise<DirectSecp256k1HdWallet | DirectSecp256k1Wallet>;
|
|
446
|
+
private readonly _aminoSigner: Promise<Secp256k1HdWallet | Secp256k1Wallet>;
|
|
447
|
+
private readonly ethereumAuthWallet: ethers.HDNodeWallet | ethers.Wallet;
|
|
441
448
|
public readonly dkgOptions: {
|
|
442
449
|
chain: Extract<LitCompatibleCosmosChain, 'cheqdTestnet' | 'cheqdMainnet'>;
|
|
443
450
|
network: LitNetwork;
|
|
@@ -471,18 +478,50 @@ export class CheqdDIDProvider extends AbstractIdentifierProvider {
|
|
|
471
478
|
: { chain: DefaultDkgSupportedChains[this.network], network: LitNetworks.datildev };
|
|
472
479
|
|
|
473
480
|
if (!options?.cosmosPayerSeed || options.cosmosPayerSeed === '') {
|
|
474
|
-
|
|
481
|
+
// generate mnemonic, if not provided
|
|
482
|
+
const mnemonic = Bip39.encode(Random.getBytes(32)).toString();
|
|
483
|
+
|
|
484
|
+
// setup wallets - case: cosmos direct payer wallet
|
|
485
|
+
this.cosmosPayerWallet = DirectSecp256k1HdWallet.fromMnemonic(mnemonic);
|
|
486
|
+
|
|
487
|
+
// setup wallets - case: ethereum signer wallet
|
|
488
|
+
this.ethereumAuthWallet = ethers.Wallet.fromPhrase(mnemonic);
|
|
489
|
+
|
|
490
|
+
// setup wallets - case: amino signer wallet
|
|
491
|
+
this._aminoSigner = Secp256k1HdWallet.fromMnemonic(mnemonic);
|
|
492
|
+
|
|
475
493
|
return;
|
|
476
494
|
}
|
|
477
|
-
|
|
495
|
+
|
|
496
|
+
const isMnemonic = EnglishMnemonic._mnemonicMatcher.test(options.cosmosPayerSeed);
|
|
497
|
+
|
|
498
|
+
this.cosmosPayerWallet = isMnemonic
|
|
478
499
|
? DirectSecp256k1HdWallet.fromMnemonic(options.cosmosPayerSeed, { prefix: 'cheqd' })
|
|
479
500
|
: DirectSecp256k1Wallet.fromKey(fromString(options.cosmosPayerSeed.replace(/^0x/, ''), 'hex'), 'cheqd');
|
|
501
|
+
|
|
502
|
+
this.ethereumAuthWallet = isMnemonic
|
|
503
|
+
? ethers.Wallet.fromPhrase(options.cosmosPayerSeed)
|
|
504
|
+
: new ethers.Wallet(options.cosmosPayerSeed);
|
|
505
|
+
|
|
506
|
+
this._aminoSigner = isMnemonic
|
|
507
|
+
? Secp256k1HdWallet.fromMnemonic(options.cosmosPayerSeed, { prefix: 'cheqd' })
|
|
508
|
+
: Secp256k1Wallet.fromKey(fromString(options.cosmosPayerSeed.replace(/^0x/, ''), 'hex'), 'cheqd');
|
|
480
509
|
}
|
|
481
510
|
|
|
482
511
|
async getWalletAccounts(): Promise<readonly AccountData[]> {
|
|
483
512
|
return await (await this.cosmosPayerWallet).getAccounts();
|
|
484
513
|
}
|
|
485
514
|
|
|
515
|
+
async getEthereumWalletAccounts(): Promise<readonly AccountData[]> {
|
|
516
|
+
return [
|
|
517
|
+
{
|
|
518
|
+
address: this.ethereumAuthWallet.address,
|
|
519
|
+
pubkey: fromString(this.ethereumAuthWallet.signingKey.publicKey, 'hex'),
|
|
520
|
+
algo: 'secp256k1',
|
|
521
|
+
},
|
|
522
|
+
];
|
|
523
|
+
}
|
|
524
|
+
|
|
486
525
|
private async getCheqdSDK(fee?: DidStdFee, gasPrice?: GasPrice): Promise<CheqdSDK> {
|
|
487
526
|
if (!this.sdk) {
|
|
488
527
|
const wallet = await this.cosmosPayerWallet.catch(() => {
|
|
@@ -970,6 +1009,92 @@ export class CheqdDIDProvider extends AbstractIdentifierProvider {
|
|
|
970
1009
|
return tx;
|
|
971
1010
|
}
|
|
972
1011
|
|
|
1012
|
+
async mintCapacityCredit(args: {
|
|
1013
|
+
effectiveDays: number;
|
|
1014
|
+
requestsPerDay?: number;
|
|
1015
|
+
requestsPerSecond?: number;
|
|
1016
|
+
requestsPerKilosecond?: number;
|
|
1017
|
+
}): Promise<MintCapacityCreditsResult> {
|
|
1018
|
+
// instantiate dkg-threshold contract client, in which case lit-protocol is used
|
|
1019
|
+
const litContracts = await this.instantiateDkgThresholdContractClient();
|
|
1020
|
+
|
|
1021
|
+
// mint capacity credits
|
|
1022
|
+
const result = await litContracts.mintCapacityCredits(args);
|
|
1023
|
+
|
|
1024
|
+
// keep log
|
|
1025
|
+
debug(
|
|
1026
|
+
'Minted capacity credits',
|
|
1027
|
+
result.capacityTokenIdStr,
|
|
1028
|
+
'for',
|
|
1029
|
+
args.effectiveDays,
|
|
1030
|
+
'days',
|
|
1031
|
+
'with transaction hash',
|
|
1032
|
+
result.rliTxHash,
|
|
1033
|
+
'from address',
|
|
1034
|
+
this.ethereumAuthWallet.address
|
|
1035
|
+
);
|
|
1036
|
+
|
|
1037
|
+
return result;
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
async delegateCapacityCredit(args: {
|
|
1041
|
+
capacityTokenId: string;
|
|
1042
|
+
delegateeAddresses: string[];
|
|
1043
|
+
uses: number;
|
|
1044
|
+
expiration?: string;
|
|
1045
|
+
statement?: string;
|
|
1046
|
+
}): Promise<CreateCapacityDelegationAuthSignatureResult> {
|
|
1047
|
+
// instantiate dkg-threshold client, in which case lit-protocol is used
|
|
1048
|
+
const litProtocol = await this.instantiateDkgThresholdProtocolClient();
|
|
1049
|
+
|
|
1050
|
+
// delegate capacity credits
|
|
1051
|
+
const result = await litProtocol.delegateCapacitCredit({
|
|
1052
|
+
dAppOwnerWallet:
|
|
1053
|
+
this.ethereumAuthWallet instanceof ethers.Wallet
|
|
1054
|
+
? this.ethereumAuthWallet
|
|
1055
|
+
: new ethers.Wallet(this.ethereumAuthWallet.privateKey),
|
|
1056
|
+
capacityTokenId: args.capacityTokenId,
|
|
1057
|
+
delegateeAddresses: args.delegateeAddresses,
|
|
1058
|
+
uses: args.uses.toString(),
|
|
1059
|
+
expiration: args.expiration,
|
|
1060
|
+
statement: args.statement,
|
|
1061
|
+
});
|
|
1062
|
+
|
|
1063
|
+
// keep log
|
|
1064
|
+
debug(
|
|
1065
|
+
'Delegated capacity credits',
|
|
1066
|
+
args.capacityTokenId,
|
|
1067
|
+
'to',
|
|
1068
|
+
args.delegateeAddresses.join(', '),
|
|
1069
|
+
'with auth signature',
|
|
1070
|
+
result.capacityDelegationAuthSig.sig,
|
|
1071
|
+
'from address',
|
|
1072
|
+
this.ethereumAuthWallet.address
|
|
1073
|
+
);
|
|
1074
|
+
|
|
1075
|
+
return result;
|
|
1076
|
+
}
|
|
1077
|
+
|
|
1078
|
+
async instantiateDkgThresholdProtocolClient(dkgOptions: DkgOptions = this.dkgOptions): Promise<LitProtocol> {
|
|
1079
|
+
return await LitProtocol.create({
|
|
1080
|
+
chain: dkgOptions.chain || this.dkgOptions.chain,
|
|
1081
|
+
litNetwork: dkgOptions.network || this.dkgOptions.network,
|
|
1082
|
+
cosmosAuthWallet: await this._aminoSigner,
|
|
1083
|
+
});
|
|
1084
|
+
}
|
|
1085
|
+
|
|
1086
|
+
async instantiateDkgThresholdContractClient(
|
|
1087
|
+
dkgNetwork: LitNetwork = this.dkgOptions.network
|
|
1088
|
+
): Promise<LitContracts> {
|
|
1089
|
+
return await LitContracts.create({
|
|
1090
|
+
ethereumAuthWallet:
|
|
1091
|
+
this.ethereumAuthWallet instanceof ethers.Wallet
|
|
1092
|
+
? this.ethereumAuthWallet
|
|
1093
|
+
: new ethers.Wallet(this.ethereumAuthWallet.privateKey),
|
|
1094
|
+
litNetwork: dkgNetwork,
|
|
1095
|
+
});
|
|
1096
|
+
}
|
|
1097
|
+
|
|
973
1098
|
private async signPayload(
|
|
974
1099
|
context: IAgentContext<IKeyManager>,
|
|
975
1100
|
data: Uint8Array,
|