@cheqd/did-provider-cheqd 4.4.1 → 4.5.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/esm/did-manager/cheqd-did-provider.d.ts.map +1 -1
- package/build/esm/did-manager/cheqd-did-provider.js +2 -1
- package/build/esm/did-manager/cheqd-did-provider.js.map +1 -1
- package/build/esm/utils/helpers.d.ts +1 -1
- package/build/esm/utils/helpers.d.ts.map +1 -1
- package/build/tsconfig.esm.tsbuildinfo +1 -1
- package/build/tsconfig.types.tsbuildinfo +1 -1
- package/build/types/did-manager/cheqd-did-provider.d.ts.map +1 -1
- package/build/types/utils/helpers.d.ts +1 -1
- package/build/types/utils/helpers.d.ts.map +1 -1
- package/package.json +3 -9
- package/src/did-manager/cheqd-did-provider.ts +2 -0
- package/src/utils/helpers.ts +1 -1
- package/tsconfig.json +1 -1
- package/build/cjs/agent/ICheqd.d.ts +0 -769
- package/build/cjs/agent/ICheqd.d.ts.map +0 -1
- package/build/cjs/agent/ICheqd.js +0 -4399
- package/build/cjs/agent/ICheqd.js.map +0 -1
- package/build/cjs/agent/index.d.ts +0 -2
- package/build/cjs/agent/index.d.ts.map +0 -1
- package/build/cjs/agent/index.js +0 -18
- package/build/cjs/agent/index.js.map +0 -1
- package/build/cjs/did-manager/cheqd-did-provider.d.ts +0 -233
- package/build/cjs/did-manager/cheqd-did-provider.d.ts.map +0 -1
- package/build/cjs/did-manager/cheqd-did-provider.js +0 -750
- package/build/cjs/did-manager/cheqd-did-provider.js.map +0 -1
- package/build/cjs/did-manager/cheqd-did-resolver.d.ts +0 -26
- package/build/cjs/did-manager/cheqd-did-resolver.d.ts.map +0 -1
- package/build/cjs/did-manager/cheqd-did-resolver.js +0 -52
- package/build/cjs/did-manager/cheqd-did-resolver.js.map +0 -1
- package/build/cjs/did-manager/index.d.ts +0 -4
- package/build/cjs/did-manager/index.d.ts.map +0 -1
- package/build/cjs/did-manager/index.js +0 -20
- package/build/cjs/did-manager/index.js.map +0 -1
- package/build/cjs/did-manager/resolver.d.ts +0 -47
- package/build/cjs/did-manager/resolver.d.ts.map +0 -1
- package/build/cjs/did-manager/resolver.js +0 -75
- package/build/cjs/did-manager/resolver.js.map +0 -1
- package/build/cjs/dkg-threshold/index.d.ts +0 -2
- package/build/cjs/dkg-threshold/index.d.ts.map +0 -1
- package/build/cjs/dkg-threshold/index.js +0 -18
- package/build/cjs/dkg-threshold/index.js.map +0 -1
- package/build/cjs/dkg-threshold/lit-protocol/v2.d.ts +0 -95
- package/build/cjs/dkg-threshold/lit-protocol/v2.d.ts.map +0 -1
- package/build/cjs/dkg-threshold/lit-protocol/v2.js +0 -193
- package/build/cjs/dkg-threshold/lit-protocol/v2.js.map +0 -1
- package/build/cjs/dkg-threshold/lit-protocol/v3.d.ts +0 -95
- package/build/cjs/dkg-threshold/lit-protocol/v3.d.ts.map +0 -1
- package/build/cjs/dkg-threshold/lit-protocol/v3.js +0 -232
- package/build/cjs/dkg-threshold/lit-protocol/v3.js.map +0 -1
- package/build/cjs/dkg-threshold/lit-protocol/v6.d.ts +0 -131
- package/build/cjs/dkg-threshold/lit-protocol/v6.d.ts.map +0 -1
- package/build/cjs/dkg-threshold/lit-protocol/v6.js +0 -345
- package/build/cjs/dkg-threshold/lit-protocol/v6.js.map +0 -1
- package/build/cjs/index.d.ts +0 -9
- package/build/cjs/index.d.ts.map +0 -1
- package/build/cjs/index.js +0 -25
- package/build/cjs/index.js.map +0 -1
- package/build/cjs/utils/constants.d.ts +0 -2
- package/build/cjs/utils/constants.d.ts.map +0 -1
- package/build/cjs/utils/constants.js +0 -5
- package/build/cjs/utils/constants.js.map +0 -1
- package/build/cjs/utils/env.d.ts +0 -7
- package/build/cjs/utils/env.d.ts.map +0 -1
- package/build/cjs/utils/env.js +0 -19
- package/build/cjs/utils/env.js.map +0 -1
- package/build/cjs/utils/helpers.d.ts +0 -18
- package/build/cjs/utils/helpers.d.ts.map +0 -1
- package/build/cjs/utils/helpers.js +0 -112
- package/build/cjs/utils/helpers.js.map +0 -1
- package/build/cjs/utils/index.d.ts +0 -3
- package/build/cjs/utils/index.d.ts.map +0 -1
- package/build/cjs/utils/index.js +0 -19
- package/build/cjs/utils/index.js.map +0 -1
- package/build/tsconfig.cjs.tsbuildinfo +0 -1
|
@@ -1,750 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.CheqdDIDProvider = exports.CheqdSignInfoProvider = exports.EnglishMnemonic = exports.CheqdProviderErrorCodes = exports.CheqdProviderError = exports.DefaultStatusList2021Encodings = exports.DefaultStatusList2021ResourceTypes = exports.DefaultStatusList2021StatusPurposeTypes = exports.DefaultDkgSupportedChains = exports.DefaultRESTUrls = exports.DefaultRPCUrls = void 0;
|
|
7
|
-
exports.createMsgCreateDidDocPayloadToSign = createMsgCreateDidDocPayloadToSign;
|
|
8
|
-
exports.createMsgDeactivateDidDocPayloadToSign = createMsgDeactivateDidDocPayloadToSign;
|
|
9
|
-
/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars, @typescript-eslint/no-non-null-assertion */
|
|
10
|
-
// any is used for extensibility
|
|
11
|
-
// unused vars are kept by convention
|
|
12
|
-
// non-null assertion is used when we know better than the compiler that the value is not null or undefined
|
|
13
|
-
const sdk_1 = require("@cheqd/sdk");
|
|
14
|
-
const index_js_1 = require("@cheqd/ts-proto/cheqd/resource/v2/index.js");
|
|
15
|
-
const proto_signing_1 = require("@cosmjs/proto-signing");
|
|
16
|
-
const stargate_1 = require("@cosmjs/stargate");
|
|
17
|
-
const utils_1 = require("@cosmjs/utils");
|
|
18
|
-
const did_manager_1 = require("@veramo/did-manager");
|
|
19
|
-
const utils_2 = require("@veramo/utils");
|
|
20
|
-
const debug_1 = __importDefault(require("debug"));
|
|
21
|
-
const crypto_1 = require("@cosmjs/crypto");
|
|
22
|
-
const uint8arrays_1 = require("uint8arrays");
|
|
23
|
-
const index_js_2 = require("@cheqd/ts-proto/cheqd/did/v2/index.js");
|
|
24
|
-
const uuid_1 = require("uuid");
|
|
25
|
-
const v6_js_1 = require("../dkg-threshold/lit-protocol/v6.js");
|
|
26
|
-
const helpers_js_1 = require("../utils/helpers.js");
|
|
27
|
-
const amino_1 = require("@cosmjs/amino");
|
|
28
|
-
const ethers_1 = require("ethers");
|
|
29
|
-
const debug = (0, debug_1.default)('veramo:did-provider-cheqd');
|
|
30
|
-
exports.DefaultRPCUrls = {
|
|
31
|
-
[sdk_1.CheqdNetwork.Mainnet]: 'https://rpc.cheqd.net',
|
|
32
|
-
[sdk_1.CheqdNetwork.Testnet]: 'https://rpc.cheqd.network',
|
|
33
|
-
};
|
|
34
|
-
exports.DefaultRESTUrls = {
|
|
35
|
-
[sdk_1.CheqdNetwork.Mainnet]: 'https://api.cheqd.net',
|
|
36
|
-
[sdk_1.CheqdNetwork.Testnet]: 'https://api.cheqd.network',
|
|
37
|
-
};
|
|
38
|
-
exports.DefaultDkgSupportedChains = {
|
|
39
|
-
[sdk_1.CheqdNetwork.Mainnet]: v6_js_1.LitCompatibleCosmosChains.cheqdMainnet,
|
|
40
|
-
[sdk_1.CheqdNetwork.Testnet]: v6_js_1.LitCompatibleCosmosChains.cheqdTestnet,
|
|
41
|
-
};
|
|
42
|
-
exports.DefaultStatusList2021StatusPurposeTypes = {
|
|
43
|
-
revocation: 'revocation',
|
|
44
|
-
suspension: 'suspension',
|
|
45
|
-
};
|
|
46
|
-
exports.DefaultStatusList2021ResourceTypes = {
|
|
47
|
-
default: 'StatusList2021',
|
|
48
|
-
revocation: 'StatusList2021Revocation',
|
|
49
|
-
suspension: 'StatusList2021Suspension',
|
|
50
|
-
};
|
|
51
|
-
exports.DefaultStatusList2021Encodings = {
|
|
52
|
-
base64url: 'base64url',
|
|
53
|
-
hex: 'hex',
|
|
54
|
-
};
|
|
55
|
-
class CheqdProviderError extends Error {
|
|
56
|
-
errorCode;
|
|
57
|
-
constructor(message, errorCode) {
|
|
58
|
-
super(message);
|
|
59
|
-
this.errorCode = errorCode;
|
|
60
|
-
this.errorCode = errorCode;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
exports.CheqdProviderError = CheqdProviderError;
|
|
64
|
-
exports.CheqdProviderErrorCodes = {
|
|
65
|
-
DeactivatedController: 'DeactivatedController',
|
|
66
|
-
UnresolvedDID: 'UnresolvedDID',
|
|
67
|
-
EmptyVerificationMethod: 'EmptyVerificationMethod',
|
|
68
|
-
};
|
|
69
|
-
class EnglishMnemonic extends crypto_1.EnglishMnemonic {
|
|
70
|
-
static _mnemonicMatcher = /^[a-z]+( [a-z]+)*$/;
|
|
71
|
-
}
|
|
72
|
-
exports.EnglishMnemonic = EnglishMnemonic;
|
|
73
|
-
class CheqdSignInfoProvider {
|
|
74
|
-
context;
|
|
75
|
-
signInfos;
|
|
76
|
-
publicKeyHexs;
|
|
77
|
-
controllers;
|
|
78
|
-
controllerKeys;
|
|
79
|
-
controllerKeyRefs;
|
|
80
|
-
constructor(context) {
|
|
81
|
-
this.signInfos = [];
|
|
82
|
-
this.publicKeyHexs = [];
|
|
83
|
-
this.controllerKeys = [];
|
|
84
|
-
this.controllerKeyRefs = [];
|
|
85
|
-
this.controllers = [];
|
|
86
|
-
this.context = context;
|
|
87
|
-
}
|
|
88
|
-
setPublicKeyHexs(publicKeyHexs) {
|
|
89
|
-
this.publicKeyHexs = publicKeyHexs;
|
|
90
|
-
}
|
|
91
|
-
setSignInfos(signInfos) {
|
|
92
|
-
this.signInfos = signInfos;
|
|
93
|
-
}
|
|
94
|
-
setControllers(controllers) {
|
|
95
|
-
this.controllers = controllers;
|
|
96
|
-
}
|
|
97
|
-
getSignInfos() {
|
|
98
|
-
return this.signInfos;
|
|
99
|
-
}
|
|
100
|
-
getPublicKeyHexs() {
|
|
101
|
-
return this.publicKeyHexs;
|
|
102
|
-
}
|
|
103
|
-
getControllerKeys() {
|
|
104
|
-
return this.controllerKeys;
|
|
105
|
-
}
|
|
106
|
-
getControllerKeyRefs() {
|
|
107
|
-
return this.controllerKeyRefs;
|
|
108
|
-
}
|
|
109
|
-
getControllerKeysForSigning() {
|
|
110
|
-
const keys = [];
|
|
111
|
-
this.controllers.forEach((controller) => {
|
|
112
|
-
const key = this.controllerKeys.find((key) => key.controller === controller);
|
|
113
|
-
if (key) {
|
|
114
|
-
keys.push(key);
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
return keys;
|
|
118
|
-
}
|
|
119
|
-
async compilePublicKeyHexs(controllers, options) {
|
|
120
|
-
const publicKeyHexs = options.publicKeyHexs || [];
|
|
121
|
-
if (publicKeyHexs.length === 0) {
|
|
122
|
-
for (const controller of controllers) {
|
|
123
|
-
const key = await this.context.agent
|
|
124
|
-
.didManagerGet({ did: controller })
|
|
125
|
-
.then((result) => result.keys[0]);
|
|
126
|
-
publicKeyHexs.push(key.kid);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
this.setPublicKeyHexs(publicKeyHexs);
|
|
130
|
-
}
|
|
131
|
-
async compileSignInfos(payload, controllers) {
|
|
132
|
-
// 1. Iterate over the contollers and for each - get DIDDocument and get the verificationMethodId associated with one of publicKeyHexs
|
|
133
|
-
// 1.1 Iterate over the list of verificationMethods and make the checks:
|
|
134
|
-
// 1.1.1 Iterate over publicKeyHexs and convert each publicKeyHex to the verification Material
|
|
135
|
-
// 1.1.2 If it compares with the one in the verificationMethod, then we have a match and can store the pair of verificationMethodId and publicKeyHex
|
|
136
|
-
// 2. Iterate over the pair of verificationMethodIds and publicKeys and create SignInfo§
|
|
137
|
-
// Setup
|
|
138
|
-
const signInfos = [];
|
|
139
|
-
const publicKeyHexs = this.getPublicKeyHexs();
|
|
140
|
-
// Get verificationMethodIds
|
|
141
|
-
const verificationMethodIds = [];
|
|
142
|
-
// Iterate over list of controllers and tries to get the corresponding verificationMethodId associated with one of publicKeyHexs
|
|
143
|
-
for (const controller of controllers) {
|
|
144
|
-
// We need to get here current version of DIDDocument associated with the controller and cannot skip it even if document.id === controller
|
|
145
|
-
// cause in case of remooving verifcation method we need to sign the payload with the old verification method which is on ledger.
|
|
146
|
-
const controllerResolutionResult = await this.context.agent.resolveDid({ didUrl: controller });
|
|
147
|
-
const controllerDidDocument = controllerResolutionResult.didDocument;
|
|
148
|
-
// Check if controller DID document is resolved
|
|
149
|
-
if (!controllerDidDocument) {
|
|
150
|
-
throw new CheqdProviderError('[did-provider-cheqd]: compileSignInfos: Error while resolving the DID document for controller DID: ' +
|
|
151
|
-
controller, exports.CheqdProviderErrorCodes.UnresolvedDID);
|
|
152
|
-
}
|
|
153
|
-
// Check that controller's DIDDocument is active
|
|
154
|
-
if (controllerResolutionResult.didDocumentMetadata.deactivated) {
|
|
155
|
-
throw new CheqdProviderError(`[did-provider-cheqd]: compileSignInfos: DIDDocument associated with controller ${controller} is deactivated`, exports.CheqdProviderErrorCodes.DeactivatedController);
|
|
156
|
-
}
|
|
157
|
-
// Check if controller DID document contains verification methods
|
|
158
|
-
if (!controllerDidDocument.verificationMethod) {
|
|
159
|
-
throw new CheqdProviderError('[did-provider-cheqd]: compileSignInfos: Controller DID document does not contain verification methods', exports.CheqdProviderErrorCodes.EmptyVerificationMethod);
|
|
160
|
-
}
|
|
161
|
-
// Iterate over verificationMethods and by comparing publicKeys get the verificationMethod Id
|
|
162
|
-
for (const vm of controllerDidDocument.verificationMethod) {
|
|
163
|
-
// Try to match verificationMethod with one of publicKeyHexs
|
|
164
|
-
for (const publicKeyHex of publicKeyHexs) {
|
|
165
|
-
// Get publicKeyHex from verificationMethod
|
|
166
|
-
const vmPublicKey = (0, utils_2.extractPublicKeyHex)(vm).publicKeyHex;
|
|
167
|
-
// Compare publicKeys
|
|
168
|
-
if (publicKeyHex === vmPublicKey) {
|
|
169
|
-
// Create SignInfo object
|
|
170
|
-
signInfos.push({
|
|
171
|
-
verificationMethodId: vm.id,
|
|
172
|
-
signature: (0, utils_2.base64ToBytes)(await this.context.agent.keyManagerSign({
|
|
173
|
-
keyRef: publicKeyHex,
|
|
174
|
-
data: (0, uint8arrays_1.toString)(payload, 'hex'),
|
|
175
|
-
encoding: 'hex',
|
|
176
|
-
})),
|
|
177
|
-
});
|
|
178
|
-
// Setup controllerKeyRefs
|
|
179
|
-
this.controllerKeyRefs.push(publicKeyHex);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
// Setup key structure for display
|
|
183
|
-
const kid = (0, utils_2.extractPublicKeyHex)(vm).publicKeyHex;
|
|
184
|
-
const key = await this.context.agent.keyManagerGet({ kid });
|
|
185
|
-
this.controllerKeys.push({ ...key, controller: vm.controller });
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
// Setup signInfos
|
|
189
|
-
this.setSignInfos(signInfos);
|
|
190
|
-
}
|
|
191
|
-
async updateIdentifierCompileSignInfos(didDocument, options) {
|
|
192
|
-
// Steps to solve the issue:
|
|
193
|
-
// 1. Collect list of controllers. The user can remove, append and reqrite the controller.
|
|
194
|
-
// But we need to send all the signatures, old and news
|
|
195
|
-
// 2. Generate payloads
|
|
196
|
-
// 3. Compile list of signInfos
|
|
197
|
-
// Get current version of DIDDocument
|
|
198
|
-
const actualDIDDocument = await this.context.agent.resolveDid({ didUrl: didDocument.id });
|
|
199
|
-
if (!actualDIDDocument.didDocument) {
|
|
200
|
-
throw new Error('[did-provider-cheqd]: updateIdentifierSignInfos: Error while resolving the DID document for updating with error: ' +
|
|
201
|
-
actualDIDDocument.didResolutionMetadata.error);
|
|
202
|
-
}
|
|
203
|
-
// Compile controllers
|
|
204
|
-
const updatedControllers = (0, helpers_js_1.getControllers)(didDocument);
|
|
205
|
-
const actualControllers = (0, helpers_js_1.getControllers)(actualDIDDocument.didDocument);
|
|
206
|
-
const controllers = [...new Set([...updatedControllers, ...actualControllers])];
|
|
207
|
-
// Generate payload
|
|
208
|
-
const versionId = options.versionId || (0, uuid_1.v4)();
|
|
209
|
-
const payload = await createMsgCreateDidDocPayloadToSign(didDocument, versionId);
|
|
210
|
-
// Setup publicKeyHexs
|
|
211
|
-
await this.compilePublicKeyHexs(controllers, options);
|
|
212
|
-
// Setup controllers. Here it's supposed to be a list of controllers which are associated with the DIDDocument
|
|
213
|
-
this.setControllers(updatedControllers);
|
|
214
|
-
// Setup SignInfos
|
|
215
|
-
await this.compileSignInfos(payload, controllers);
|
|
216
|
-
}
|
|
217
|
-
async deactivateIdentifierCompileSignInfos(didDocument, options) {
|
|
218
|
-
// Steps to solve the issue:
|
|
219
|
-
// 1. Collect list of controllers. The user can remove, append and reqrite the controller.
|
|
220
|
-
// But we need to send all the signatures, old and news
|
|
221
|
-
// Generate payload to sign
|
|
222
|
-
// 3. Compile list of signInfos
|
|
223
|
-
// Get Controllers
|
|
224
|
-
const controllers = (0, helpers_js_1.getControllers)(didDocument);
|
|
225
|
-
// For did deactivation ledger requires the signature from original DID Document controller
|
|
226
|
-
// So we need to add the controller to the list of controllers
|
|
227
|
-
if (!controllers.includes(didDocument.id)) {
|
|
228
|
-
controllers.push(didDocument.id);
|
|
229
|
-
}
|
|
230
|
-
// Generate payload
|
|
231
|
-
const versionId = options.versionId || (0, uuid_1.v4)();
|
|
232
|
-
const payload = await createMsgDeactivateDidDocPayloadToSign(didDocument, versionId);
|
|
233
|
-
// Setup publicKeyHexs
|
|
234
|
-
await this.compilePublicKeyHexs(controllers, options);
|
|
235
|
-
// Setup SignInfos
|
|
236
|
-
await this.compileSignInfos(payload, controllers);
|
|
237
|
-
}
|
|
238
|
-
async resourceCreateCompileSignInfos(did, resourcePayload, options) {
|
|
239
|
-
// Steps to solve the issue:
|
|
240
|
-
// 1. Collect list of controllers. The user can remove, append and reqrite the controller.
|
|
241
|
-
// But we need to send all the signatures, old and news
|
|
242
|
-
// Generate payload to sign
|
|
243
|
-
// 3. Compile list of signInfos
|
|
244
|
-
const didDocument = await this.context.agent.resolveDid({ didUrl: did }).then((result) => result.didDocument);
|
|
245
|
-
if (!didDocument) {
|
|
246
|
-
throw new Error('[did-provider-cheqd]: resourceCreateCompileSignInfos: Erro while resolving the DID document for controller DID: ' +
|
|
247
|
-
did);
|
|
248
|
-
}
|
|
249
|
-
// Get Controllers
|
|
250
|
-
const controllers = (0, helpers_js_1.getControllers)(didDocument);
|
|
251
|
-
// For resource creation ledger requires the signature from original DID Document controller
|
|
252
|
-
// So we need to add the controller to the list of controllers
|
|
253
|
-
if (!controllers.includes(did)) {
|
|
254
|
-
controllers.push(did);
|
|
255
|
-
}
|
|
256
|
-
// Generate payload
|
|
257
|
-
const payload = await index_js_1.MsgCreateResourcePayload.encode(index_js_1.MsgCreateResourcePayload.fromPartial(resourcePayload)).finish();
|
|
258
|
-
// Setup publicKeyHexs
|
|
259
|
-
await this.compilePublicKeyHexs(controllers, options);
|
|
260
|
-
// Setup SignInfos
|
|
261
|
-
await this.compileSignInfos(payload, controllers);
|
|
262
|
-
}
|
|
263
|
-
async keysAreInKMS(publicKeys) {
|
|
264
|
-
for (const keyRef of publicKeys) {
|
|
265
|
-
try {
|
|
266
|
-
await this.context.agent.keyManagerGet({ kid: keyRef });
|
|
267
|
-
}
|
|
268
|
-
catch (e) {
|
|
269
|
-
return {
|
|
270
|
-
placed: false,
|
|
271
|
-
error: `PublicKey: ${keyRef} is not placed in kms`,
|
|
272
|
-
};
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
return {
|
|
276
|
-
placed: true,
|
|
277
|
-
};
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
exports.CheqdSignInfoProvider = CheqdSignInfoProvider;
|
|
281
|
-
/**
|
|
282
|
-
* {@link @veramo/did-manager#DIDManager} identifier provider for `did:cheqd` identifiers.
|
|
283
|
-
* @public
|
|
284
|
-
*/
|
|
285
|
-
class CheqdDIDProvider extends did_manager_1.AbstractIdentifierProvider {
|
|
286
|
-
defaultKms;
|
|
287
|
-
network;
|
|
288
|
-
rpcUrl;
|
|
289
|
-
cosmosPayerWallet;
|
|
290
|
-
_aminoSigner;
|
|
291
|
-
ethereumAuthWallet;
|
|
292
|
-
dkgOptions;
|
|
293
|
-
sdk;
|
|
294
|
-
fee;
|
|
295
|
-
static defaultGasPrice = stargate_1.GasPrice.fromString('50ncheq');
|
|
296
|
-
constructor(options) {
|
|
297
|
-
super();
|
|
298
|
-
this.defaultKms = options.defaultKms;
|
|
299
|
-
this.network = options.networkType ? options.networkType : sdk_1.CheqdNetwork.Testnet;
|
|
300
|
-
this.rpcUrl = options.rpcUrl ? options.rpcUrl : exports.DefaultRPCUrls[this.network];
|
|
301
|
-
this.dkgOptions = options.dkgOptions
|
|
302
|
-
? {
|
|
303
|
-
chain: options.dkgOptions.chain
|
|
304
|
-
? options.dkgOptions.chain
|
|
305
|
-
: exports.DefaultDkgSupportedChains[this.network],
|
|
306
|
-
network: options.dkgOptions.network ? options.dkgOptions.network : v6_js_1.LitNetworks.datildev,
|
|
307
|
-
}
|
|
308
|
-
: { chain: exports.DefaultDkgSupportedChains[this.network], network: v6_js_1.LitNetworks.datildev };
|
|
309
|
-
if (!options?.cosmosPayerSeed || options.cosmosPayerSeed === '') {
|
|
310
|
-
// generate mnemonic, if not provided
|
|
311
|
-
const mnemonic = crypto_1.Bip39.encode(crypto_1.Random.getBytes(32)).toString();
|
|
312
|
-
// setup wallets - case: cosmos direct payer wallet
|
|
313
|
-
this.cosmosPayerWallet = proto_signing_1.DirectSecp256k1HdWallet.fromMnemonic(mnemonic);
|
|
314
|
-
// setup wallets - case: ethereum signer wallet
|
|
315
|
-
this.ethereumAuthWallet = ethers_1.ethers.Wallet.fromPhrase(mnemonic);
|
|
316
|
-
// setup wallets - case: amino signer wallet
|
|
317
|
-
this._aminoSigner = amino_1.Secp256k1HdWallet.fromMnemonic(mnemonic);
|
|
318
|
-
return;
|
|
319
|
-
}
|
|
320
|
-
const isMnemonic = EnglishMnemonic._mnemonicMatcher.test(options.cosmosPayerSeed);
|
|
321
|
-
this.cosmosPayerWallet = isMnemonic
|
|
322
|
-
? proto_signing_1.DirectSecp256k1HdWallet.fromMnemonic(options.cosmosPayerSeed, { prefix: 'cheqd' })
|
|
323
|
-
: proto_signing_1.DirectSecp256k1Wallet.fromKey((0, uint8arrays_1.fromString)(options.cosmosPayerSeed.replace(/^0x/, ''), 'hex'), 'cheqd');
|
|
324
|
-
this.ethereumAuthWallet = isMnemonic
|
|
325
|
-
? ethers_1.ethers.Wallet.fromPhrase(options.cosmosPayerSeed)
|
|
326
|
-
: new ethers_1.ethers.Wallet(options.cosmosPayerSeed);
|
|
327
|
-
this._aminoSigner = isMnemonic
|
|
328
|
-
? amino_1.Secp256k1HdWallet.fromMnemonic(options.cosmosPayerSeed, { prefix: 'cheqd' })
|
|
329
|
-
: amino_1.Secp256k1Wallet.fromKey((0, uint8arrays_1.fromString)(options.cosmosPayerSeed.replace(/^0x/, ''), 'hex'), 'cheqd');
|
|
330
|
-
}
|
|
331
|
-
async getWalletAccounts() {
|
|
332
|
-
return await (await this.cosmosPayerWallet).getAccounts();
|
|
333
|
-
}
|
|
334
|
-
async getEthereumWalletAccounts() {
|
|
335
|
-
return [
|
|
336
|
-
{
|
|
337
|
-
address: this.ethereumAuthWallet.address,
|
|
338
|
-
pubkey: (0, uint8arrays_1.fromString)(this.ethereumAuthWallet.signingKey.publicKey, 'hex'),
|
|
339
|
-
algo: 'secp256k1',
|
|
340
|
-
},
|
|
341
|
-
];
|
|
342
|
-
}
|
|
343
|
-
async getCheqdSDK(fee, gasPrice) {
|
|
344
|
-
if (!this.sdk) {
|
|
345
|
-
const wallet = await this.cosmosPayerWallet.catch(() => {
|
|
346
|
-
throw new Error(`[did-provider-cheqd]: network: ${this.network} valid cosmosPayerSeed is required`);
|
|
347
|
-
});
|
|
348
|
-
const sdkOptions = {
|
|
349
|
-
modules: [
|
|
350
|
-
sdk_1.DIDModule,
|
|
351
|
-
sdk_1.ResourceModule,
|
|
352
|
-
],
|
|
353
|
-
rpcUrl: this.rpcUrl,
|
|
354
|
-
wallet: wallet,
|
|
355
|
-
gasPrice,
|
|
356
|
-
};
|
|
357
|
-
this.sdk = await (0, sdk_1.createCheqdSDK)(sdkOptions);
|
|
358
|
-
this.fee = fee;
|
|
359
|
-
if (this?.fee && !this?.fee?.payer) {
|
|
360
|
-
const feePayer = (await (await this.cosmosPayerWallet).getAccounts())[0].address;
|
|
361
|
-
this.fee.payer = feePayer;
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
return this.sdk;
|
|
365
|
-
}
|
|
366
|
-
async createIdentifier({ kms, options, }, context) {
|
|
367
|
-
const sdk = await this.getCheqdSDK(options?.fee);
|
|
368
|
-
const versionId = options.versionId || (0, uuid_1.v4)();
|
|
369
|
-
const signInputs = options.keys
|
|
370
|
-
? (function () {
|
|
371
|
-
return options.keys.map((key) => (0, sdk_1.createSignInputsFromImportableEd25519Key)(key, options.document.verificationMethod || []));
|
|
372
|
-
})()
|
|
373
|
-
: await (async function (that) {
|
|
374
|
-
const data = await createMsgCreateDidDocPayloadToSign(options.document, versionId);
|
|
375
|
-
return await that.signPayload(context, data, options.document.verificationMethod);
|
|
376
|
-
})(this);
|
|
377
|
-
const tx = await sdk.createDidDocTx(signInputs, options.document, '', this?.fee, undefined, versionId, {
|
|
378
|
-
sdk: sdk,
|
|
379
|
-
});
|
|
380
|
-
(0, utils_1.assert)(tx.code === 0, `cosmos_transaction: Failed to create DID. Reason: ${tx.rawLog}`);
|
|
381
|
-
const identifier = {
|
|
382
|
-
did: options.document.id,
|
|
383
|
-
keys: [],
|
|
384
|
-
services: options.document.service || [],
|
|
385
|
-
provider: options.document.id.split(':').splice(0, 3).join(':'),
|
|
386
|
-
};
|
|
387
|
-
//* Currently, only one controller key is supported.
|
|
388
|
-
//* We assume that the first key in the list is the controller key.
|
|
389
|
-
//* This is subject to change in the near future.
|
|
390
|
-
identifier.keys = options.keys
|
|
391
|
-
? await (async function (that) {
|
|
392
|
-
const scopedKeys = [];
|
|
393
|
-
for (const key of options.keys) {
|
|
394
|
-
let managedKey;
|
|
395
|
-
try {
|
|
396
|
-
managedKey = await context.agent.keyManagerImport({
|
|
397
|
-
...key,
|
|
398
|
-
kms: kms || that.defaultKms,
|
|
399
|
-
});
|
|
400
|
-
}
|
|
401
|
-
catch (e) {
|
|
402
|
-
debug(`Failed to import key ${key.kid}. Reason: ${e}`);
|
|
403
|
-
// construct key, if it failed to import
|
|
404
|
-
managedKey = { ...key, kms: kms || that.defaultKms };
|
|
405
|
-
}
|
|
406
|
-
if (managedKey) {
|
|
407
|
-
scopedKeys.push(managedKey);
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
return scopedKeys;
|
|
411
|
-
})(this)
|
|
412
|
-
: await (async function (that) {
|
|
413
|
-
const vmKeys = await that.getKeysFromVerificationMethod(context, options.document.verificationMethod);
|
|
414
|
-
// Setup controllerKeyRefs
|
|
415
|
-
identifier.controllerKeyRefs = vmKeys.map((key) => key.kid);
|
|
416
|
-
// Setup controllerKeys. It's a list of keys to display
|
|
417
|
-
identifier.controllerKeys = vmKeys.map((key) => ({ ...key, controller: options.document.id }));
|
|
418
|
-
// Here we are returning all keys associated with the DIDDocument (including keys for controllers)
|
|
419
|
-
// We already compiled it while discovering the verificationMethodIds
|
|
420
|
-
return vmKeys;
|
|
421
|
-
})(this);
|
|
422
|
-
await this.getKeysFromVerificationMethod(context, options.document.verificationMethod);
|
|
423
|
-
const controllerKey = identifier.keys[0];
|
|
424
|
-
identifier.controllerKeyId = controllerKey.kid;
|
|
425
|
-
debug('Created DID', identifier.did);
|
|
426
|
-
return identifier;
|
|
427
|
-
}
|
|
428
|
-
async updateIdentifier({ did, document, options, }, context) {
|
|
429
|
-
// Handle input parameters
|
|
430
|
-
const sdk = await this.getCheqdSDK(options?.fee);
|
|
431
|
-
const versionId = options.versionId || (0, uuid_1.v4)();
|
|
432
|
-
const keys = options.keys || [];
|
|
433
|
-
const signInfoProvider = new CheqdSignInfoProvider(context);
|
|
434
|
-
// It answers on question what the keys are actually in input
|
|
435
|
-
const areKeysImportable = keys.length > 0 &&
|
|
436
|
-
keys.every((key) => {
|
|
437
|
-
return Object.keys(key).includes('privateKeyHex');
|
|
438
|
-
});
|
|
439
|
-
// options.keys may be list of keys with privateKey ibside or just list of publicKeys
|
|
440
|
-
const publicKeyHexs = areKeysImportable ? [] : keys.map((key) => key.publicKeyHex);
|
|
441
|
-
// Check that publicKeyHexs are placed in kms if the user provides the keys
|
|
442
|
-
const _r = await signInfoProvider.keysAreInKMS(publicKeyHexs);
|
|
443
|
-
if (_r.error) {
|
|
444
|
-
throw Error(`[updateIdentifier]: ${_r.error}`);
|
|
445
|
-
}
|
|
446
|
-
// Check that verificationMethod on changed DIDDocument list exists and not empty
|
|
447
|
-
if (!document.verificationMethod || document.verificationMethod.length === 0) {
|
|
448
|
-
throw new CheqdProviderError('[updateIdentifier]: VerificationMethod should be placed and not be empty', exports.CheqdProviderErrorCodes.EmptyVerificationMethod);
|
|
449
|
-
}
|
|
450
|
-
const signInputs = areKeysImportable
|
|
451
|
-
? (function () {
|
|
452
|
-
// We are sure here that keys are placed
|
|
453
|
-
return options.keys.map((key) => (0, sdk_1.createSignInputsFromImportableEd25519Key)(key, document.verificationMethod || []));
|
|
454
|
-
})()
|
|
455
|
-
: await (async function () {
|
|
456
|
-
await signInfoProvider.updateIdentifierCompileSignInfos(document, {
|
|
457
|
-
publicKeyHexs,
|
|
458
|
-
versionId,
|
|
459
|
-
});
|
|
460
|
-
return signInfoProvider.getSignInfos();
|
|
461
|
-
})();
|
|
462
|
-
debug(`[updateIdentifier]: DID: ${did}, VerificationMethodIds for signing: ${signInputs.map((signInput) => signInput.verificationMethodId)}`);
|
|
463
|
-
const tx = await sdk.updateDidDocTx(signInputs, document, '', this?.fee, undefined, versionId, { sdk: sdk });
|
|
464
|
-
(0, utils_1.assert)(tx.code === 0, `cosmos_transaction: Failed to update DID. Reason: ${tx.rawLog}`);
|
|
465
|
-
// Setup return value
|
|
466
|
-
const identifier = {
|
|
467
|
-
did: document.id,
|
|
468
|
-
keys: [],
|
|
469
|
-
services: document.service || [],
|
|
470
|
-
provider: document.id.split(':').splice(0, 3).join(':'),
|
|
471
|
-
};
|
|
472
|
-
// Get keys for updated DIDDocument
|
|
473
|
-
// Here we are importing only the keys which has privateKey field set up
|
|
474
|
-
identifier.keys =
|
|
475
|
-
options.keys && areKeysImportable
|
|
476
|
-
? await (async function (that) {
|
|
477
|
-
const scopedKeys = [];
|
|
478
|
-
for (const key of options.keys) {
|
|
479
|
-
let managedKey;
|
|
480
|
-
try {
|
|
481
|
-
managedKey = await context.agent.keyManagerImport({
|
|
482
|
-
...key,
|
|
483
|
-
kms: options.kms || that.defaultKms,
|
|
484
|
-
});
|
|
485
|
-
}
|
|
486
|
-
catch (e) {
|
|
487
|
-
debug(`Failed to import key ${key.kid}. Reason: ${e}`);
|
|
488
|
-
// construct key, if it failed to import
|
|
489
|
-
managedKey = { ...key, kms: options.kms || that.defaultKms };
|
|
490
|
-
}
|
|
491
|
-
if (managedKey) {
|
|
492
|
-
scopedKeys.push(managedKey);
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
// Setup controllerKeyId
|
|
496
|
-
identifier.controllerKeyId = scopedKeys[0].kid;
|
|
497
|
-
return scopedKeys;
|
|
498
|
-
})(this)
|
|
499
|
-
: await (async function (that) {
|
|
500
|
-
const vmKeys = await that.getKeysFromVerificationMethod(context, document.verificationMethod);
|
|
501
|
-
// Setup controllerKeyId. It should be asocciated with verificationMethod list
|
|
502
|
-
identifier.controllerKeyId = vmKeys[0].kid;
|
|
503
|
-
// Setup controllerKeyRefs. It's a list of keys which were used for signing the transaction
|
|
504
|
-
identifier.controllerKeyRefs = signInfoProvider.getControllerKeyRefs();
|
|
505
|
-
// Setup controllerKeys. It's a list of keys to display
|
|
506
|
-
identifier.controllerKeys = signInfoProvider.getControllerKeysForSigning();
|
|
507
|
-
// Here we are returning all keys associated with the DIDDocument (including keys for controllers)
|
|
508
|
-
// We already compiled it while discovering the verificationMethodIds
|
|
509
|
-
return vmKeys;
|
|
510
|
-
})(this);
|
|
511
|
-
debug('Updated DID', did);
|
|
512
|
-
return identifier;
|
|
513
|
-
}
|
|
514
|
-
async deactivateIdentifier({ did, document, options, }, context) {
|
|
515
|
-
const sdk = await this.getCheqdSDK(options?.fee);
|
|
516
|
-
const versionId = options.versionId || (0, uuid_1.v4)();
|
|
517
|
-
const keys = options.keys || [];
|
|
518
|
-
// Providr for compiling SignInfos
|
|
519
|
-
const signInfoProvider = new CheqdSignInfoProvider(context);
|
|
520
|
-
// It answers on question what the keys are actually in input
|
|
521
|
-
const areKeysImportable = keys.length > 0 &&
|
|
522
|
-
keys.every((key) => {
|
|
523
|
-
return Object.keys(key).includes('privateKeyHex');
|
|
524
|
-
});
|
|
525
|
-
const publicKeyHexs = areKeysImportable ? [] : keys.map((key) => key.publicKeyHex);
|
|
526
|
-
// Check that publicKeyHexs are placed in kms
|
|
527
|
-
const _r = await signInfoProvider.keysAreInKMS(publicKeyHexs);
|
|
528
|
-
if (_r.error) {
|
|
529
|
-
throw Error(`[deactivateIdentifier]: ${_r.error}`);
|
|
530
|
-
}
|
|
531
|
-
const signInputs = areKeysImportable
|
|
532
|
-
? (function () {
|
|
533
|
-
// We are sure here that keys are placed
|
|
534
|
-
return options.keys.map((key) => (0, sdk_1.createSignInputsFromImportableEd25519Key)(key, document.verificationMethod || []));
|
|
535
|
-
})()
|
|
536
|
-
: await (async function () {
|
|
537
|
-
await signInfoProvider.deactivateIdentifierCompileSignInfos(document, {
|
|
538
|
-
publicKeyHexs,
|
|
539
|
-
versionId,
|
|
540
|
-
});
|
|
541
|
-
return signInfoProvider.getSignInfos();
|
|
542
|
-
})();
|
|
543
|
-
debug(`[deactivateIdentifier]: DID: ${did}, VerificationMethodIds for signing: ${signInputs.map((signInput) => signInput.verificationMethodId)}`);
|
|
544
|
-
const tx = await sdk.deactivateDidDocTx(signInputs, document, '', this?.fee, undefined, versionId, { sdk: sdk });
|
|
545
|
-
(0, utils_1.assert)(tx.code === 0, `cosmos_transaction: Failed to update DID. Reason: ${tx.rawLog}`);
|
|
546
|
-
debug('Deactivated DID', did);
|
|
547
|
-
return true;
|
|
548
|
-
}
|
|
549
|
-
async createResource({ options, }, context) {
|
|
550
|
-
const sdk = await this.getCheqdSDK(options?.fee);
|
|
551
|
-
const signInfoProvider = new CheqdSignInfoProvider(context);
|
|
552
|
-
const inputKeys = options.signInputs || [];
|
|
553
|
-
const areSignInputs = inputKeys.length > 0 &&
|
|
554
|
-
inputKeys.every((key) => {
|
|
555
|
-
return Object.keys(key).includes('privateKeyHex');
|
|
556
|
-
});
|
|
557
|
-
// options.signInputs may be list of keys with privateKey ibside or just list of publicKeys
|
|
558
|
-
const publicKeyHexs = areSignInputs ? [] : inputKeys.map((key) => key.publicKeyHex);
|
|
559
|
-
// Check that publicKeyHexs are placed in kms
|
|
560
|
-
const _r = await signInfoProvider.keysAreInKMS(publicKeyHexs);
|
|
561
|
-
if (_r.error) {
|
|
562
|
-
throw Error(`[updateIdentifier]: ${_r.error}`);
|
|
563
|
-
}
|
|
564
|
-
const signInputs = areSignInputs
|
|
565
|
-
? options.signInputs
|
|
566
|
-
: await (async function (that) {
|
|
567
|
-
const did = `did:cheqd:${that.network}:${options.payload.collectionId}`;
|
|
568
|
-
await signInfoProvider.resourceCreateCompileSignInfos(did, options.payload, {
|
|
569
|
-
publicKeyHexs,
|
|
570
|
-
});
|
|
571
|
-
return signInfoProvider.getSignInfos();
|
|
572
|
-
})(this);
|
|
573
|
-
debug(`[createResource]: DID: did:cheqd:${this.network}:${options.payload.collectionId} , VerificationMethodIds for signing: ${signInputs.map((signInput) => signInput.verificationMethodId)}`);
|
|
574
|
-
const tx = await sdk.createLinkedResourceTx(signInputs, options.payload, '', this?.fee, undefined, {
|
|
575
|
-
sdk: sdk,
|
|
576
|
-
});
|
|
577
|
-
(0, utils_1.assert)(tx.code === 0, `cosmos_transaction: Failed to create Resource. Reason: ${tx.rawLog}`);
|
|
578
|
-
const mapKeyType = (keyType) => {
|
|
579
|
-
switch (keyType) {
|
|
580
|
-
case 'Ed25519':
|
|
581
|
-
return 'Ed25519';
|
|
582
|
-
case 'Secp256k1':
|
|
583
|
-
return 'Secp256k1';
|
|
584
|
-
default:
|
|
585
|
-
return undefined;
|
|
586
|
-
}
|
|
587
|
-
};
|
|
588
|
-
if (areSignInputs) {
|
|
589
|
-
const signInput = inputKeys.filter((input) => mapKeyType(input.keyType) !== undefined);
|
|
590
|
-
const keys = [];
|
|
591
|
-
for (const input of signInput) {
|
|
592
|
-
let managedKey;
|
|
593
|
-
try {
|
|
594
|
-
// get public key from private key in hex
|
|
595
|
-
const publicKey = (0, uint8arrays_1.toString)((await crypto_1.Ed25519.makeKeypair((0, uint8arrays_1.fromString)(input.privateKeyHex, 'hex'))).pubkey, 'hex');
|
|
596
|
-
managedKey = await context.agent.keyManagerImport({
|
|
597
|
-
kid: publicKey,
|
|
598
|
-
publicKeyHex: publicKey,
|
|
599
|
-
privateKeyHex: input.privateKeyHex,
|
|
600
|
-
type: mapKeyType(input.keyType),
|
|
601
|
-
kms: options.kms || this.defaultKms,
|
|
602
|
-
});
|
|
603
|
-
}
|
|
604
|
-
catch (e) {
|
|
605
|
-
debug(`Failed to import key ${input.verificationMethodId}. Reason: ${e}`);
|
|
606
|
-
}
|
|
607
|
-
if (managedKey) {
|
|
608
|
-
keys.push(managedKey);
|
|
609
|
-
}
|
|
610
|
-
}
|
|
611
|
-
}
|
|
612
|
-
debug('Created Resource', options.payload);
|
|
613
|
-
return true;
|
|
614
|
-
}
|
|
615
|
-
async deleteIdentifier(identity, context) {
|
|
616
|
-
for (const { kid } of identity.keys) {
|
|
617
|
-
await context.agent.keyManagerDelete({ kid });
|
|
618
|
-
}
|
|
619
|
-
return true;
|
|
620
|
-
}
|
|
621
|
-
async addKey({ identifier, key, options }, context) {
|
|
622
|
-
throw Error('CheqdDIDProvider addKey is not supported.');
|
|
623
|
-
}
|
|
624
|
-
async addService({ identifier, service, options }, context) {
|
|
625
|
-
throw Error('CheqdDIDProvider addService is not supported.');
|
|
626
|
-
}
|
|
627
|
-
async removeKey(args, context) {
|
|
628
|
-
throw Error('CheqdDIDProvider removeKey is not supported.');
|
|
629
|
-
}
|
|
630
|
-
async removeService(args, context) {
|
|
631
|
-
throw Error('CheqdDIDProvider removeService is not supported.');
|
|
632
|
-
}
|
|
633
|
-
async transactSendTokens(args) {
|
|
634
|
-
const sdk = await this.getCheqdSDK(undefined, CheqdDIDProvider.defaultGasPrice);
|
|
635
|
-
if (args?.txBytes) {
|
|
636
|
-
// broadcast txBytes
|
|
637
|
-
const tx = await sdk.signer.broadcastTx(args.txBytes, args?.timeoutMs, args?.pollIntervalMs);
|
|
638
|
-
// assert tx code is 0, in other words, tx succeeded
|
|
639
|
-
(0, utils_1.assert)(tx.code === 0, `cosmos_transaction: Failed to send tokens. Reason: ${tx.rawLog}`);
|
|
640
|
-
// keep log
|
|
641
|
-
debug('Sent tokens', 'txBytes', (0, uint8arrays_1.toString)(args.txBytes, 'hex'));
|
|
642
|
-
return tx;
|
|
643
|
-
}
|
|
644
|
-
// poll gas price
|
|
645
|
-
const gasPrice = await sdk.queryGasPrice(args.amount.denom);
|
|
646
|
-
// define fee
|
|
647
|
-
const fee = {
|
|
648
|
-
amount: [
|
|
649
|
-
{
|
|
650
|
-
amount: (Number(gasPrice.price?.amount ?? '0') * 10 ** 9).toString(),
|
|
651
|
-
denom: args.amount.denom,
|
|
652
|
-
},
|
|
653
|
-
],
|
|
654
|
-
gas: '360000',
|
|
655
|
-
};
|
|
656
|
-
const tx = await sdk.signer.sendTokens((await (await this.cosmosPayerWallet).getAccounts())[0].address, args.recipientAddress, [args.amount], fee, args.memo);
|
|
657
|
-
(0, utils_1.assert)(tx.code === 0, `cosmos_transaction: Failed to send tokens. Reason: ${tx.rawLog}`);
|
|
658
|
-
debug('Sent tokens', args.amount.amount, args.amount.denom, 'to', args.recipientAddress);
|
|
659
|
-
return tx;
|
|
660
|
-
}
|
|
661
|
-
async mintCapacityCredit(args) {
|
|
662
|
-
// instantiate dkg-threshold contract client, in which case lit-protocol is used
|
|
663
|
-
const litContracts = await this.instantiateDkgThresholdContractClient();
|
|
664
|
-
// mint capacity credits
|
|
665
|
-
const result = await litContracts.mintCapacityCredits(args);
|
|
666
|
-
// keep log
|
|
667
|
-
debug('Minted capacity credits', result.capacityTokenIdStr, 'for', args.effectiveDays, 'days', 'with transaction hash', result.rliTxHash, 'from address', this.ethereumAuthWallet.address);
|
|
668
|
-
return result;
|
|
669
|
-
}
|
|
670
|
-
async delegateCapacityCredit(args) {
|
|
671
|
-
// instantiate dkg-threshold client, in which case lit-protocol is used
|
|
672
|
-
const litProtocol = await this.instantiateDkgThresholdProtocolClient();
|
|
673
|
-
// delegate capacity credits
|
|
674
|
-
const result = await litProtocol.delegateCapacitCredit({
|
|
675
|
-
dAppOwnerWallet: this.ethereumAuthWallet instanceof ethers_1.ethers.Wallet
|
|
676
|
-
? this.ethereumAuthWallet
|
|
677
|
-
: new ethers_1.ethers.Wallet(this.ethereumAuthWallet.privateKey),
|
|
678
|
-
capacityTokenId: args.capacityTokenId,
|
|
679
|
-
delegateeAddresses: args.delegateeAddresses,
|
|
680
|
-
uses: args.uses.toString(),
|
|
681
|
-
expiration: args.expiration,
|
|
682
|
-
statement: args.statement,
|
|
683
|
-
});
|
|
684
|
-
// keep log
|
|
685
|
-
debug('Delegated capacity credits', args.capacityTokenId, 'to', args.delegateeAddresses.join(', '), 'with auth signature', result.capacityDelegationAuthSig.sig, 'from address', this.ethereumAuthWallet.address);
|
|
686
|
-
return result;
|
|
687
|
-
}
|
|
688
|
-
async instantiateDkgThresholdProtocolClient(dkgOptions = this.dkgOptions) {
|
|
689
|
-
return await v6_js_1.LitProtocol.create({
|
|
690
|
-
chain: dkgOptions.chain || this.dkgOptions.chain,
|
|
691
|
-
litNetwork: dkgOptions.network || this.dkgOptions.network,
|
|
692
|
-
cosmosAuthWallet: await this._aminoSigner,
|
|
693
|
-
});
|
|
694
|
-
}
|
|
695
|
-
async instantiateDkgThresholdContractClient(dkgNetwork = this.dkgOptions.network) {
|
|
696
|
-
return await v6_js_1.LitContracts.create({
|
|
697
|
-
ethereumAuthWallet: this.ethereumAuthWallet instanceof ethers_1.ethers.Wallet
|
|
698
|
-
? this.ethereumAuthWallet
|
|
699
|
-
: new ethers_1.ethers.Wallet(this.ethereumAuthWallet.privateKey),
|
|
700
|
-
litNetwork: dkgNetwork,
|
|
701
|
-
});
|
|
702
|
-
}
|
|
703
|
-
async signPayload(context, data, verificationMethod = []) {
|
|
704
|
-
return Promise.all(verificationMethod.map(async (method) => {
|
|
705
|
-
const keyRef = (0, utils_2.extractPublicKeyHex)(method).publicKeyHex;
|
|
706
|
-
return {
|
|
707
|
-
verificationMethodId: method.id,
|
|
708
|
-
signature: (0, utils_2.base64ToBytes)(await context.agent.keyManagerSign({
|
|
709
|
-
keyRef,
|
|
710
|
-
data: (0, uint8arrays_1.toString)(data, 'hex'),
|
|
711
|
-
encoding: 'hex',
|
|
712
|
-
})),
|
|
713
|
-
};
|
|
714
|
-
}));
|
|
715
|
-
}
|
|
716
|
-
async getKeysFromVerificationMethod(context, verificationMethod = []) {
|
|
717
|
-
return Promise.all(verificationMethod.map(async (method) => {
|
|
718
|
-
const kid = (0, utils_2.extractPublicKeyHex)(method).publicKeyHex;
|
|
719
|
-
const key = await context.agent.keyManagerGet({ kid });
|
|
720
|
-
return { ...key, controller: method.controller };
|
|
721
|
-
})).catch((error) => {
|
|
722
|
-
throw new Error(`Failed to sign payload: ${error}`);
|
|
723
|
-
});
|
|
724
|
-
}
|
|
725
|
-
}
|
|
726
|
-
exports.CheqdDIDProvider = CheqdDIDProvider;
|
|
727
|
-
async function createMsgCreateDidDocPayloadToSign(didPayload, versionId) {
|
|
728
|
-
const { protobufVerificationMethod, protobufService } = await sdk_1.DIDModule.validateSpecCompliantPayload(didPayload);
|
|
729
|
-
return index_js_2.MsgCreateDidDocPayload.encode(index_js_2.MsgCreateDidDocPayload.fromPartial({
|
|
730
|
-
context: didPayload?.['@context'],
|
|
731
|
-
id: didPayload.id,
|
|
732
|
-
controller: didPayload.controller,
|
|
733
|
-
verificationMethod: protobufVerificationMethod,
|
|
734
|
-
authentication: didPayload.authentication,
|
|
735
|
-
assertionMethod: didPayload.assertionMethod,
|
|
736
|
-
capabilityInvocation: didPayload.capabilityInvocation,
|
|
737
|
-
capabilityDelegation: didPayload.capabilityDelegation,
|
|
738
|
-
keyAgreement: didPayload.keyAgreement,
|
|
739
|
-
service: protobufService,
|
|
740
|
-
alsoKnownAs: didPayload.alsoKnownAs,
|
|
741
|
-
versionId,
|
|
742
|
-
})).finish();
|
|
743
|
-
}
|
|
744
|
-
async function createMsgDeactivateDidDocPayloadToSign(didPayload, versionId) {
|
|
745
|
-
return index_js_2.MsgDeactivateDidDocPayload.encode(index_js_2.MsgDeactivateDidDocPayload.fromPartial({
|
|
746
|
-
id: didPayload.id,
|
|
747
|
-
versionId,
|
|
748
|
-
})).finish();
|
|
749
|
-
}
|
|
750
|
-
//# sourceMappingURL=cheqd-did-provider.js.map
|