@cheqd/did-provider-cheqd 3.6.16-develop.1 → 3.7.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.
Files changed (37) hide show
  1. package/build/cjs/agent/ICheqd.d.ts +4 -4
  2. package/build/cjs/agent/ICheqd.d.ts.map +1 -1
  3. package/build/cjs/agent/ICheqd.js +1 -1
  4. package/build/cjs/agent/ICheqd.js.map +1 -1
  5. package/build/cjs/did-manager/cheqd-did-provider.d.ts +64 -4
  6. package/build/cjs/did-manager/cheqd-did-provider.d.ts.map +1 -1
  7. package/build/cjs/did-manager/cheqd-did-provider.js +343 -40
  8. package/build/cjs/did-manager/cheqd-did-provider.js.map +1 -1
  9. package/build/cjs/utils/helpers.d.ts +2 -0
  10. package/build/cjs/utils/helpers.d.ts.map +1 -1
  11. package/build/cjs/utils/helpers.js +14 -1
  12. package/build/cjs/utils/helpers.js.map +1 -1
  13. package/build/esm/agent/ICheqd.d.ts +4 -4
  14. package/build/esm/agent/ICheqd.d.ts.map +1 -1
  15. package/build/esm/agent/ICheqd.js +1 -1
  16. package/build/esm/agent/ICheqd.js.map +1 -1
  17. package/build/esm/did-manager/cheqd-did-provider.d.ts +64 -4
  18. package/build/esm/did-manager/cheqd-did-provider.d.ts.map +1 -1
  19. package/build/esm/did-manager/cheqd-did-provider.js +340 -39
  20. package/build/esm/did-manager/cheqd-did-provider.js.map +1 -1
  21. package/build/esm/utils/helpers.d.ts +2 -0
  22. package/build/esm/utils/helpers.d.ts.map +1 -1
  23. package/build/esm/utils/helpers.js +12 -0
  24. package/build/esm/utils/helpers.js.map +1 -1
  25. package/build/tsconfig.cjs.tsbuildinfo +1 -1
  26. package/build/tsconfig.esm.tsbuildinfo +1 -1
  27. package/build/tsconfig.types.tsbuildinfo +1 -1
  28. package/build/types/agent/ICheqd.d.ts +4 -4
  29. package/build/types/agent/ICheqd.d.ts.map +1 -1
  30. package/build/types/did-manager/cheqd-did-provider.d.ts +64 -4
  31. package/build/types/did-manager/cheqd-did-provider.d.ts.map +1 -1
  32. package/build/types/utils/helpers.d.ts +2 -0
  33. package/build/types/utils/helpers.d.ts.map +1 -1
  34. package/package.json +4 -4
  35. package/src/agent/ICheqd.ts +9 -4
  36. package/src/did-manager/cheqd-did-provider.ts +483 -67
  37. package/src/utils/helpers.ts +14 -0
@@ -6,6 +6,7 @@ import { DIDDocument } from 'did-resolver';
6
6
  import { IIdentifier, IKey, IService } from '@veramo/core';
7
7
  import { AbstractIdentifierProvider } from '@veramo/did-manager';
8
8
  import { EnglishMnemonic as _ } from '@cosmjs/crypto';
9
+ import { SignInfo } from '@cheqd/ts-proto/cheqd/did/v2/index.js';
9
10
  import { LitCompatibleCosmosChain, LitNetwork } from '../dkg-threshold/lit-protocol.js';
10
11
  import { IContext } from '../agent/ICheqd.js';
11
12
  export declare const DefaultRPCUrls: {
@@ -50,10 +51,69 @@ export type TImportableEd25519Key = Required<Pick<IKey, 'publicKeyHex' | 'privat
50
51
  kid: TImportableEd25519Key['publicKeyHex'];
51
52
  type: 'Ed25519';
52
53
  };
54
+ export declare class CheqdProviderError extends Error {
55
+ readonly errorCode: string;
56
+ constructor(message: string, errorCode: string);
57
+ }
58
+ export declare const CheqdProviderErrorCodes: {
59
+ readonly DeactivatedController: "DeactivatedController";
60
+ readonly UnresolvedDID: "UnresolvedDID";
61
+ readonly EmptyVerificationMethod: "EmptyVerificationMethod";
62
+ };
63
+ export type TPublicKeyEd25519 = Required<Pick<IKey, 'publicKeyHex'>> & {
64
+ kid: TImportableEd25519Key['publicKeyHex'];
65
+ type: 'Ed25519';
66
+ };
53
67
  export type TSupportedKeyType = 'Ed25519' | 'Secp256k1';
