@credo-ts/cheqd 0.4.1-alpha.157
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/LICENSE +202 -0
- package/README.md +31 -0
- package/build/CheqdModule.d.ts +9 -0
- package/build/CheqdModule.js +31 -0
- package/build/CheqdModule.js.map +1 -0
- package/build/CheqdModuleConfig.d.ts +17 -0
- package/build/CheqdModuleConfig.js +14 -0
- package/build/CheqdModuleConfig.js.map +1 -0
- package/build/anoncreds/index.d.ts +1 -0
- package/build/anoncreds/index.js +6 -0
- package/build/anoncreds/index.js.map +1 -0
- package/build/anoncreds/services/CheqdAnonCredsRegistry.d.ts +19 -0
- package/build/anoncreds/services/CheqdAnonCredsRegistry.js +264 -0
- package/build/anoncreds/services/CheqdAnonCredsRegistry.js.map +1 -0
- package/build/anoncreds/utils/identifiers.d.ts +12 -0
- package/build/anoncreds/utils/identifiers.js +53 -0
- package/build/anoncreds/utils/identifiers.js.map +1 -0
- package/build/anoncreds/utils/transform.d.ts +43 -0
- package/build/anoncreds/utils/transform.js +170 -0
- package/build/anoncreds/utils/transform.js.map +1 -0
- package/build/dids/CheqdDidRegistrar.d.ts +72 -0
- package/build/dids/CheqdDidRegistrar.js +320 -0
- package/build/dids/CheqdDidRegistrar.js.map +1 -0
- package/build/dids/CheqdDidResolver.d.ts +24 -0
- package/build/dids/CheqdDidResolver.js +170 -0
- package/build/dids/CheqdDidResolver.js.map +1 -0
- package/build/dids/didCheqdUtil.d.ts +28 -0
- package/build/dids/didCheqdUtil.js +129 -0
- package/build/dids/didCheqdUtil.js.map +1 -0
- package/build/dids/index.d.ts +2 -0
- package/build/dids/index.js +8 -0
- package/build/dids/index.js.map +1 -0
- package/build/index.d.ts +5 -0
- package/build/index.js +17 -0
- package/build/index.js.map +1 -0
- package/build/ledger/CheqdLedgerService.d.ts +33 -0
- package/build/ledger/CheqdLedgerService.js +92 -0
- package/build/ledger/CheqdLedgerService.js.map +1 -0
- package/build/ledger/index.d.ts +1 -0
- package/build/ledger/index.js +6 -0
- package/build/ledger/index.js.map +1 -0
- package/package.json +44 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseCheqdDid = exports.cheqdResourceMetadataRegex = exports.cheqdResourceRegex = exports.cheqdDidMetadataRegex = exports.cheqdDidVersionsRegex = exports.cheqdDidVersionRegex = exports.cheqdDidRegex = exports.cheqdSdkAnonCredsRegistryIdentifierRegex = void 0;
|
|
4
|
+
const core_1 = require("@credo-ts/core");
|
|
5
|
+
const class_validator_1 = require("class-validator");
|
|
6
|
+
const ID_CHAR = '([a-z,A-Z,0-9,-])';
|
|
7
|
+
const NETWORK = '(testnet|mainnet)';
|
|
8
|
+
const IDENTIFIER = `((?:${ID_CHAR}*:)*(${ID_CHAR}+))`;
|
|
9
|
+
const PATH = `(/[^#?]*)?`;
|
|
10
|
+
const QUERY = `([?][^#]*)?`;
|
|
11
|
+
const VERSION_ID = `(.*?)`;
|
|
12
|
+
const FRAGMENT = `([#].*)?`;
|
|
13
|
+
exports.cheqdSdkAnonCredsRegistryIdentifierRegex = new RegExp(`^did:cheqd:${NETWORK}:${IDENTIFIER}${PATH}${QUERY}${FRAGMENT}$`);
|
|
14
|
+
exports.cheqdDidRegex = new RegExp(`^did:cheqd:${NETWORK}:${IDENTIFIER}${QUERY}${FRAGMENT}$`);
|
|
15
|
+
exports.cheqdDidVersionRegex = new RegExp(`^did:cheqd:${NETWORK}:${IDENTIFIER}/version/${VERSION_ID}${QUERY}${FRAGMENT}$`);
|
|
16
|
+
exports.cheqdDidVersionsRegex = new RegExp(`^did:cheqd:${NETWORK}:${IDENTIFIER}/versions${QUERY}${FRAGMENT}$`);
|
|
17
|
+
exports.cheqdDidMetadataRegex = new RegExp(`^did:cheqd:${NETWORK}:${IDENTIFIER}/metadata${QUERY}${FRAGMENT}$`);
|
|
18
|
+
exports.cheqdResourceRegex = new RegExp(`^did:cheqd:${NETWORK}:${IDENTIFIER}/resources/${IDENTIFIER}${QUERY}${FRAGMENT}$`);
|
|
19
|
+
exports.cheqdResourceMetadataRegex = new RegExp(`^did:cheqd:${NETWORK}:${IDENTIFIER}/resources/${IDENTIFIER}/metadata${QUERY}${FRAGMENT}`);
|
|
20
|
+
function parseCheqdDid(didUrl) {
|
|
21
|
+
if (didUrl === '' || !didUrl)
|
|
22
|
+
return null;
|
|
23
|
+
const sections = didUrl.match(exports.cheqdSdkAnonCredsRegistryIdentifierRegex);
|
|
24
|
+
if (sections) {
|
|
25
|
+
if (!(core_1.utils.isValidUuid(sections[2]) ||
|
|
26
|
+
((0, class_validator_1.isBase58)(sections[2]) && core_1.TypedArrayEncoder.fromBase58(sections[2]).length == 16))) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
const parts = {
|
|
30
|
+
did: `did:cheqd:${sections[1]}:${sections[2]}`,
|
|
31
|
+
method: 'cheqd',
|
|
32
|
+
network: sections[1],
|
|
33
|
+
id: sections[2],
|
|
34
|
+
didUrl,
|
|
35
|
+
};
|
|
36
|
+
if (sections[7]) {
|
|
37
|
+
const params = sections[7].slice(1).split('&');
|
|
38
|
+
parts.params = {};
|
|
39
|
+
for (const p of params) {
|
|
40
|
+
const kv = p.split('=');
|
|
41
|
+
parts.params[kv[0]] = kv[1];
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (sections[6])
|
|
45
|
+
parts.path = sections[6];
|
|
46
|
+
if (sections[8])
|
|
47
|
+
parts.fragment = sections[8].slice(1);
|
|
48
|
+
return parts;
|
|
49
|
+
}
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
exports.parseCheqdDid = parseCheqdDid;
|
|
53
|
+
//# sourceMappingURL=identifiers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identifiers.js","sourceRoot":"","sources":["../../../src/anoncreds/utils/identifiers.ts"],"names":[],"mappings":";;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,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;QACtD,OAAO,KAAK,CAAA;KACb;IACD,OAAO,IAAI,CAAA;AACb,CAAC;AAhCD,sCAgCC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { AnonCredsCredentialDefinition, AnonCredsRevocationRegistryDefinition, AnonCredsRevocationStatusList, AnonCredsSchema } from '@credo-ts/anoncreds';
|
|
2
|
+
export declare class CheqdSchema {
|
|
3
|
+
constructor(options: Omit<AnonCredsSchema, 'issuerId'>);
|
|
4
|
+
name: string;
|
|
5
|
+
attrNames: string[];
|
|
6
|
+
version: string;
|
|
7
|
+
}
|
|
8
|
+
export declare class CheqdCredentialDefinitionValue {
|
|
9
|
+
primary: Record<string, unknown>;
|
|
10
|
+
revocation?: unknown;
|
|
11
|
+
}
|
|
12
|
+
export declare class CheqdCredentialDefinition {
|
|
13
|
+
constructor(options: Omit<AnonCredsCredentialDefinition, 'issuerId'>);
|
|
14
|
+
schemaId: string;
|
|
15
|
+
type: 'CL';
|
|
16
|
+
tag: string;
|
|
17
|
+
value: CheqdCredentialDefinitionValue;
|
|
18
|
+
}
|
|
19
|
+
export declare class AccumKey {
|
|
20
|
+
z: string;
|
|
21
|
+
}
|
|
22
|
+
export declare class PublicKeys {
|
|
23
|
+
accumKey: AccumKey;
|
|
24
|
+
}
|
|
25
|
+
export declare class CheqdRevocationRegistryDefinitionValue {
|
|
26
|
+
publicKeys: PublicKeys;
|
|
27
|
+
maxCredNum: number;
|
|
28
|
+
tailsLocation: string;
|
|
29
|
+
tailsHash: string;
|
|
30
|
+
}
|
|
31
|
+
export declare class CheqdRevocationRegistryDefinition {
|
|
32
|
+
constructor(options: Omit<AnonCredsRevocationRegistryDefinition, 'issuerId'>);
|
|
33
|
+
revocDefType: 'CL_ACCUM';
|
|
34
|
+
credDefId: string;
|
|
35
|
+
tag: string;
|
|
36
|
+
value: CheqdRevocationRegistryDefinitionValue;
|
|
37
|
+
}
|
|
38
|
+
export declare class CheqdRevocationStatusList {
|
|
39
|
+
constructor(options: Omit<AnonCredsRevocationStatusList, 'issuerId'>);
|
|
40
|
+
revRegDefId: string;
|
|
41
|
+
revocationList: number[];
|
|
42
|
+
currentAccumulator: string;
|
|
43
|
+
}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// These functions will throw an error if the JSON doesn't
|
|
3
|
+
// match the expected interface, even if the JSON is valid.
|
|
4
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
5
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
6
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
7
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
8
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
9
|
+
};
|
|
10
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
11
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.CheqdRevocationStatusList = exports.CheqdRevocationRegistryDefinition = exports.CheqdRevocationRegistryDefinitionValue = exports.PublicKeys = exports.AccumKey = exports.CheqdCredentialDefinition = exports.CheqdCredentialDefinitionValue = exports.CheqdSchema = void 0;
|
|
15
|
+
const class_transformer_1 = require("class-transformer");
|
|
16
|
+
const class_validator_1 = require("class-validator");
|
|
17
|
+
class CheqdSchema {
|
|
18
|
+
constructor(options) {
|
|
19
|
+
if (options) {
|
|
20
|
+
this.name = options.name;
|
|
21
|
+
this.attrNames = options.attrNames;
|
|
22
|
+
this.version = options.version;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
__decorate([
|
|
27
|
+
(0, class_validator_1.IsString)(),
|
|
28
|
+
__metadata("design:type", String)
|
|
29
|
+
], CheqdSchema.prototype, "name", void 0);
|
|
30
|
+
__decorate([
|
|
31
|
+
(0, class_validator_1.IsArray)(),
|
|
32
|
+
(0, class_validator_1.IsString)({ each: true }),
|
|
33
|
+
(0, class_validator_1.ArrayMinSize)(1),
|
|
34
|
+
__metadata("design:type", Array)
|
|
35
|
+
], CheqdSchema.prototype, "attrNames", void 0);
|
|
36
|
+
__decorate([
|
|
37
|
+
(0, class_validator_1.IsString)(),
|
|
38
|
+
__metadata("design:type", String)
|
|
39
|
+
], CheqdSchema.prototype, "version", void 0);
|
|
40
|
+
exports.CheqdSchema = CheqdSchema;
|
|
41
|
+
class CheqdCredentialDefinitionValue {
|
|
42
|
+
}
|
|
43
|
+
__decorate([
|
|
44
|
+
(0, class_validator_1.IsObject)(),
|
|
45
|
+
__metadata("design:type", Object)
|
|
46
|
+
], CheqdCredentialDefinitionValue.prototype, "primary", void 0);
|
|
47
|
+
__decorate([
|
|
48
|
+
(0, class_validator_1.IsObject)(),
|
|
49
|
+
(0, class_validator_1.IsOptional)(),
|
|
50
|
+
__metadata("design:type", Object)
|
|
51
|
+
], CheqdCredentialDefinitionValue.prototype, "revocation", void 0);
|
|
52
|
+
exports.CheqdCredentialDefinitionValue = CheqdCredentialDefinitionValue;
|
|
53
|
+
class CheqdCredentialDefinition {
|
|
54
|
+
constructor(options) {
|
|
55
|
+
if (options) {
|
|
56
|
+
this.schemaId = options.schemaId;
|
|
57
|
+
this.type = options.type;
|
|
58
|
+
this.tag = options.tag;
|
|
59
|
+
this.value = options.value;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
__decorate([
|
|
64
|
+
(0, class_validator_1.IsString)(),
|
|
65
|
+
__metadata("design:type", String)
|
|
66
|
+
], CheqdCredentialDefinition.prototype, "schemaId", void 0);
|
|
67
|
+
__decorate([
|
|
68
|
+
(0, class_validator_1.Contains)('CL'),
|
|
69
|
+
__metadata("design:type", String)
|
|
70
|
+
], CheqdCredentialDefinition.prototype, "type", void 0);
|
|
71
|
+
__decorate([
|
|
72
|
+
(0, class_validator_1.IsString)(),
|
|
73
|
+
__metadata("design:type", String)
|
|
74
|
+
], CheqdCredentialDefinition.prototype, "tag", void 0);
|
|
75
|
+
__decorate([
|
|
76
|
+
(0, class_validator_1.ValidateNested)(),
|
|
77
|
+
(0, class_validator_1.IsInstance)(CheqdCredentialDefinitionValue),
|
|
78
|
+
(0, class_transformer_1.Type)(() => CheqdCredentialDefinitionValue),
|
|
79
|
+
__metadata("design:type", CheqdCredentialDefinitionValue)
|
|
80
|
+
], CheqdCredentialDefinition.prototype, "value", void 0);
|
|
81
|
+
exports.CheqdCredentialDefinition = CheqdCredentialDefinition;
|
|
82
|
+
class AccumKey {
|
|
83
|
+
}
|
|
84
|
+
__decorate([
|
|
85
|
+
(0, class_validator_1.IsString)(),
|
|
86
|
+
__metadata("design:type", String)
|
|
87
|
+
], AccumKey.prototype, "z", void 0);
|
|
88
|
+
exports.AccumKey = AccumKey;
|
|
89
|
+
class PublicKeys {
|
|
90
|
+
}
|
|
91
|
+
__decorate([
|
|
92
|
+
(0, class_validator_1.ValidateNested)(),
|
|
93
|
+
(0, class_validator_1.IsInstance)(AccumKey),
|
|
94
|
+
(0, class_transformer_1.Type)(() => AccumKey),
|
|
95
|
+
__metadata("design:type", AccumKey)
|
|
96
|
+
], PublicKeys.prototype, "accumKey", void 0);
|
|
97
|
+
exports.PublicKeys = PublicKeys;
|
|
98
|
+
class CheqdRevocationRegistryDefinitionValue {
|
|
99
|
+
}
|
|
100
|
+
__decorate([
|
|
101
|
+
(0, class_validator_1.ValidateNested)(),
|
|
102
|
+
(0, class_validator_1.IsInstance)(PublicKeys),
|
|
103
|
+
(0, class_transformer_1.Type)(() => PublicKeys),
|
|
104
|
+
__metadata("design:type", PublicKeys)
|
|
105
|
+
], CheqdRevocationRegistryDefinitionValue.prototype, "publicKeys", void 0);
|
|
106
|
+
__decorate([
|
|
107
|
+
(0, class_validator_1.IsNumber)(),
|
|
108
|
+
__metadata("design:type", Number)
|
|
109
|
+
], CheqdRevocationRegistryDefinitionValue.prototype, "maxCredNum", void 0);
|
|
110
|
+
__decorate([
|
|
111
|
+
(0, class_validator_1.IsString)(),
|
|
112
|
+
__metadata("design:type", String)
|
|
113
|
+
], CheqdRevocationRegistryDefinitionValue.prototype, "tailsLocation", void 0);
|
|
114
|
+
__decorate([
|
|
115
|
+
(0, class_validator_1.IsString)(),
|
|
116
|
+
__metadata("design:type", String)
|
|
117
|
+
], CheqdRevocationRegistryDefinitionValue.prototype, "tailsHash", void 0);
|
|
118
|
+
exports.CheqdRevocationRegistryDefinitionValue = CheqdRevocationRegistryDefinitionValue;
|
|
119
|
+
class CheqdRevocationRegistryDefinition {
|
|
120
|
+
constructor(options) {
|
|
121
|
+
if (options) {
|
|
122
|
+
this.revocDefType = options.revocDefType;
|
|
123
|
+
this.credDefId = options.credDefId;
|
|
124
|
+
this.tag = options.tag;
|
|
125
|
+
this.value = options.value;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
__decorate([
|
|
130
|
+
(0, class_validator_1.Contains)('CL_ACCUM'),
|
|
131
|
+
__metadata("design:type", String)
|
|
132
|
+
], CheqdRevocationRegistryDefinition.prototype, "revocDefType", void 0);
|
|
133
|
+
__decorate([
|
|
134
|
+
(0, class_validator_1.IsString)(),
|
|
135
|
+
__metadata("design:type", String)
|
|
136
|
+
], CheqdRevocationRegistryDefinition.prototype, "credDefId", void 0);
|
|
137
|
+
__decorate([
|
|
138
|
+
(0, class_validator_1.IsString)(),
|
|
139
|
+
__metadata("design:type", String)
|
|
140
|
+
], CheqdRevocationRegistryDefinition.prototype, "tag", void 0);
|
|
141
|
+
__decorate([
|
|
142
|
+
(0, class_validator_1.ValidateNested)(),
|
|
143
|
+
(0, class_validator_1.IsInstance)(CheqdRevocationRegistryDefinitionValue),
|
|
144
|
+
(0, class_transformer_1.Type)(() => CheqdRevocationRegistryDefinitionValue),
|
|
145
|
+
__metadata("design:type", CheqdRevocationRegistryDefinitionValue)
|
|
146
|
+
], CheqdRevocationRegistryDefinition.prototype, "value", void 0);
|
|
147
|
+
exports.CheqdRevocationRegistryDefinition = CheqdRevocationRegistryDefinition;
|
|
148
|
+
class CheqdRevocationStatusList {
|
|
149
|
+
constructor(options) {
|
|
150
|
+
if (options) {
|
|
151
|
+
this.revRegDefId = options.revRegDefId;
|
|
152
|
+
this.revocationList = options.revocationList;
|
|
153
|
+
this.currentAccumulator = options.currentAccumulator;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
__decorate([
|
|
158
|
+
(0, class_validator_1.IsString)(),
|
|
159
|
+
__metadata("design:type", String)
|
|
160
|
+
], CheqdRevocationStatusList.prototype, "revRegDefId", void 0);
|
|
161
|
+
__decorate([
|
|
162
|
+
(0, class_validator_1.IsNumber)({}, { each: true }),
|
|
163
|
+
__metadata("design:type", Array)
|
|
164
|
+
], CheqdRevocationStatusList.prototype, "revocationList", void 0);
|
|
165
|
+
__decorate([
|
|
166
|
+
(0, class_validator_1.IsString)(),
|
|
167
|
+
__metadata("design:type", String)
|
|
168
|
+
], CheqdRevocationStatusList.prototype, "currentAccumulator", void 0);
|
|
169
|
+
exports.CheqdRevocationStatusList = CheqdRevocationStatusList;
|
|
170
|
+
//# sourceMappingURL=transform.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transform.js","sourceRoot":"","sources":["../../../src/anoncreds/utils/transform.ts"],"names":[],"mappings":";AAAA,0DAA0D;AAC1D,2DAA2D;;;;;;;;;;;;AAS3D,yDAAwC;AACxC,qDAUwB;AAExB,MAAa,WAAW;IACtB,YAAmB,OAA0C;QAC3D,IAAI,OAAO,EAAE;YACX,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAA;YACxB,IAAI,CAAC,S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IAAI,CAAC,kBAAkB,GAAG,OAAO,CAAC,kBAAkB,CAAA;SACrD;IACH,CAAC;CAUF;AARC;IAAC,IAAA,0BAAQ,GAAE;;8DACgB;AAE3B;IAAC,IAAA,0BAAQ,EAAC,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;;iEACG;AAEhC;IAAC,IAAA,0BAAQ,GAAE;;qEACuB;AAhBpC,8DAiBC"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { CheqdNetwork, DidStdFee, TVerificationKey, VerificationMethods } from '@cheqd/sdk';
|
|
2
|
+
import type { AgentContext, DidRegistrar, DidCreateOptions, DidCreateResult, DidDeactivateResult, DidUpdateResult } from '@credo-ts/core';
|
|
3
|
+
import { MethodSpecificIdAlgo } from '@cheqd/sdk';
|
|
4
|
+
import { MsgCreateResourcePayload } from '@cheqd/ts-proto/cheqd/resource/v2';
|
|
5
|
+
import { DidDocument, Buffer } from '@credo-ts/core';
|
|
6
|
+
export declare class CheqdDidRegistrar implements DidRegistrar {
|
|
7
|
+
readonly supportedMethods: string[];
|
|
8
|
+
create(agentContext: AgentContext, options: CheqdDidCreateOptions): Promise<DidCreateResult>;
|
|
9
|
+
update(agentContext: AgentContext, options: CheqdDidUpdateOptions): Promise<DidUpdateResult>;
|
|
10
|
+
deactivate(agentContext: AgentContext, options: CheqdDidDeactivateOptions): Promise<DidDeactivateResult>;
|
|
11
|
+
createResource(agentContext: AgentContext, did: string, resource: CheqdCreateResourceOptions): Promise<{
|
|
12
|
+
resourceMetadata: {};
|
|
13
|
+
resourceRegistrationMetadata: {};
|
|
14
|
+
resourceState: {
|
|
15
|
+
state: string;
|
|
16
|
+
reason: string;
|
|
17
|
+
resourceId?: undefined;
|
|
18
|
+
resource?: undefined;
|
|
19
|
+
};
|
|
20
|
+
} | {
|
|
21
|
+
resourceMetadata: {};
|
|
22
|
+
resourceRegistrationMetadata: {};
|
|
23
|
+
resourceState: {
|
|
24
|
+
state: string;
|
|
25
|
+
resourceId: string;
|
|
26
|
+
resource: MsgCreateResourcePayload;
|
|
27
|
+
reason?: undefined;
|
|
28
|
+
};
|
|
29
|
+
}>;
|
|
30
|
+
private signPayload;
|
|
31
|
+
}
|
|
32
|
+
export interface CheqdDidCreateOptions extends DidCreateOptions {
|
|
33
|
+
method: 'cheqd';
|
|
34
|
+
options: {
|
|
35
|
+
network: `${CheqdNetwork}`;
|
|
36
|
+
fee?: DidStdFee;
|
|
37
|
+
versionId?: string;
|
|
38
|
+
methodSpecificIdAlgo?: `${MethodSpecificIdAlgo}`;
|
|
39
|
+
};
|
|
40
|
+
secret: {
|
|
41
|
+
verificationMethod?: IVerificationMethod;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export interface CheqdDidUpdateOptions extends DidCreateOptions {
|
|
45
|
+
method: 'cheqd';
|
|
46
|
+
did: string;
|
|
47
|
+
didDocument: DidDocument;
|
|
48
|
+
options: {
|
|
49
|
+
fee?: DidStdFee;
|
|
50
|
+
versionId?: string;
|
|
51
|
+
};
|
|
52
|
+
secret?: {
|
|
53
|
+
verificationMethod: IVerificationMethod;
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
export interface CheqdDidDeactivateOptions extends DidCreateOptions {
|
|
57
|
+
method: 'cheqd';
|
|
58
|
+
did: string;
|
|
59
|
+
options: {
|
|
60
|
+
fee?: DidStdFee;
|
|
61
|
+
versionId?: string;
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
export interface CheqdCreateResourceOptions extends Omit<Partial<MsgCreateResourcePayload>, 'data'> {
|
|
65
|
+
data: string | Uint8Array | object;
|
|
66
|
+
}
|
|
67
|
+
interface IVerificationMethod {
|
|
68
|
+
type: `${VerificationMethods}`;
|
|
69
|
+
id: TVerificationKey<string, number>;
|
|
70
|
+
privateKey?: Buffer;
|
|
71
|
+
}
|
|
72
|
+
export {};
|
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CheqdDidRegistrar = void 0;
|
|
4
|
+
const sdk_1 = require("@cheqd/sdk");
|
|
5
|
+
const v2_1 = require("@cheqd/ts-proto/cheqd/resource/v2");
|
|
6
|
+
const core_1 = require("@credo-ts/core");
|
|
7
|
+
const ledger_1 = require("../ledger");
|
|
8
|
+
const didCheqdUtil_1 = require("./didCheqdUtil");
|
|
9
|
+
class CheqdDidRegistrar {
|
|
10
|
+
constructor() {
|
|
11
|
+
this.supportedMethods = ['cheqd'];
|
|
12
|
+
}
|
|
13
|
+
async create(agentContext, options) {
|
|
14
|
+
var _a;
|
|
15
|
+
const didRepository = agentContext.dependencyManager.resolve(core_1.DidRepository);
|
|
16
|
+
const cheqdLedgerService = agentContext.dependencyManager.resolve(ledger_1.CheqdLedgerService);
|
|
17
|
+
const { methodSpecificIdAlgo, network, versionId = core_1.utils.uuid() } = options.options;
|
|
18
|
+
const verificationMethod = (_a = options.secret) === null || _a === void 0 ? void 0 : _a.verificationMethod;
|
|
19
|
+
let didDocument;
|
|
20
|
+
try {
|
|
21
|
+
if (options.didDocument && (0, didCheqdUtil_1.validateSpecCompliantPayload)(options.didDocument)) {
|
|
22
|
+
didDocument = options.didDocument;
|
|
23
|
+
}
|
|
24
|
+
else if (verificationMethod) {
|
|
25
|
+
const privateKey = verificationMethod.privateKey;
|
|
26
|
+
if (privateKey && !(0, core_1.isValidPrivateKey)(privateKey, core_1.KeyType.Ed25519)) {
|
|
27
|
+
return {
|
|
28
|
+
didDocumentMetadata: {},
|
|
29
|
+
didRegistrationMetadata: {},
|
|
30
|
+
didState: {
|
|
31
|
+
state: 'failed',
|
|
32
|
+
reason: 'Invalid private key provided',
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
const key = await agentContext.wallet.createKey({
|
|
37
|
+
keyType: core_1.KeyType.Ed25519,
|
|
38
|
+
privateKey: privateKey,
|
|
39
|
+
});
|
|
40
|
+
didDocument = (0, didCheqdUtil_1.generateDidDoc)({
|
|
41
|
+
verificationMethod: verificationMethod.type,
|
|
42
|
+
verificationMethodId: verificationMethod.id || 'key-1',
|
|
43
|
+
methodSpecificIdAlgo: methodSpecificIdAlgo || sdk_1.MethodSpecificIdAlgo.Uuid,
|
|
44
|
+
network: network,
|
|
45
|
+
publicKey: core_1.TypedArrayEncoder.toHex(key.publicKey),
|
|
46
|
+
});
|
|
47
|
+
const contextMapping = {
|
|
48
|
+
Ed25519VerificationKey2018: 'https://w3id.org/security/suites/ed25519-2018/v1',
|
|
49
|
+
Ed25519VerificationKey2020: 'https://w3id.org/security/suites/ed25519-2020/v1',
|
|
50
|
+
JsonWebKey2020: 'https://w3id.org/security/suites/jws-2020/v1',
|
|
51
|
+
};
|
|
52
|
+
const contextUrl = contextMapping[verificationMethod.type];
|
|
53
|
+
// Add the context to the did document
|
|
54
|
+
// NOTE: cheqd sdk uses https://www.w3.org/ns/did/v1 while Credo did doc uses https://w3id.org/did/v1
|
|
55
|
+
// We should align these at some point. For now we just return a consistent value.
|
|
56
|
+
didDocument.context = ['https://www.w3.org/ns/did/v1', contextUrl];
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
return {
|
|
60
|
+
didDocumentMetadata: {},
|
|
61
|
+
didRegistrationMetadata: {},
|
|
62
|
+
didState: {
|
|
63
|
+
state: 'failed',
|
|
64
|
+
reason: 'Provide a didDocument or at least one verificationMethod with seed in secret',
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
const didDocumentJson = didDocument.toJSON();
|
|
69
|
+
const payloadToSign = await (0, didCheqdUtil_1.createMsgCreateDidDocPayloadToSign)(didDocumentJson, versionId);
|
|
70
|
+
const signInputs = await this.signPayload(agentContext, payloadToSign, didDocument.verificationMethod);
|
|
71
|
+
const response = await cheqdLedgerService.create(didDocumentJson, signInputs, versionId);
|
|
72
|
+
if (response.code !== 0) {
|
|
73
|
+
throw new Error(`${response.rawLog}`);
|
|
74
|
+
}
|
|
75
|
+
// Save the did so we know we created it and can issue with it
|
|
76
|
+
const didRecord = new core_1.DidRecord({
|
|
77
|
+
did: didDocument.id,
|
|
78
|
+
role: core_1.DidDocumentRole.Created,
|
|
79
|
+
didDocument,
|
|
80
|
+
});
|
|
81
|
+
await didRepository.save(agentContext, didRecord);
|
|
82
|
+
return {
|
|
83
|
+
didDocumentMetadata: {},
|
|
84
|
+
didRegistrationMetadata: {},
|
|
85
|
+
didState: {
|
|
86
|
+
state: 'finished',
|
|
87
|
+
did: didDocument.id,
|
|
88
|
+
didDocument,
|
|
89
|
+
secret: options.secret,
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
agentContext.config.logger.error(`Error registering DID`, error);
|
|
95
|
+
return {
|
|
96
|
+
didDocumentMetadata: {},
|
|
97
|
+
didRegistrationMetadata: {},
|
|
98
|
+
didState: {
|
|
99
|
+
state: 'failed',
|
|
100
|
+
reason: `unknownError: ${error.message}`,
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
async update(agentContext, options) {
|
|
106
|
+
var _a, _b, _c;
|
|
107
|
+
const didRepository = agentContext.dependencyManager.resolve(core_1.DidRepository);
|
|
108
|
+
const cheqdLedgerService = agentContext.dependencyManager.resolve(ledger_1.CheqdLedgerService);
|
|
109
|
+
const versionId = ((_a = options.options) === null || _a === void 0 ? void 0 : _a.versionId) || core_1.utils.uuid();
|
|
110
|
+
const verificationMethod = (_b = options.secret) === null || _b === void 0 ? void 0 : _b.verificationMethod;
|
|
111
|
+
let didDocument;
|
|
112
|
+
let didRecord;
|
|
113
|
+
try {
|
|
114
|
+
if (options.didDocument && (0, didCheqdUtil_1.validateSpecCompliantPayload)(options.didDocument)) {
|
|
115
|
+
didDocument = options.didDocument;
|
|
116
|
+
const resolvedDocument = await cheqdLedgerService.resolve(didDocument.id);
|
|
117
|
+
didRecord = await didRepository.findCreatedDid(agentContext, didDocument.id);
|
|
118
|
+
if (!resolvedDocument.didDocument || resolvedDocument.didDocumentMetadata.deactivated || !didRecord) {
|
|
119
|
+
return {
|
|
120
|
+
didDocumentMetadata: {},
|
|
121
|
+
didRegistrationMetadata: {},
|
|
122
|
+
didState: {
|
|
123
|
+
state: 'failed',
|
|
124
|
+
reason: 'Did not found',
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
if (verificationMethod) {
|
|
129
|
+
const privateKey = verificationMethod.privateKey;
|
|
130
|
+
if (privateKey && !(0, core_1.isValidPrivateKey)(privateKey, core_1.KeyType.Ed25519)) {
|
|
131
|
+
return {
|
|
132
|
+
didDocumentMetadata: {},
|
|
133
|
+
didRegistrationMetadata: {},
|
|
134
|
+
didState: {
|
|
135
|
+
state: 'failed',
|
|
136
|
+
reason: 'Invalid private key provided',
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
const key = await agentContext.wallet.createKey({
|
|
141
|
+
keyType: core_1.KeyType.Ed25519,
|
|
142
|
+
privateKey: privateKey,
|
|
143
|
+
});
|
|
144
|
+
(_c = didDocument.verificationMethod) === null || _c === void 0 ? void 0 : _c.concat(core_1.JsonTransformer.fromJSON((0, sdk_1.createDidVerificationMethod)([verificationMethod.type], [
|
|
145
|
+
{
|
|
146
|
+
methodSpecificId: didDocument.id.split(':')[3],
|
|
147
|
+
didUrl: didDocument.id,
|
|
148
|
+
keyId: `${didDocument.id}#${verificationMethod.id}`,
|
|
149
|
+
publicKey: core_1.TypedArrayEncoder.toHex(key.publicKey),
|
|
150
|
+
},
|
|
151
|
+
]), core_1.VerificationMethod));
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
return {
|
|
156
|
+
didDocumentMetadata: {},
|
|
157
|
+
didRegistrationMetadata: {},
|
|
158
|
+
didState: {
|
|
159
|
+
state: 'failed',
|
|
160
|
+
reason: 'Provide a valid didDocument',
|
|
161
|
+
},
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
const payloadToSign = await (0, didCheqdUtil_1.createMsgCreateDidDocPayloadToSign)(didDocument, versionId);
|
|
165
|
+
const signInputs = await this.signPayload(agentContext, payloadToSign, didDocument.verificationMethod);
|
|
166
|
+
const response = await cheqdLedgerService.update(didDocument, signInputs, versionId);
|
|
167
|
+
if (response.code !== 0) {
|
|
168
|
+
throw new Error(`${response.rawLog}`);
|
|
169
|
+
}
|
|
170
|
+
// Save the did so we know we created it and can issue with it
|
|
171
|
+
didRecord.didDocument = didDocument;
|
|
172
|
+
await didRepository.update(agentContext, didRecord);
|
|
173
|
+
return {
|
|
174
|
+
didDocumentMetadata: {},
|
|
175
|
+
didRegistrationMetadata: {},
|
|
176
|
+
didState: {
|
|
177
|
+
state: 'finished',
|
|
178
|
+
did: didDocument.id,
|
|
179
|
+
didDocument,
|
|
180
|
+
secret: options.secret,
|
|
181
|
+
},
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
catch (error) {
|
|
185
|
+
agentContext.config.logger.error(`Error updating DID`, error);
|
|
186
|
+
return {
|
|
187
|
+
didDocumentMetadata: {},
|
|
188
|
+
didRegistrationMetadata: {},
|
|
189
|
+
didState: {
|
|
190
|
+
state: 'failed',
|
|
191
|
+
reason: `unknownError: ${error.message}`,
|
|
192
|
+
},
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
async deactivate(agentContext, options) {
|
|
197
|
+
var _a;
|
|
198
|
+
const didRepository = agentContext.dependencyManager.resolve(core_1.DidRepository);
|
|
199
|
+
const cheqdLedgerService = agentContext.dependencyManager.resolve(ledger_1.CheqdLedgerService);
|
|
200
|
+
const did = options.did;
|
|
201
|
+
const versionId = ((_a = options.options) === null || _a === void 0 ? void 0 : _a.versionId) || core_1.utils.uuid();
|
|
202
|
+
try {
|
|
203
|
+
const { didDocument, didDocumentMetadata } = await cheqdLedgerService.resolve(did);
|
|
204
|
+
const didRecord = await didRepository.findCreatedDid(agentContext, did);
|
|
205
|
+
if (!didDocument || didDocumentMetadata.deactivated || !didRecord) {
|
|
206
|
+
return {
|
|
207
|
+
didDocumentMetadata: {},
|
|
208
|
+
didRegistrationMetadata: {},
|
|
209
|
+
didState: {
|
|
210
|
+
state: 'failed',
|
|
211
|
+
reason: 'Did not found',
|
|
212
|
+
},
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
const payloadToSign = (0, didCheqdUtil_1.createMsgDeactivateDidDocPayloadToSign)(didDocument, versionId);
|
|
216
|
+
const didDocumentInstance = core_1.JsonTransformer.fromJSON(didDocument, core_1.DidDocument);
|
|
217
|
+
const signInputs = await this.signPayload(agentContext, payloadToSign, didDocumentInstance.verificationMethod);
|
|
218
|
+
const response = await cheqdLedgerService.deactivate(didDocument, signInputs, versionId);
|
|
219
|
+
if (response.code !== 0) {
|
|
220
|
+
throw new Error(`${response.rawLog}`);
|
|
221
|
+
}
|
|
222
|
+
await didRepository.update(agentContext, didRecord);
|
|
223
|
+
return {
|
|
224
|
+
didDocumentMetadata: {},
|
|
225
|
+
didRegistrationMetadata: {},
|
|
226
|
+
didState: {
|
|
227
|
+
state: 'finished',
|
|
228
|
+
did: didDocument.id,
|
|
229
|
+
didDocument: core_1.JsonTransformer.fromJSON(didDocument, core_1.DidDocument),
|
|
230
|
+
secret: options.secret,
|
|
231
|
+
},
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
catch (error) {
|
|
235
|
+
agentContext.config.logger.error(`Error deactivating DID`, error);
|
|
236
|
+
return {
|
|
237
|
+
didDocumentMetadata: {},
|
|
238
|
+
didRegistrationMetadata: {},
|
|
239
|
+
didState: {
|
|
240
|
+
state: 'failed',
|
|
241
|
+
reason: `unknownError: ${error.message}`,
|
|
242
|
+
},
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
async createResource(agentContext, did, resource) {
|
|
247
|
+
const didRepository = agentContext.dependencyManager.resolve(core_1.DidRepository);
|
|
248
|
+
const cheqdLedgerService = agentContext.dependencyManager.resolve(ledger_1.CheqdLedgerService);
|
|
249
|
+
const { didDocument, didDocumentMetadata } = await cheqdLedgerService.resolve(did);
|
|
250
|
+
const didRecord = await didRepository.findCreatedDid(agentContext, did);
|
|
251
|
+
if (!didDocument || didDocumentMetadata.deactivated || !didRecord) {
|
|
252
|
+
return {
|
|
253
|
+
resourceMetadata: {},
|
|
254
|
+
resourceRegistrationMetadata: {},
|
|
255
|
+
resourceState: {
|
|
256
|
+
state: 'failed',
|
|
257
|
+
reason: `DID: ${did} not found`,
|
|
258
|
+
},
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
try {
|
|
262
|
+
let data;
|
|
263
|
+
if (typeof resource.data === 'string') {
|
|
264
|
+
data = core_1.TypedArrayEncoder.fromBase64(resource.data);
|
|
265
|
+
}
|
|
266
|
+
else if (typeof resource.data == 'object') {
|
|
267
|
+
data = core_1.TypedArrayEncoder.fromString(JSON.stringify(resource.data));
|
|
268
|
+
}
|
|
269
|
+
else {
|
|
270
|
+
data = resource.data;
|
|
271
|
+
}
|
|
272
|
+
const resourcePayload = v2_1.MsgCreateResourcePayload.fromPartial({
|
|
273
|
+
collectionId: did.split(':')[3],
|
|
274
|
+
id: resource.id,
|
|
275
|
+
resourceType: resource.resourceType,
|
|
276
|
+
name: resource.name,
|
|
277
|
+
version: resource.version,
|
|
278
|
+
alsoKnownAs: resource.alsoKnownAs,
|
|
279
|
+
data,
|
|
280
|
+
});
|
|
281
|
+
const payloadToSign = v2_1.MsgCreateResourcePayload.encode(resourcePayload).finish();
|
|
282
|
+
const didDocumentInstance = core_1.JsonTransformer.fromJSON(didDocument, core_1.DidDocument);
|
|
283
|
+
const signInputs = await this.signPayload(agentContext, payloadToSign, didDocumentInstance.verificationMethod);
|
|
284
|
+
const response = await cheqdLedgerService.createResource(did, resourcePayload, signInputs);
|
|
285
|
+
if (response.code !== 0) {
|
|
286
|
+
throw new Error(`${response.rawLog}`);
|
|
287
|
+
}
|
|
288
|
+
return {
|
|
289
|
+
resourceMetadata: {},
|
|
290
|
+
resourceRegistrationMetadata: {},
|
|
291
|
+
resourceState: {
|
|
292
|
+
state: 'finished',
|
|
293
|
+
resourceId: resourcePayload.id,
|
|
294
|
+
resource: resourcePayload,
|
|
295
|
+
},
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
catch (error) {
|
|
299
|
+
return {
|
|
300
|
+
resourceMetadata: {},
|
|
301
|
+
resourceRegistrationMetadata: {},
|
|
302
|
+
resourceState: {
|
|
303
|
+
state: 'failed',
|
|
304
|
+
reason: `unknownError: ${error.message}`,
|
|
305
|
+
},
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
async signPayload(agentContext, payload, verificationMethod = []) {
|
|
310
|
+
return await Promise.all(verificationMethod.map(async (method) => {
|
|
311
|
+
const key = (0, core_1.getKeyFromVerificationMethod)(method);
|
|
312
|
+
return {
|
|
313
|
+
verificationMethodId: method.id,
|
|
314
|
+
signature: await agentContext.wallet.sign({ data: core_1.Buffer.from(payload), key }),
|
|
315
|
+
};
|
|
316
|
+
}));
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
exports.CheqdDidRegistrar = CheqdDidRegistrar;
|
|
320
|
+
//# sourceMappingURL=CheqdDidRegistrar.js.map
|