@cheqd/did-provider-cheqd 3.6.16 → 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.
- package/build/cjs/agent/ICheqd.d.ts +4 -4
- package/build/cjs/agent/ICheqd.d.ts.map +1 -1
- package/build/cjs/agent/ICheqd.js +1 -1
- package/build/cjs/agent/ICheqd.js.map +1 -1
- package/build/cjs/did-manager/cheqd-did-provider.d.ts +64 -4
- package/build/cjs/did-manager/cheqd-did-provider.d.ts.map +1 -1
- package/build/cjs/did-manager/cheqd-did-provider.js +343 -40
- package/build/cjs/did-manager/cheqd-did-provider.js.map +1 -1
- package/build/cjs/utils/helpers.d.ts +2 -0
- package/build/cjs/utils/helpers.d.ts.map +1 -1
- package/build/cjs/utils/helpers.js +14 -1
- package/build/cjs/utils/helpers.js.map +1 -1
- package/build/esm/agent/ICheqd.d.ts +4 -4
- package/build/esm/agent/ICheqd.d.ts.map +1 -1
- package/build/esm/agent/ICheqd.js +1 -1
- package/build/esm/agent/ICheqd.js.map +1 -1
- package/build/esm/did-manager/cheqd-did-provider.d.ts +64 -4
- package/build/esm/did-manager/cheqd-did-provider.d.ts.map +1 -1
- package/build/esm/did-manager/cheqd-did-provider.js +340 -39
- package/build/esm/did-manager/cheqd-did-provider.js.map +1 -1
- package/build/esm/utils/helpers.d.ts +2 -0
- package/build/esm/utils/helpers.d.ts.map +1 -1
- package/build/esm/utils/helpers.js +12 -0
- package/build/esm/utils/helpers.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 +4 -4
- package/build/types/agent/ICheqd.d.ts.map +1 -1
- package/build/types/did-manager/cheqd-did-provider.d.ts +64 -4
- package/build/types/did-manager/cheqd-did-provider.d.ts.map +1 -1
- package/build/types/utils/helpers.d.ts +2 -0
- package/build/types/utils/helpers.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/agent/ICheqd.ts +9 -4
- package/src/did-manager/cheqd-did-provider.ts +483 -67
- 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<
|
|
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,YA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C;QACX,OAAO,CAAC,EAAE,GAAG,CAAC;KACd,EACD,OAAO,EAAE,QAAQ,GACf,OAAO,CAAC,GAAG,CAAC;IAIT,kBAAkB,CAAC,IAAI,EAAE;QAC9B,gBAAgB,EAAE,MAAM,CAAC;QACzB,MAAM,EAAE,IAAI,CAAC;QACb,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,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"}
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.createMsgDeactivateDidDocPayloadToSign = exports.createMsgCreateDidDocPayloadToSign = exports.CheqdDIDProvider = exports.EnglishMnemonic = exports.DefaultStatusList2021Encodings = exports.DefaultStatusList2021ResourceTypes = exports.DefaultStatusList2021StatusPurposeTypes = exports.DefaultDkgSupportedChains = exports.DefaultRESTUrls = exports.DefaultRPCUrls = void 0;
|
|
6
|
+
exports.createMsgDeactivateDidDocPayloadToSign = exports.createMsgCreateDidDocPayloadToSign = 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
7
|
/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars, @typescript-eslint/no-non-null-assertion */
|
|
8
8
|
// any is used for extensibility
|
|
9
9
|
// unused vars are kept by convention
|
|
@@ -21,6 +21,7 @@ const uint8arrays_1 = require("uint8arrays");
|
|
|
21
21
|
const index_js_2 = require("@cheqd/ts-proto/cheqd/did/v2/index.js");
|
|
22
22
|
const uuid_1 = require("uuid");
|
|
23
23
|
const lit_protocol_js_1 = require("../dkg-threshold/lit-protocol.js");
|
|
24
|
+
const helpers_js_1 = require("../utils/helpers.js");
|
|
24
25
|
const debug = (0, debug_1.default)('veramo:did-provider-cheqd');
|
|
25
26
|
exports.DefaultRPCUrls = {
|
|
26
27
|
[sdk_1.CheqdNetwork.Mainnet]: 'https://rpc.cheqd.net',
|
|
@@ -48,10 +49,227 @@ exports.DefaultStatusList2021Encodings = {
|
|
|
48
49
|
base64url: 'base64url',
|
|
49
50
|
hex: 'hex',
|
|
50
51
|
};
|
|
52
|
+
class CheqdProviderError extends Error {
|
|
53
|
+
errorCode;
|
|
54
|
+
constructor(message, errorCode) {
|
|
55
|
+
super(message);
|
|
56
|
+
this.errorCode = errorCode;
|
|
57
|
+
this.errorCode = errorCode;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.CheqdProviderError = CheqdProviderError;
|
|
61
|
+
exports.CheqdProviderErrorCodes = {
|
|
62
|
+
DeactivatedController: 'DeactivatedController',
|
|
63
|
+
UnresolvedDID: 'UnresolvedDID',
|
|
64
|
+
EmptyVerificationMethod: 'EmptyVerificationMethod'
|
|
65
|
+
};
|
|
51
66
|
class EnglishMnemonic extends crypto_1.EnglishMnemonic {
|
|
52
67
|
static _mnemonicMatcher = /^[a-z]+( [a-z]+)*$/;
|
|
53
68
|
}
|
|
54
69
|
exports.EnglishMnemonic = EnglishMnemonic;
|
|
70
|
+
class CheqdSignInfoProvider {
|
|
71
|
+
context;
|
|
72
|
+
signInfos;
|
|
73
|
+
publicKeyHexs;
|
|
74
|
+
controllers;
|
|
75
|
+
controllerKeys;
|
|
76
|
+
controllerKeyRefs;
|
|
77
|
+
constructor(context) {
|
|
78
|
+
this.signInfos = [];
|
|
79
|
+
this.publicKeyHexs = [];
|
|
80
|
+
this.controllerKeys = [];
|
|
81
|
+
this.controllerKeyRefs = [];
|
|
82
|
+
this.controllers = [];
|
|
83
|
+
this.context = context;
|
|
84
|
+
}
|
|
85
|
+
setPublicKeyHexs(publicKeyHexs) {
|
|
86
|
+
this.publicKeyHexs = publicKeyHexs;
|
|
87
|
+
}
|
|
88
|
+
setSignInfos(signInfos) {
|
|
89
|
+
this.signInfos = signInfos;
|
|
90
|
+
}
|
|
91
|
+
setControllers(controllers) {
|
|
92
|
+
this.controllers = controllers;
|
|
93
|
+
}
|
|
94
|
+
getSignInfos() {
|
|
95
|
+
return this.signInfos;
|
|
96
|
+
}
|
|
97
|
+
getPublicKeyHexs() {
|
|
98
|
+
return this.publicKeyHexs;
|
|
99
|
+
}
|
|
100
|
+
getControllerKeys() {
|
|
101
|
+
return this.controllerKeys;
|
|
102
|
+
}
|
|
103
|
+
getControllerKeyRefs() {
|
|
104
|
+
return this.controllerKeyRefs;
|
|
105
|
+
}
|
|
106
|
+
getControllerKeysForSigning() {
|
|
107
|
+
const keys = [];
|
|
108
|
+
this.controllers.forEach((controller) => {
|
|
109
|
+
const key = this.controllerKeys.find((key) => key.controller === controller);
|
|
110
|
+
if (key) {
|
|
111
|
+
keys.push(key);
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
return keys;
|
|
115
|
+
}
|
|
116
|
+
async compilePublicKeyHexs(controllers, options) {
|
|
117
|
+
const publicKeyHexs = options.publicKeyHexs || [];
|
|
118
|
+
if (publicKeyHexs.length === 0) {
|
|
119
|
+
for (const controller of controllers) {
|
|
120
|
+
const key = await this.context.agent.didManagerGet({ did: controller }).then((result) => result.keys[0]);
|
|
121
|
+
publicKeyHexs.push(key.kid);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
this.setPublicKeyHexs(publicKeyHexs);
|
|
125
|
+
}
|
|
126
|
+
async compileSignInfos(payload, controllers) {
|
|
127
|
+
// 1. Iterate over the contollers and for each - get DIDDocument and get the verificationMethodId associated with one of publicKeyHexs
|
|
128
|
+
// 1.1 Iterate over the list of verificationMethods and make the checks:
|
|
129
|
+
// 1.1.1 Iterate over publicKeyHexs and convert each publicKeyHex to the verification Material
|
|
130
|
+
// 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
|
|
131
|
+
// 2. Iterate over the pair of verificationMethodIds and publicKeys and create SignInfo§
|
|
132
|
+
// Setup
|
|
133
|
+
const signInfos = [];
|
|
134
|
+
const publicKeyHexs = this.getPublicKeyHexs();
|
|
135
|
+
// Get verificationMethodIds
|
|
136
|
+
const verificationMethodIds = [];
|
|
137
|
+
// Iterate over list of controllers and tries to get the corresponding verificationMethodId associated with one of publicKeyHexs
|
|
138
|
+
for (const controller of controllers) {
|
|
139
|
+
// We need to get here current version of DIDDocument associated with the controller and cannot skip it even if document.id === controller
|
|
140
|
+
// cause in case of remooving verifcation method we need to sign the payload with the old verification method which is on ledger.
|
|
141
|
+
const controllerResolutionResult = await this.context.agent.resolveDid({ didUrl: controller });
|
|
142
|
+
const controllerDidDocument = controllerResolutionResult.didDocument;
|
|
143
|
+
// Check if controller DID document is resolved
|
|
144
|
+
if (!controllerDidDocument) {
|
|
145
|
+
throw new CheqdProviderError('[did-provider-cheqd]: compileSignInfos: Error while resolving the DID document for controller DID: ' + controller, exports.CheqdProviderErrorCodes.UnresolvedDID);
|
|
146
|
+
}
|
|
147
|
+
// Check that controller's DIDDocument is active
|
|
148
|
+
if (controllerResolutionResult.didDocumentMetadata.deactivated) {
|
|
149
|
+
throw new CheqdProviderError(`[did-provider-cheqd]: compileSignInfos: DIDDocument associated with controller ${controller} is deactivated`, exports.CheqdProviderErrorCodes.DeactivatedController);
|
|
150
|
+
}
|
|
151
|
+
// Check if controller DID document contains verification methods
|
|
152
|
+
if (!controllerDidDocument.verificationMethod) {
|
|
153
|
+
throw new CheqdProviderError('[did-provider-cheqd]: compileSignInfos: Controller DID document does not contain verification methods', exports.CheqdProviderErrorCodes.EmptyVerificationMethod);
|
|
154
|
+
}
|
|
155
|
+
// Iterate over verificationMethods and by comparing publicKeys get the verificationMethod Id
|
|
156
|
+
for (const vm of controllerDidDocument.verificationMethod) {
|
|
157
|
+
// Try to match verificationMethod with one of publicKeyHexs
|
|
158
|
+
for (const publicKeyHex of publicKeyHexs) {
|
|
159
|
+
// Get publicKeyHex from verificationMethod
|
|
160
|
+
const vmPublicKey = (0, utils_2.extractPublicKeyHex)(vm);
|
|
161
|
+
// Compare publicKeys
|
|
162
|
+
if (publicKeyHex === vmPublicKey) {
|
|
163
|
+
// Create SignInfo object
|
|
164
|
+
signInfos.push({
|
|
165
|
+
verificationMethodId: vm.id,
|
|
166
|
+
signature: (0, utils_2.base64ToBytes)(await this.context.agent.keyManagerSign({
|
|
167
|
+
keyRef: publicKeyHex,
|
|
168
|
+
data: (0, uint8arrays_1.toString)(payload, 'hex'),
|
|
169
|
+
encoding: 'hex',
|
|
170
|
+
})),
|
|
171
|
+
});
|
|
172
|
+
// Setup controllerKeyRefs
|
|
173
|
+
this.controllerKeyRefs.push(publicKeyHex);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
// Setup key structure for display
|
|
177
|
+
const kid = (0, utils_2.extractPublicKeyHex)(vm);
|
|
178
|
+
const key = await this.context.agent.keyManagerGet({ kid });
|
|
179
|
+
this.controllerKeys.push({ ...key, controller: vm.controller });
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
// Setup signInfos
|
|
183
|
+
this.setSignInfos(signInfos);
|
|
184
|
+
}
|
|
185
|
+
async updateIdentifierCompileSignInfos(didDocument, options) {
|
|
186
|
+
// Steps to solve the issue:
|
|
187
|
+
// 1. Collect list of controllers. The user can remove, append and reqrite the controller.
|
|
188
|
+
// But we need to send all the signatures, old and news
|
|
189
|
+
// 2. Generate payloads
|
|
190
|
+
// 3. Compile list of signInfos
|
|
191
|
+
// Get current version of DIDDocument
|
|
192
|
+
const actualDIDDocument = await this.context.agent.resolveDid({ didUrl: didDocument.id });
|
|
193
|
+
if (!actualDIDDocument.didDocument) {
|
|
194
|
+
throw new Error('[did-provider-cheqd]: updateIdentifierSignInfos: Error while resolving the DID document for updating with error: ' + actualDIDDocument.didResolutionMetadata.error);
|
|
195
|
+
}
|
|
196
|
+
// Compile controllers
|
|
197
|
+
const updatedControllers = (0, helpers_js_1.getControllers)(didDocument);
|
|
198
|
+
const actualControllers = (0, helpers_js_1.getControllers)(actualDIDDocument.didDocument);
|
|
199
|
+
const controllers = [...new Set([...updatedControllers, ...actualControllers])];
|
|
200
|
+
// Generate payload
|
|
201
|
+
const versionId = options.versionId || (0, uuid_1.v4)();
|
|
202
|
+
const payload = await createMsgCreateDidDocPayloadToSign(didDocument, versionId);
|
|
203
|
+
// Setup publicKeyHexs
|
|
204
|
+
await this.compilePublicKeyHexs(controllers, options);
|
|
205
|
+
// Setup controllers. Here it's supposed to be a list of controllers which are associated with the DIDDocument
|
|
206
|
+
this.setControllers(updatedControllers);
|
|
207
|
+
// Setup SignInfos
|
|
208
|
+
await this.compileSignInfos(payload, controllers);
|
|
209
|
+
}
|
|
210
|
+
async deactivateIdentifierCompileSignInfos(didDocument, options) {
|
|
211
|
+
// Steps to solve the issue:
|
|
212
|
+
// 1. Collect list of controllers. The user can remove, append and reqrite the controller.
|
|
213
|
+
// But we need to send all the signatures, old and news
|
|
214
|
+
// Generate payload to sign
|
|
215
|
+
// 3. Compile list of signInfos
|
|
216
|
+
// Get Controllers
|
|
217
|
+
const controllers = (0, helpers_js_1.getControllers)(didDocument);
|
|
218
|
+
// For did deactivation ledger requires the signature from original DID Document controller
|
|
219
|
+
// So we need to add the controller to the list of controllers
|
|
220
|
+
if (!controllers.includes(didDocument.id)) {
|
|
221
|
+
controllers.push(didDocument.id);
|
|
222
|
+
}
|
|
223
|
+
// Generate payload
|
|
224
|
+
const versionId = options.versionId || (0, uuid_1.v4)();
|
|
225
|
+
const payload = await createMsgDeactivateDidDocPayloadToSign(didDocument, versionId);
|
|
226
|
+
// Setup publicKeyHexs
|
|
227
|
+
await this.compilePublicKeyHexs(controllers, options);
|
|
228
|
+
// Setup SignInfos
|
|
229
|
+
await this.compileSignInfos(payload, controllers);
|
|
230
|
+
}
|
|
231
|
+
async resourceCreateCompileSignInfos(did, resourcePayload, options) {
|
|
232
|
+
// Steps to solve the issue:
|
|
233
|
+
// 1. Collect list of controllers. The user can remove, append and reqrite the controller.
|
|
234
|
+
// But we need to send all the signatures, old and news
|
|
235
|
+
// Generate payload to sign
|
|
236
|
+
// 3. Compile list of signInfos
|
|
237
|
+
const didDocument = await this.context.agent.resolveDid({ didUrl: did }).then((result) => result.didDocument);
|
|
238
|
+
if (!didDocument) {
|
|
239
|
+
throw new Error('[did-provider-cheqd]: resourceCreateCompileSignInfos: Erro while resolving the DID document for controller DID: ' + did);
|
|
240
|
+
}
|
|
241
|
+
// Get Controllers
|
|
242
|
+
const controllers = (0, helpers_js_1.getControllers)(didDocument);
|
|
243
|
+
// For resource creation ledger requires the signature from original DID Document controller
|
|
244
|
+
// So we need to add the controller to the list of controllers
|
|
245
|
+
if (!controllers.includes(did)) {
|
|
246
|
+
controllers.push(did);
|
|
247
|
+
}
|
|
248
|
+
// Generate payload
|
|
249
|
+
const payload = await index_js_1.MsgCreateResourcePayload.encode(index_js_1.MsgCreateResourcePayload.fromPartial(resourcePayload)).finish();
|
|
250
|
+
// Setup publicKeyHexs
|
|
251
|
+
await this.compilePublicKeyHexs(controllers, options);
|
|
252
|
+
// Setup SignInfos
|
|
253
|
+
await this.compileSignInfos(payload, controllers);
|
|
254
|
+
}
|
|
255
|
+
async keysAreInKMS(publicKeys) {
|
|
256
|
+
for (const keyRef of publicKeys) {
|
|
257
|
+
try {
|
|
258
|
+
await this.context.agent.keyManagerGet({ kid: keyRef });
|
|
259
|
+
}
|
|
260
|
+
catch (e) {
|
|
261
|
+
return {
|
|
262
|
+
placed: false,
|
|
263
|
+
error: `PublicKey: ${keyRef} is not placed in kms`
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
return {
|
|
268
|
+
placed: true
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
exports.CheqdSignInfoProvider = CheqdSignInfoProvider;
|
|
55
273
|
/**
|
|
56
274
|
* {@link @veramo/did-manager#DIDManager} identifier provider for `did:cheqd` identifiers.
|
|
57
275
|
* @public
|
|
@@ -127,10 +345,16 @@ class CheqdDIDProvider extends did_manager_1.AbstractIdentifierProvider {
|
|
|
127
345
|
sdk: sdk,
|
|
128
346
|
});
|
|
129
347
|
(0, utils_1.assert)(tx.code === 0, `cosmos_transaction: Failed to create DID. Reason: ${tx.rawLog}`);
|
|
348
|
+
const identifier = {
|
|
349
|
+
did: options.document.id,
|
|
350
|
+
keys: [],
|
|
351
|
+
services: options.document.service || [],
|
|
352
|
+
provider: options.document.id.split(':').splice(0, 3).join(':'),
|
|
353
|
+
};
|
|
130
354
|
//* Currently, only one controller key is supported.
|
|
131
355
|
//* We assume that the first key in the list is the controller key.
|
|
132
356
|
//* This is subject to change in the near future.
|
|
133
|
-
|
|
357
|
+
identifier.keys = options.keys
|
|
134
358
|
? await (async function (that) {
|
|
135
359
|
const scopedKeys = [];
|
|
136
360
|
for (const key of options.keys) {
|
|
@@ -152,35 +376,71 @@ class CheqdDIDProvider extends did_manager_1.AbstractIdentifierProvider {
|
|
|
152
376
|
}
|
|
153
377
|
return scopedKeys;
|
|
154
378
|
})(this)
|
|
155
|
-
: await
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
379
|
+
: await (async function (that) {
|
|
380
|
+
const vmKeys = await that.getKeysFromVerificationMethod(context, options.document.verificationMethod);
|
|
381
|
+
// Setup controllerKeyRefs
|
|
382
|
+
identifier.controllerKeyRefs = vmKeys.map((key) => key.kid);
|
|
383
|
+
// Setup controllerKeys. It's a list of keys to display
|
|
384
|
+
identifier.controllerKeys = vmKeys.map((key) => ({ ...key, controller: options.document.id }));
|
|
385
|
+
// Here we are returning all keys associated with the DIDDocument (including keys for controllers)
|
|
386
|
+
// We already compiled it while discovering the verificationMethodIds
|
|
387
|
+
return vmKeys;
|
|
388
|
+
})(this);
|
|
389
|
+
await this.getKeysFromVerificationMethod(context, options.document.verificationMethod);
|
|
390
|
+
const controllerKey = identifier.keys[0];
|
|
391
|
+
identifier.controllerKeyId = controllerKey.kid;
|
|
164
392
|
debug('Created DID', identifier.did);
|
|
165
393
|
return identifier;
|
|
166
394
|
}
|
|
167
395
|
async updateIdentifier({ did, document, options, }, context) {
|
|
396
|
+
// Handle input parameters
|
|
168
397
|
const sdk = await this.getCheqdSDK(options?.fee);
|
|
169
398
|
const versionId = options.versionId || (0, uuid_1.v4)();
|
|
170
|
-
const
|
|
399
|
+
const keys = options.keys || [];
|
|
400
|
+
const signInfoProvider = new CheqdSignInfoProvider(context);
|
|
401
|
+
// It answers on question what the keys are actually in input
|
|
402
|
+
const areKeysImportable = keys.length > 0 && keys.every((key) => {
|
|
403
|
+
return Object.keys(key).includes('privateKeyHex');
|
|
404
|
+
});
|
|
405
|
+
// options.keys may be list of keys with privateKey ibside or just list of publicKeys
|
|
406
|
+
const publicKeyHexs = areKeysImportable
|
|
407
|
+
? []
|
|
408
|
+
: keys.map((key) => key.publicKeyHex);
|
|
409
|
+
// Check that publicKeyHexs are placed in kms if the user provides the keys
|
|
410
|
+
const _r = await signInfoProvider.keysAreInKMS(publicKeyHexs);
|
|
411
|
+
if (_r.error) {
|
|
412
|
+
throw Error(`[updateIdentifier]: ${_r.error}`);
|
|
413
|
+
}
|
|
414
|
+
// Check that verificationMethod on changed DIDDocument list exists and not empty
|
|
415
|
+
if (!document.verificationMethod || document.verificationMethod.length === 0) {
|
|
416
|
+
throw new CheqdProviderError('[updateIdentifier]: VerificationMethod should be placed and not be empty', exports.CheqdProviderErrorCodes.EmptyVerificationMethod);
|
|
417
|
+
}
|
|
418
|
+
const signInputs = areKeysImportable
|
|
171
419
|
? (function () {
|
|
420
|
+
// We are sure here that keys are placed
|
|
172
421
|
return options.keys.map((key) => (0, sdk_1.createSignInputsFromImportableEd25519Key)(key, document.verificationMethod || []));
|
|
173
422
|
})()
|
|
174
|
-
: await (async function (
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
423
|
+
: await (async function () {
|
|
424
|
+
await signInfoProvider.updateIdentifierCompileSignInfos(document, {
|
|
425
|
+
publicKeyHexs,
|
|
426
|
+
versionId
|
|
427
|
+
});
|
|
428
|
+
return signInfoProvider.getSignInfos();
|
|
429
|
+
})();
|
|
430
|
+
debug(`[updateIdentifier]: DID: ${did}, VerificationMethodIds for signing: ${signInputs.map((signInput) => signInput.verificationMethodId)}`);
|
|
178
431
|
const tx = await sdk.updateDidDocTx(signInputs, document, '', this?.fee, undefined, versionId, { sdk: sdk });
|
|
179
432
|
(0, utils_1.assert)(tx.code === 0, `cosmos_transaction: Failed to update DID. Reason: ${tx.rawLog}`);
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
433
|
+
// Setup return value
|
|
434
|
+
const identifier = {
|
|
435
|
+
did: document.id,
|
|
436
|
+
keys: [],
|
|
437
|
+
services: document.service || [],
|
|
438
|
+
provider: document.id.split(':').splice(0, 3).join(':'),
|
|
439
|
+
};
|
|
440
|
+
;
|
|
441
|
+
// Get keys for updated DIDDocument
|
|
442
|
+
// Here we are importing only the keys which has privateKey field set up
|
|
443
|
+
identifier.keys = options.keys && areKeysImportable
|
|
184
444
|
? await (async function (that) {
|
|
185
445
|
const scopedKeys = [];
|
|
186
446
|
for (const key of options.keys) {
|
|
@@ -200,31 +460,56 @@ class CheqdDIDProvider extends did_manager_1.AbstractIdentifierProvider {
|
|
|
200
460
|
scopedKeys.push(managedKey);
|
|
201
461
|
}
|
|
202
462
|
}
|
|
463
|
+
// Setup controllerKeyId
|
|
464
|
+
identifier.controllerKeyId = scopedKeys[0].kid;
|
|
203
465
|
return scopedKeys;
|
|
204
466
|
})(this)
|
|
205
|
-
: await
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
467
|
+
: await (async function (that) {
|
|
468
|
+
const vmKeys = await that.getKeysFromVerificationMethod(context, document.verificationMethod);
|
|
469
|
+
// Setup controllerKeyId. It should be asocciated with verificationMethod list
|
|
470
|
+
identifier.controllerKeyId = vmKeys[0].kid;
|
|
471
|
+
// Setup controllerKeyRefs. It's a list of keys which were used for signing the transaction
|
|
472
|
+
identifier.controllerKeyRefs = signInfoProvider.getControllerKeyRefs();
|
|
473
|
+
// Setup controllerKeys. It's a list of keys to display
|
|
474
|
+
identifier.controllerKeys = signInfoProvider.getControllerKeysForSigning();
|
|
475
|
+
// Here we are returning all keys associated with the DIDDocument (including keys for controllers)
|
|
476
|
+
// We already compiled it while discovering the verificationMethodIds
|
|
477
|
+
return vmKeys;
|
|
478
|
+
})(this);
|
|
214
479
|
debug('Updated DID', did);
|
|
215
480
|
return identifier;
|
|
216
481
|
}
|
|
217
482
|
async deactivateIdentifier({ did, document, options, }, context) {
|
|
218
483
|
const sdk = await this.getCheqdSDK(options?.fee);
|
|
219
484
|
const versionId = options.versionId || (0, uuid_1.v4)();
|
|
220
|
-
const
|
|
485
|
+
const keys = options.keys || [];
|
|
486
|
+
// Providr for compiling SignInfos
|
|
487
|
+
const signInfoProvider = new CheqdSignInfoProvider(context);
|
|
488
|
+
// It answers on question what the keys are actually in input
|
|
489
|
+
const areKeysImportable = keys.length > 0 && keys.every((key) => {
|
|
490
|
+
return Object.keys(key).includes('privateKeyHex');
|
|
491
|
+
});
|
|
492
|
+
const publicKeyHexs = areKeysImportable
|
|
493
|
+
? []
|
|
494
|
+
: keys.map((key) => key.publicKeyHex);
|
|
495
|
+
// Check that publicKeyHexs are placed in kms
|
|
496
|
+
const _r = await signInfoProvider.keysAreInKMS(publicKeyHexs);
|
|
497
|
+
if (_r.error) {
|
|
498
|
+
throw Error(`[deactivateIdentifier]: ${_r.error}`);
|
|
499
|
+
}
|
|
500
|
+
const signInputs = areKeysImportable
|
|
221
501
|
? (function () {
|
|
502
|
+
// We are sure here that keys are placed
|
|
222
503
|
return options.keys.map((key) => (0, sdk_1.createSignInputsFromImportableEd25519Key)(key, document.verificationMethod || []));
|
|
223
504
|
})()
|
|
224
|
-
: await (async function (
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
505
|
+
: await (async function () {
|
|
506
|
+
await signInfoProvider.deactivateIdentifierCompileSignInfos(document, {
|
|
507
|
+
publicKeyHexs,
|
|
508
|
+
versionId
|
|
509
|
+
});
|
|
510
|
+
return signInfoProvider.getSignInfos();
|
|
511
|
+
})();
|
|
512
|
+
debug(`[deactivateIdentifier]: DID: ${did}, VerificationMethodIds for signing: ${signInputs.map((signInput) => signInput.verificationMethodId)}`);
|
|
228
513
|
const tx = await sdk.deactivateDidDocTx(signInputs, document, '', this?.fee, undefined, versionId, { sdk: sdk });
|
|
229
514
|
(0, utils_1.assert)(tx.code === 0, `cosmos_transaction: Failed to update DID. Reason: ${tx.rawLog}`);
|
|
230
515
|
debug('Deactivated DID', did);
|
|
@@ -232,13 +517,30 @@ class CheqdDIDProvider extends did_manager_1.AbstractIdentifierProvider {
|
|
|
232
517
|
}
|
|
233
518
|
async createResource({ options, }, context) {
|
|
234
519
|
const sdk = await this.getCheqdSDK(options?.fee);
|
|
235
|
-
const
|
|
520
|
+
const signInfoProvider = new CheqdSignInfoProvider(context);
|
|
521
|
+
const inputKeys = options.signInputs || [];
|
|
522
|
+
const areSignInputs = inputKeys.length > 0 && inputKeys.every((key) => {
|
|
523
|
+
return Object.keys(key).includes('privateKeyHex');
|
|
524
|
+
});
|
|
525
|
+
// options.signInputs may be list of keys with privateKey ibside or just list of publicKeys
|
|
526
|
+
const publicKeyHexs = areSignInputs
|
|
527
|
+
? []
|
|
528
|
+
: inputKeys.map((key) => key.publicKeyHex);
|
|
529
|
+
// Check that publicKeyHexs are placed in kms
|
|
530
|
+
const _r = await signInfoProvider.keysAreInKMS(publicKeyHexs);
|
|
531
|
+
if (_r.error) {
|
|
532
|
+
throw Error(`[updateIdentifier]: ${_r.error}`);
|
|
533
|
+
}
|
|
534
|
+
const signInputs = areSignInputs
|
|
236
535
|
? options.signInputs
|
|
237
536
|
: await (async function (that) {
|
|
238
537
|
const did = `did:cheqd:${that.network}:${options.payload.collectionId}`;
|
|
239
|
-
|
|
240
|
-
|
|
538
|
+
await signInfoProvider.resourceCreateCompileSignInfos(did, options.payload, {
|
|
539
|
+
publicKeyHexs,
|
|
540
|
+
});
|
|
541
|
+
return signInfoProvider.getSignInfos();
|
|
241
542
|
})(this);
|
|
543
|
+
debug(`[createResource]: DID: did:cheqd:${this.network}:${options.payload.collectionId} , VerificationMethodIds for signing: ${signInputs.map((signInput) => signInput.verificationMethodId)}`);
|
|
242
544
|
const tx = await sdk.createLinkedResourceTx(signInputs, options.payload, '', this?.fee, undefined, {
|
|
243
545
|
sdk: sdk,
|
|
244
546
|
});
|
|
@@ -253,8 +555,8 @@ class CheqdDIDProvider extends did_manager_1.AbstractIdentifierProvider {
|
|
|
253
555
|
return undefined;
|
|
254
556
|
}
|
|
255
557
|
};
|
|
256
|
-
if (
|
|
257
|
-
const signInput =
|
|
558
|
+
if (areSignInputs) {
|
|
559
|
+
const signInput = inputKeys.filter((input) => mapKeyType(input.keyType) !== undefined);
|
|
258
560
|
const keys = [];
|
|
259
561
|
for (const input of signInput) {
|
|
260
562
|
let managedKey;
|
|
@@ -330,7 +632,8 @@ class CheqdDIDProvider extends did_manager_1.AbstractIdentifierProvider {
|
|
|
330
632
|
async getKeysFromVerificationMethod(context, verificationMethod = []) {
|
|
331
633
|
return Promise.all(verificationMethod.map(async (method) => {
|
|
332
634
|
const kid = (0, utils_2.extractPublicKeyHex)(method);
|
|
333
|
-
|
|
635
|
+
const key = await context.agent.keyManagerGet({ kid });
|
|
636
|
+
return { ...key, controller: method.controller };
|
|
334
637
|
})).catch((error) => {
|
|
335
638
|
throw new Error(`Failed to sign payload: ${error}`);
|
|
336
639
|
});
|