68
+ export interface IKeyWithController extends IKey {
69
+ controller?: string;
70
+ }
71
+ export interface ICheqdIDentifier extends IIdentifier {
72
+ controllerKeyRefs?: string[];
73
+ controllerKeys?: IKeyWithController[];
74
+ }
54
75
  export declare class EnglishMnemonic extends _ {
55
76
  static readonly _mnemonicMatcher: RegExp;
56
77
  }
78
+ export declare class CheqdSignInfoProvider {
79
+ readonly context: IContext;
80
+ signInfos: SignInfo[];
81
+ publicKeyHexs: string[];
82
+ controllers: string[];
83
+ controllerKeys: IKeyWithController[];
84
+ controllerKeyRefs: string[];
85
+ constructor(context: IContext);
86
+ setPublicKeyHexs(publicKeyHexs: string[]): void;
87
+ setSignInfos(signInfos: SignInfo[]): void;
88
+ setControllers(controllers: string[]): void;
89
+ getSignInfos(): SignInfo[];
90
+ getPublicKeyHexs(): string[];
91
+ getControllerKeys(): IKeyWithController[];
92
+ getControllerKeyRefs(): string[];
93
+ getControllerKeysForSigning(): IKeyWithController[];
94
+ compilePublicKeyHexs(controllers: string[], options: {
95
+ publicKeyHexs?: string[];
96
+ }): Promise<void>;
97
+ compileSignInfos(payload: Uint8Array, controllers: string[]): Promise<void>;
98
+ updateIdentifierCompileSignInfos(didDocument: DIDDocument, options: {
99
+ versionId?: string;
100
+ publicKeyHexs?: string[];
101
+ }): Promise<void>;
102
+ deactivateIdentifierCompileSignInfos(didDocument: DIDDocument, options: {
103
+ publicKeyHexs?: string[];
104
+ versionId?: string;
105
+ }): Promise<void>;
106
+ resourceCreateCompileSignInfos(did: string, resourcePayload: ResourcePayload, options: {
107
+ publicKeyHexs?: string[];
108
+ }): Promise<void>;
109
+ keysAreInKMS(publicKeys: string[]): Promise<{
110
+ placed: boolean;
111
+ error: string;
112
+ } | {
113
+ placed: boolean;
114
+ error?: undefined;
115
+ }>;
116
+ }
57
117
  /**
58
118
  * {@link @veramo/did-manager#DIDManager} identifier provider for `did:cheqd` identifiers.
59
119
  * @public
@@ -97,16 +157,16 @@ export declare class CheqdDIDProvider extends AbstractIdentifierProvider {
97
157
  document: DIDDocument;
98
158
  options: {
99
159
  kms: string;
100
- keys?: TImportableEd25519Key[];
160
+ keys?: TImportableEd25519Key[] | TPublicKeyEd25519[];
101
161
  versionId?: string;
102
162
  fee?: DidStdFee;
103
163
  };
104
- }, context: IContext): Promise<IIdentifier>;
164
+ }, context: IContext): Promise<ICheqdIDentifier>;
105
165
  deactivateIdentifier({ did, document, options, }: {
106
166
  did: string;
107
167
  document: DIDDocument;
108
168
  options: {
109
- keys?: TImportableEd25519Key[];
169
+ keys?: TImportableEd25519Key[] | TPublicKeyEd25519[];
110
170
  fee?: DidStdFee;
111
171
  versionId?: string;
112
172
  };
@@ -114,7 +174,7 @@ export declare class CheqdDIDProvider extends AbstractIdentifierProvider {
114
174
  createResource({ options, }: {
115
175
  options: {
116
176
  payload: ResourcePayload;
117
- signInputs?: ISignInputs[];
177
+ signInputs?: ISignInputs[] | TPublicKeyEd25519[];
118
178
  kms?: string;
119
179
  fee?: DidStdFee;
120
180
  };
@@ -1 +1 @@
1
- {"version":3,"file":"cheqd-did-provider.d.ts","sourceRoot":"","sources":["../../../src/did-manager/cheqd-did-provider.ts"],"names":[],"mappings":"AAIA,OAAO,EASN,SAAS,EACT,WAAW,EAEX,YAAY,EACZ,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,wBAAwB,EAAE,MAAM,4CAA4C,CAAC;AACtF,OAAO,EAAE,WAAW,EAAE,IAAI,EAAkD,MAAM,uBAAuB,CAAC;AAC1G,OAAO,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAE/D,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EACN,WAAW,EACX,IAAI,EACJ,QAAQ,EAMR,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,0BAA0B,EAAE,MAAM,qBAAqB,CAAC;AAGjE,OAAO,EAAE,eAAe,IAAI,CAAC,EAAW,MAAM,gBAAgB,CAAC;AAI/D,OAAO,EACN,wBAAwB,EAExB,UAAU,EAEV,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAI9C,eAAO,MAAM,cAAc;;;CAGjB,CAAC;AAEX,eAAO,MAAM,eAAe;;;CAGlB,CAAC;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d,OAAO,CAAC,EAAE,UAAU,CAAC;QACrB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,cAAc,CAAC,EAAE,MAAM,CAAC;KACxB,GAAG,OAAO,CAAC,iBAAiB,CAAC;YA+BhB,WAAW;YAsBX,6BAA6B;CAc3C;AAED,wBAAsB,kCAAkC,CACvD,UAAU,EAAE,WAAW,EACvB,SAAS,EAAE,MAAM,GACf,OAAO,CAAC,UAAU,CAAC,CAkBrB;AAED,wBAAsB,sCAAsC,CAC3D,UAAU,EAAE,WAAW,EACvB,SAAS,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC,UAAU,CAAC,CAOrB"}
@@ -15,6 +15,7 @@ import { fromString, toString } from 'uint8arrays';
15
15
  import { MsgCreateDidDocPayload, MsgDeactivateDidDocPayload } from '@cheqd/ts-proto/cheqd/did/v2/index.js';
16
16
  import { v4 } from 'uuid';
17
17
  import { LitCompatibleCosmosChains, LitNetworks, } from '../dkg-threshold/lit-protocol.js';
18
+ import { getControllers } from '../utils/helpers.js';
18
19
  const debug = Debug('veramo:did-provider-cheqd');
19
20
  export const DefaultRPCUrls = {
20
21
  [CheqdNetwork.Mainnet]: 'https://rpc.cheqd.net',
@@ -42,9 +43,224 @@ export const DefaultStatusList2021Encodings = {
42
43
  base64url: 'base64url',
43
44
  hex: 'hex',
44
45
  };
46
+ export class CheqdProviderError extends Error {
47
+ errorCode;
48
+ constructor(message, errorCode) {
49
+ super(message);
50
+ this.errorCode = errorCode;
51
+ this.errorCode = errorCode;
52
+ }
53
+ }
54
+ export const CheqdProviderErrorCodes = {
55
+ DeactivatedController: 'DeactivatedController',
56
+ UnresolvedDID: 'UnresolvedDID',
57
+ EmptyVerificationMethod: 'EmptyVerificationMethod'
58
+ };
45
59
  export class EnglishMnemonic extends _ {
46
60
  static _mnemonicMatcher = /^[a-z]+( [a-z]+)*$/;
47
61
  }
62
+ export class CheqdSignInfoProvider {
63
+ context;
64
+ signInfos;
65
+ publicKeyHexs;
66
+ controllers;
67
+ controllerKeys;
68
+ controllerKeyRefs;
69
+ constructor(context) {
70
+ this.signInfos = [];
71
+ this.publicKeyHexs = [];
72
+ this.controllerKeys = [];
73
+ this.controllerKeyRefs = [];
74
+ this.controllers = [];
75
+ this.context = context;
76
+ }
77
+ setPublicKeyHexs(publicKeyHexs) {
78
+ this.publicKeyHexs = publicKeyHexs;
79
+ }
80
+ setSignInfos(signInfos) {
81
+ this.signInfos = signInfos;
82
+ }
83
+ setControllers(controllers) {
84
+ this.controllers = controllers;
85
+ }
86
+ getSignInfos() {
87
+ return this.signInfos;
88
+ }
89
+ getPublicKeyHexs() {
90
+ return this.publicKeyHexs;
91
+ }
92
+ getControllerKeys() {
93
+ return this.controllerKeys;
94
+ }
95
+ getControllerKeyRefs() {
96
+ return this.controllerKeyRefs;
97
+ }
98
+ getControllerKeysForSigning() {
99
+ const keys = [];
100
+ this.controllers.forEach((controller) => {
101
+ const key = this.controllerKeys.find((key) => key.controller === controller);
102
+ if (key) {
103
+ keys.push(key);
104
+ }
105
+ });
106
+ return keys;
107
+ }
108
+ async compilePublicKeyHexs(controllers, options) {
109
+ const publicKeyHexs = options.publicKeyHexs || [];
110
+ if (publicKeyHexs.length === 0) {
111
+ for (const controller of controllers) {
112
+ const key = await this.context.agent.didManagerGet({ did: controller }).then((result) => result.keys[0]);
113
+ publicKeyHexs.push(key.kid);
114
+ }
115
+ }
116
+ this.setPublicKeyHexs(publicKeyHexs);
117
+ }
118
+ async compileSignInfos(payload, controllers) {
119
+ // 1. Iterate over the contollers and for each - get DIDDocument and get the verificationMethodId associated with one of publicKeyHexs
120
+ // 1.1 Iterate over the list of verificationMethods and make the checks:
121
+ // 1.1.1 Iterate over publicKeyHexs and convert each publicKeyHex to the verification Material
122
+ // 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
123
+ // 2. Iterate over the pair of verificationMethodIds and publicKeys and create SignInfo§
124
+ // Setup
125
+ const signInfos = [];
126
+ const publicKeyHexs = this.getPublicKeyHexs();
127
+ // Get verificationMethodIds
128
+ const verificationMethodIds = [];
129
+ // Iterate over list of controllers and tries to get the corresponding verificationMethodId associated with one of publicKeyHexs
130
+ for (const controller of controllers) {
131
+ // We need to get here current version of DIDDocument associated with the controller and cannot skip it even if document.id === controller
132
+ // cause in case of remooving verifcation method we need to sign the payload with the old verification method which is on ledger.
133
+ const controllerResolutionResult = await this.context.agent.resolveDid({ didUrl: controller });
134
+ const controllerDidDocument = controllerResolutionResult.didDocument;
135
+ // Check if controller DID document is resolved
136
+ if (!controllerDidDocument) {
137
+ throw new CheqdProviderError('[did-provider-cheqd]: compileSignInfos: Error while resolving the DID document for controller DID: ' + controller, CheqdProviderErrorCodes.UnresolvedDID);
138
+ }
139
+ // Check that controller's DIDDocument is active
140
+ if (controllerResolutionResult.didDocumentMetadata.deactivated) {
141
+ throw new CheqdProviderError(`[did-provider-cheqd]: compileSignInfos: DIDDocument associated with controller ${controller} is deactivated`, CheqdProviderErrorCodes.DeactivatedController);
142
+ }
143
+ // Check if controller DID document contains verification methods
144
+ if (!controllerDidDocument.verificationMethod) {
145
+ throw new CheqdProviderError('[did-provider-cheqd]: compileSignInfos: Controller DID document does not contain verification methods', CheqdProviderErrorCodes.EmptyVerificationMethod);
146
+ }
147
+ // Iterate over verificationMethods and by comparing publicKeys get the verificationMethod Id
148
+ for (const vm of controllerDidDocument.verificationMethod) {
149
+ // Try to match verificationMethod with one of publicKeyHexs
150
+ for (const publicKeyHex of publicKeyHexs) {
151
+ // Get publicKeyHex from verificationMethod
152
+ const vmPublicKey = extractPublicKeyHex(vm);
153
+ // Compare publicKeys
154
+ if (publicKeyHex === vmPublicKey) {
155
+ // Create SignInfo object
156
+ signInfos.push({
157
+ verificationMethodId: vm.id,
158
+ signature: base64ToBytes(await this.context.agent.keyManagerSign({
159
+ keyRef: publicKeyHex,
160
+ data: toString(payload, 'hex'),
161
+ encoding: 'hex',
162
+ })),
163
+ });
164
+ // Setup controllerKeyRefs
165
+ this.controllerKeyRefs.push(publicKeyHex);
166
+ }
167
+ }
168
+ // Setup key structure for display
169
+ const kid = extractPublicKeyHex(vm);
170
+ const key = await this.context.agent.keyManagerGet({ kid });
171
+ this.controllerKeys.push({ ...key, controller: vm.controller });
172
+ }
173
+ }
174
+ // Setup signInfos
175
+ this.setSignInfos(signInfos);
176
+ }
177
+ async updateIdentifierCompileSignInfos(didDocument, options) {
178
+ // Steps to solve the issue:
179
+ // 1. Collect list of controllers. The user can remove, append and reqrite the controller.
180
+ // But we need to send all the signatures, old and news
181
+ // 2. Generate payloads
182
+ // 3. Compile list of signInfos
183
+ // Get current version of DIDDocument
184
+ const actualDIDDocument = await this.context.agent.resolveDid({ didUrl: didDocument.id });
185
+ if (!actualDIDDocument.didDocument) {
186
+ throw new Error('[did-provider-cheqd]: updateIdentifierSignInfos: Error while resolving the DID document for updating with error: ' + actualDIDDocument.didResolutionMetadata.error);
187
+ }
188
+ // Compile controllers
189
+ const updatedControllers = getControllers(didDocument);
190
+ const actualControllers = getControllers(actualDIDDocument.didDocument);
191
+ const controllers = [...new Set([...updatedControllers, ...actualControllers])];
192
+ // Generate payload
193
+ const versionId = options.versionId || v4();
194
+ const payload = await createMsgCreateDidDocPayloadToSign(didDocument, versionId);
195
+ // Setup publicKeyHexs
196
+ await this.compilePublicKeyHexs(controllers, options);
197
+ // Setup controllers. Here it's supposed to be a list of controllers which are associated with the DIDDocument
198
+ this.setControllers(updatedControllers);
199
+ // Setup SignInfos
200
+ await this.compileSignInfos(payload, controllers);
201
+ }
202
+ async deactivateIdentifierCompileSignInfos(didDocument, options) {
203
+ // Steps to solve the issue:
204
+ // 1. Collect list of controllers. The user can remove, append and reqrite the controller.
205
+ // But we need to send all the signatures, old and news
206
+ // Generate payload to sign
207
+ // 3. Compile list of signInfos
208
+ // Get Controllers
209
+ const controllers = getControllers(didDocument);
210
+ // For did deactivation ledger requires the signature from original DID Document controller
211
+ // So we need to add the controller to the list of controllers
212
+ if (!controllers.includes(didDocument.id)) {
213
+ controllers.push(didDocument.id);
214
+ }
215
+ // Generate payload
216
+ const versionId = options.versionId || v4();
217
+ const payload = await createMsgDeactivateDidDocPayloadToSign(didDocument, versionId);
218
+ // Setup publicKeyHexs
219
+ await this.compilePublicKeyHexs(controllers, options);
220
+ // Setup SignInfos
221
+ await this.compileSignInfos(payload, controllers);
222
+ }
223
+ async resourceCreateCompileSignInfos(did, resourcePayload, options) {
224
+ // Steps to solve the issue:
225
+ // 1. Collect list of controllers. The user can remove, append and reqrite the controller.
226
+ // But we need to send all the signatures, old and news
227
+ // Generate payload to sign
228
+ // 3. Compile list of signInfos
229
+ const didDocument = await this.context.agent.resolveDid({ didUrl: did }).then((result) => result.didDocument);
230
+ if (!didDocument) {
231
+ throw new Error('[did-provider-cheqd]: resourceCreateCompileSignInfos: Erro while resolving the DID document for controller DID: ' + did);
232
+ }
233
+ // Get Controllers
234
+ const controllers = getControllers(didDocument);
235
+ // For resource creation ledger requires the signature from original DID Document controller
236
+ // So we need to add the controller to the list of controllers
237
+ if (!controllers.includes(did)) {
238
+ controllers.push(did);
239
+ }
240
+ // Generate payload
241
+ const payload = await MsgCreateResourcePayload.encode(MsgCreateResourcePayload.fromPartial(resourcePayload)).finish();
242
+ // Setup publicKeyHexs
243
+ await this.compilePublicKeyHexs(controllers, options);
244
+ // Setup SignInfos
245
+ await this.compileSignInfos(payload, controllers);
246
+ }
247
+ async keysAreInKMS(publicKeys) {
248
+ for (const keyRef of publicKeys) {
249
+ try {
250
+ await this.context.agent.keyManagerGet({ kid: keyRef });
251
+ }
252
+ catch (e) {
253
+ return {
254
+ placed: false,
255
+ error: `PublicKey: ${keyRef} is not placed in kms`
256
+ };
257
+ }
258
+ }
259
+ return {
260
+ placed: true
261
+ };
262
+ }
263
+ }
48
264
  /**
49
265
  * {@link @veramo/did-manager#DIDManager} identifier provider for `did:cheqd` identifiers.
50
266
  * @public
@@ -120,10 +336,16 @@ export class CheqdDIDProvider extends AbstractIdentifierProvider {
120
336
  sdk: sdk,
121
337
  });
122
338
  assert(tx.code === 0, `cosmos_transaction: Failed to create DID. Reason: ${tx.rawLog}`);
339
+ const identifier = {
340
+ did: options.document.id,
341
+ keys: [],
342
+ services: options.document.service || [],
343
+ provider: options.document.id.split(':').splice(0, 3).join(':'),
344
+ };
123
345
  //* Currently, only one controller key is supported.
124
346
  //* We assume that the first key in the list is the controller key.
125
347
  //* This is subject to change in the near future.
126
- const keys = options.keys
348
+ identifier.keys = options.keys
127
349
  ? await (async function (that) {
128
350
  const scopedKeys = [];
129
351
  for (const key of options.keys) {
@@ -145,35 +367,71 @@ export class CheqdDIDProvider extends AbstractIdentifierProvider {
145
367
  }
146
368
  return scopedKeys;
147
369
  })(this)
148
- : await this.getKeysFromVerificationMethod(context, options.document.verificationMethod);
149
- const controllerKey = keys[0];
150
- const identifier = {
151
- did: options.document.id,
152
- controllerKeyId: controllerKey.kid,
153
- keys,
154
- services: options.document.service || [],
155
- provider: options.document.id.split(':').splice(0, 3).join(':'),
156
- };
370
+ : await (async function (that) {
371
+ const vmKeys = await that.getKeysFromVerificationMethod(context, options.document.verificationMethod);
372
+ // Setup controllerKeyRefs
373
+ identifier.controllerKeyRefs = vmKeys.map((key) => key.kid);
374
+ // Setup controllerKeys. It's a list of keys to display
375
+ identifier.controllerKeys = vmKeys.map((key) => ({ ...key, controller: options.document.id }));
376
+ // Here we are returning all keys associated with the DIDDocument (including keys for controllers)
377
+ // We already compiled it while discovering the verificationMethodIds
378
+ return vmKeys;
379
+ })(this);
380
+ await this.getKeysFromVerificationMethod(context, options.document.verificationMethod);
381
+ const controllerKey = identifier.keys[0];
382
+ identifier.controllerKeyId = controllerKey.kid;
157
383
  debug('Created DID', identifier.did);
158
384
  return identifier;
159
385
  }
160
386
  async updateIdentifier({ did, document, options, }, context) {
387
+ // Handle input parameters
161
388
  const sdk = await this.getCheqdSDK(options?.fee);
162
389
  const versionId = options.versionId || v4();
163
- const signInputs = options.keys
390
+ const keys = options.keys || [];
391
+ const signInfoProvider = new CheqdSignInfoProvider(context);
392
+ // It answers on question what the keys are actually in input
393
+ const areKeysImportable = keys.length > 0 && keys.every((key) => {
394
+ return Object.keys(key).includes('privateKeyHex');
395
+ });
396
+ // options.keys may be list of keys with privateKey ibside or just list of publicKeys
397
+ const publicKeyHexs = areKeysImportable
398
+ ? []
399
+ : keys.map((key) => key.publicKeyHex);
400
+ // Check that publicKeyHexs are placed in kms if the user provides the keys
401
+ const _r = await signInfoProvider.keysAreInKMS(publicKeyHexs);
402
+ if (_r.error) {
403
+ throw Error(`[updateIdentifier]: ${_r.error}`);
404
+ }
405
+ // Check that verificationMethod on changed DIDDocument list exists and not empty
406
+ if (!document.verificationMethod || document.verificationMethod.length === 0) {
407
+ throw new CheqdProviderError('[updateIdentifier]: VerificationMethod should be placed and not be empty', CheqdProviderErrorCodes.EmptyVerificationMethod);
408
+ }
409
+ const signInputs = areKeysImportable
164
410
  ? (function () {
411
+ // We are sure here that keys are placed
165
412
  return options.keys.map((key) => createSignInputsFromImportableEd25519Key(key, document.verificationMethod || []));
166
413
  })()
167
- : await (async function (that) {
168
- const data = await createMsgCreateDidDocPayloadToSign(document, versionId);
169
- return await that.signPayload(context, data, document.verificationMethod);
170
- })(this);
414
+ : await (async function () {
415
+ await signInfoProvider.updateIdentifierCompileSignInfos(document, {
416
+ publicKeyHexs,
417
+ versionId
418
+ });
419
+ return signInfoProvider.getSignInfos();
420
+ })();
421
+ debug(`[updateIdentifier]: DID: ${did}, VerificationMethodIds for signing: ${signInputs.map((signInput) => signInput.verificationMethodId)}`);
171
422
  const tx = await sdk.updateDidDocTx(signInputs, document, '', this?.fee, undefined, versionId, { sdk: sdk });
172
423
  assert(tx.code === 0, `cosmos_transaction: Failed to update DID. Reason: ${tx.rawLog}`);
173
- //* Currently, only one controller key is supported.
174
- //* We assume that the first key in the list is the controller key.
175
- //* This is subject to change in the near future.
176
- const keys = options.keys
424
+ // Setup return value
425
+ const identifier = {
426
+ did: document.id,
427
+ keys: [],
428
+ services: document.service || [],
429
+ provider: document.id.split(':').splice(0, 3).join(':'),
430
+ };
431
+ ;
432
+ // Get keys for updated DIDDocument
433
+ // Here we are importing only the keys which has privateKey field set up
434
+ identifier.keys = options.keys && areKeysImportable
177
435
  ? await (async function (that) {
178
436
  const scopedKeys = [];
179
437
  for (const key of options.keys) {
@@ -193,31 +451,56 @@ export class CheqdDIDProvider extends AbstractIdentifierProvider {
193
451
  scopedKeys.push(managedKey);
194
452
  }
195
453
  }
454
+ // Setup controllerKeyId
455
+ identifier.controllerKeyId = scopedKeys[0].kid;
196
456
  return scopedKeys;
197
457
  })(this)
198
- : await this.getKeysFromVerificationMethod(context, document.verificationMethod);
199
- const controllerKey = keys[0];
200
- const identifier = {
201
- did: document.id,
202
- controllerKeyId: controllerKey.kid,
203
- keys,
204
- services: document.service || [],
205
- provider: document.id.split(':').splice(0, 3).join(':'),
206
- };
458
+ : await (async function (that) {
459
+ const vmKeys = await that.getKeysFromVerificationMethod(context, document.verificationMethod);
460
+ // Setup controllerKeyId. It should be asocciated with verificationMethod list
461
+ identifier.controllerKeyId = vmKeys[0].kid;
462
+ // Setup controllerKeyRefs. It's a list of keys which were used for signing the transaction
463
+ identifier.controllerKeyRefs = signInfoProvider.getControllerKeyRefs();
464
+ // Setup controllerKeys. It's a list of keys to display
465
+ identifier.controllerKeys = signInfoProvider.getControllerKeysForSigning();
466
+ // Here we are returning all keys associated with the DIDDocument (including keys for controllers)
467
+ // We already compiled it while discovering the verificationMethodIds
468
+ return vmKeys;
469
+ })(this);
207
470
  debug('Updated DID', did);
208
471
  return identifier;
209
472
  }
210
473
  async deactivateIdentifier({ did, document, options, }, context) {
211
474
  const sdk = await this.getCheqdSDK(options?.fee);
212
475
  const versionId = options.versionId || v4();
213
- const signInputs = options.keys
476
+ const keys = options.keys || [];
477
+ // Providr for compiling SignInfos
478
+ const signInfoProvider = new CheqdSignInfoProvider(context);
479
+ // It answers on question what the keys are actually in input
480
+ const areKeysImportable = keys.length > 0 && keys.every((key) => {
481
+ return Object.keys(key).includes('privateKeyHex');
482
+ });
483
+ const publicKeyHexs = areKeysImportable
484
+ ? []
485
+ : keys.map((key) => key.publicKeyHex);
486
+ // Check that publicKeyHexs are placed in kms
487
+ const _r = await signInfoProvider.keysAreInKMS(publicKeyHexs);
488
+ if (_r.error) {
489
+ throw Error(`[deactivateIdentifier]: ${_r.error}`);
490
+ }
491
+ const signInputs = areKeysImportable
214
492
  ? (function () {
493
+ // We are sure here that keys are placed
215
494
  return options.keys.map((key) => createSignInputsFromImportableEd25519Key(key, document.verificationMethod || []));
216
495
  })()
217
- : await (async function (that) {
218
- const data = await createMsgDeactivateDidDocPayloadToSign(document, versionId);
219
- return await that.signPayload(context, data, document.verificationMethod);
220
- })(this);
496
+ : await (async function () {
497
+ await signInfoProvider.deactivateIdentifierCompileSignInfos(document, {
498
+ publicKeyHexs,
499
+ versionId
500
+ });
501
+ return signInfoProvider.getSignInfos();
502
+ })();
503
+ debug(`[deactivateIdentifier]: DID: ${did}, VerificationMethodIds for signing: ${signInputs.map((signInput) => signInput.verificationMethodId)}`);
221
504
  const tx = await sdk.deactivateDidDocTx(signInputs, document, '', this?.fee, undefined, versionId, { sdk: sdk });
222
505
  assert(tx.code === 0, `cosmos_transaction: Failed to update DID. Reason: ${tx.rawLog}`);
223
506
  debug('Deactivated DID', did);
@@ -225,13 +508,30 @@ export class CheqdDIDProvider extends AbstractIdentifierProvider {
225
508
  }
226
509
  async createResource({ options, }, context) {
227
510
  const sdk = await this.getCheqdSDK(options?.fee);
228
- const signInputs = options.signInputs
511
+ const signInfoProvider = new CheqdSignInfoProvider(context);
512
+ const inputKeys = options.signInputs || [];
513
+ const areSignInputs = inputKeys.length > 0 && inputKeys.every((key) => {
514
+ return Object.keys(key).includes('privateKeyHex');
515
+ });
516
+ // options.signInputs may be list of keys with privateKey ibside or just list of publicKeys
517
+ const publicKeyHexs = areSignInputs
518
+ ? []
519
+ : inputKeys.map((key) => key.publicKeyHex);
520
+ // Check that publicKeyHexs are placed in kms
521
+ const _r = await signInfoProvider.keysAreInKMS(publicKeyHexs);
522
+ if (_r.error) {
523
+ throw Error(`[updateIdentifier]: ${_r.error}`);
524
+ }
525
+ const signInputs = areSignInputs
229
526
  ? options.signInputs
230
527
  : await (async function (that) {
231
528
  const did = `did:cheqd:${that.network}:${options.payload.collectionId}`;
232
- const { didDocument } = await sdk.queryDidDoc(did, { sdk: sdk });
233
- return await that.signPayload(context, MsgCreateResourcePayload.encode(MsgCreateResourcePayload.fromPartial(options.payload)).finish(), didDocument?.verificationMethod);
529
+ await signInfoProvider.resourceCreateCompileSignInfos(did, options.payload, {
530
+ publicKeyHexs,
531
+ });
532
+ return signInfoProvider.getSignInfos();
234
533
  })(this);
534
+ debug(`[createResource]: DID: did:cheqd:${this.network}:${options.payload.collectionId} , VerificationMethodIds for signing: ${signInputs.map((signInput) => signInput.verificationMethodId)}`);
235
535
  const tx = await sdk.createLinkedResourceTx(signInputs, options.payload, '', this?.fee, undefined, {
236
536
  sdk: sdk,
237
537
  });
@@ -246,8 +546,8 @@ export class CheqdDIDProvider extends AbstractIdentifierProvider {
246
546
  return undefined;
247
547
  }
248
548
  };
249
- if (options.signInputs) {
250
- const signInput = options.signInputs.filter((input) => mapKeyType(input.keyType) !== undefined);
549
+ if (areSignInputs) {
550
+ const signInput = inputKeys.filter((input) => mapKeyType(input.keyType) !== undefined);
251
551
  const keys = [];
252
552
  for (const input of signInput) {
253
553
  let managedKey;
@@ -323,7 +623,8 @@ export class CheqdDIDProvider extends AbstractIdentifierProvider {
323
623
  async getKeysFromVerificationMethod(context, verificationMethod = []) {
324
624
  return Promise.all(verificationMethod.map(async (method) => {
325
625
  const kid = extractPublicKeyHex(method);
326
- return await context.agent.keyManagerGet({ kid });
626
+ const key = await context.agent.keyManagerGet({ kid });
627
+ return { ...key, controller: method.controller };
327
628
  })).catch((error) => {
328
629
  throw new Error(`Failed to sign payload: ${error}`);
329
630
  });