@credo-ts/hedera 0.5.18-alpha-20251007144852
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/HederaModule.d.ts +8 -0
- package/build/HederaModule.js +26 -0
- package/build/HederaModule.js.map +1 -0
- package/build/HederaModuleConfig.d.ts +9 -0
- package/build/HederaModuleConfig.js +10 -0
- package/build/HederaModuleConfig.js.map +1 -0
- package/build/anoncreds/HederaAnonCredsRegistry.d.ts +14 -0
- package/build/anoncreds/HederaAnonCredsRegistry.js +187 -0
- package/build/anoncreds/HederaAnonCredsRegistry.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/dids/HederaDidRegistrar.d.ts +8 -0
- package/build/dids/HederaDidRegistrar.js +134 -0
- package/build/dids/HederaDidRegistrar.js.map +1 -0
- package/build/dids/HederaDidResolver.d.ts +7 -0
- package/build/dids/HederaDidResolver.js +45 -0
- package/build/dids/HederaDidResolver.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 +22 -0
- package/build/index.js.map +1 -0
- package/build/ledger/HederaLedgerService.d.ts +45 -0
- package/build/ledger/HederaLedgerService.js +337 -0
- package/build/ledger/HederaLedgerService.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/build/ledger/publisher/CredoPublisher.d.ts +12 -0
- package/build/ledger/publisher/CredoPublisher.js +31 -0
- package/build/ledger/publisher/CredoPublisher.js.map +1 -0
- package/build/ledger/signer/CredoSigner.d.ts +12 -0
- package/build/ledger/signer/CredoSigner.js +36 -0
- package/build/ledger/signer/CredoSigner.js.map +1 -0
- package/build/ledger/utils/index.d.ts +5 -0
- package/build/ledger/utils/index.js +18 -0
- package/build/ledger/utils/index.js.map +1 -0
- package/package.json +45 -0
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HederaDidRegistrar = void 0;
|
|
4
|
+
const core_1 = require("@credo-ts/core");
|
|
5
|
+
const ledger_1 = require("../ledger");
|
|
6
|
+
class HederaDidRegistrar {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.supportedMethods = ['hedera'];
|
|
9
|
+
}
|
|
10
|
+
async create(agentContext, options) {
|
|
11
|
+
try {
|
|
12
|
+
const didRepository = agentContext.dependencyManager.resolve(core_1.DidRepository);
|
|
13
|
+
const ledgerService = agentContext.dependencyManager.resolve(ledger_1.HederaLedgerService);
|
|
14
|
+
const { did, didDocument } = await ledgerService.createDid(agentContext, options);
|
|
15
|
+
const credoDidDocument = new core_1.DidDocument({
|
|
16
|
+
...didDocument,
|
|
17
|
+
service: didDocument.service?.map((s) => new core_1.DidDocumentService(s)),
|
|
18
|
+
});
|
|
19
|
+
await didRepository.save(agentContext, new core_1.DidRecord({
|
|
20
|
+
did,
|
|
21
|
+
role: core_1.DidDocumentRole.Created,
|
|
22
|
+
didDocument: credoDidDocument,
|
|
23
|
+
}));
|
|
24
|
+
return {
|
|
25
|
+
didDocumentMetadata: {},
|
|
26
|
+
didRegistrationMetadata: {},
|
|
27
|
+
didState: {
|
|
28
|
+
state: 'finished',
|
|
29
|
+
did,
|
|
30
|
+
didDocument: credoDidDocument,
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
agentContext.config.logger.debug('Error creating DID', {
|
|
36
|
+
error,
|
|
37
|
+
});
|
|
38
|
+
return {
|
|
39
|
+
didDocumentMetadata: {},
|
|
40
|
+
didRegistrationMetadata: {},
|
|
41
|
+
didState: {
|
|
42
|
+
state: 'failed',
|
|
43
|
+
reason: `Unable to register Did: ${error.message}`,
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
async update(agentContext, options) {
|
|
49
|
+
const didRepository = agentContext.dependencyManager.resolve(core_1.DidRepository);
|
|
50
|
+
const ledgerService = agentContext.dependencyManager.resolve(ledger_1.HederaLedgerService);
|
|
51
|
+
try {
|
|
52
|
+
const { did } = options;
|
|
53
|
+
const { didDocument, didDocumentMetadata } = await ledgerService.resolveDid(agentContext, did);
|
|
54
|
+
const didRecord = await didRepository.findCreatedDid(agentContext, did);
|
|
55
|
+
if (!didDocument || didDocumentMetadata.deactivated || !didRecord) {
|
|
56
|
+
return {
|
|
57
|
+
didDocumentMetadata: {},
|
|
58
|
+
didRegistrationMetadata: {},
|
|
59
|
+
didState: {
|
|
60
|
+
state: 'failed',
|
|
61
|
+
reason: 'Did not found',
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
const { didDocument: updatedDidDocument } = await ledgerService.updateDid(agentContext, options);
|
|
66
|
+
didRecord.didDocument = core_1.JsonTransformer.fromJSON(updatedDidDocument, core_1.DidDocument);
|
|
67
|
+
await didRepository.update(agentContext, didRecord);
|
|
68
|
+
return {
|
|
69
|
+
didDocumentMetadata: {},
|
|
70
|
+
didRegistrationMetadata: {},
|
|
71
|
+
didState: {
|
|
72
|
+
state: 'finished',
|
|
73
|
+
did,
|
|
74
|
+
didDocument: didRecord.didDocument,
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
agentContext.config.logger.error('Error updating DID', error);
|
|
80
|
+
return {
|
|
81
|
+
didDocumentMetadata: {},
|
|
82
|
+
didRegistrationMetadata: {},
|
|
83
|
+
didState: {
|
|
84
|
+
state: 'failed',
|
|
85
|
+
reason: `Unable update DID: ${error.message}`,
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
async deactivate(agentContext, options) {
|
|
91
|
+
const didRepository = agentContext.dependencyManager.resolve(core_1.DidRepository);
|
|
92
|
+
const ledgerService = agentContext.dependencyManager.resolve(ledger_1.HederaLedgerService);
|
|
93
|
+
const did = options.did;
|
|
94
|
+
try {
|
|
95
|
+
const { didDocument, didDocumentMetadata } = await ledgerService.resolveDid(agentContext, did);
|
|
96
|
+
const didRecord = await didRepository.findCreatedDid(agentContext, did);
|
|
97
|
+
if (!didDocument || didDocumentMetadata.deactivated || !didRecord) {
|
|
98
|
+
return {
|
|
99
|
+
didDocumentMetadata,
|
|
100
|
+
didRegistrationMetadata: {},
|
|
101
|
+
didState: {
|
|
102
|
+
state: 'failed',
|
|
103
|
+
reason: 'Did not found',
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
const { didDocument: deactivatedDidDocument } = await ledgerService.deactivateDid(agentContext, options);
|
|
108
|
+
didRecord.didDocument = core_1.JsonTransformer.fromJSON(deactivatedDidDocument, core_1.DidDocument);
|
|
109
|
+
await didRepository.update(agentContext, didRecord);
|
|
110
|
+
return {
|
|
111
|
+
didDocumentMetadata: {},
|
|
112
|
+
didRegistrationMetadata: {},
|
|
113
|
+
didState: {
|
|
114
|
+
state: 'finished',
|
|
115
|
+
did,
|
|
116
|
+
didDocument: didRecord.didDocument,
|
|
117
|
+
},
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
agentContext.config.logger.error('Error deactivating DID', error);
|
|
122
|
+
return {
|
|
123
|
+
didDocumentMetadata: {},
|
|
124
|
+
didRegistrationMetadata: {},
|
|
125
|
+
didState: {
|
|
126
|
+
state: 'failed',
|
|
127
|
+
reason: `Unable deactivating DID: ${error.message}`,
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
exports.HederaDidRegistrar = HederaDidRegistrar;
|
|
134
|
+
//# sourceMappingURL=HederaDidRegistrar.js.map
|
|
@@ -0,0 +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,EAAE,WAAW,EAAE,sBAAsB,EAAE,GAAG,MAAM,aAAa,CAAC,aAAa,CAAC,YAAY,EAAE,OAAO,CAAC,CAAA;YAExG,SAAS,CAAC,WAAW,GAAG,sBAAe,CAAC,QAAQ,CAAC,sBAAsB,EAAE,kBAAW,CAAC,CAAA;YACrF,MAAM,aAAa,CAAC,MAAM,CAAC,YAAY,EAAE,SAAS,CAAC,CAAA;YAEnD,OAAO;gBACL,mBAAmB,EAAE,EAAE;gBACvB,uBAAuB,EAAE,EAAE;gBAC3B,QAAQ,EAAE;oBACR,KAAK,EAAE,UAAU;oBACjB,GAAG;oBACH,WAAW,EAAE,SAAS,CAAC,WAAW;iBACnC;aACF,CAAA;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,YAAY,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,wBAAwB,EAAE,KAAK,CAAC,CAAA;YACjE,OAAO;gBACL,mBAAmB,EAAE,EAAE;gBACvB,uBAAuB,EAAE,EAAE;gBAC3B,QAAQ,EAAE;oBACR,KAAK,EAAE,QAAQ;oBACf,MAAM,EAAE,4BAA4B,KAAK,CAAC,OAAO,EAAE;iBACpD;aACF,CAAA;QACH,CAAC;IACH,CAAC;CACF;AA7ID,gDA6IC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type AgentContext, type DidResolutionOptions, type DidResolutionResult, type DidResolver, type ParsedDid } from '@credo-ts/core';
|
|
2
|
+
export declare class HederaDidResolver implements DidResolver {
|
|
3
|
+
readonly supportedMethods: string[];
|
|
4
|
+
readonly allowsCaching = true;
|
|
5
|
+
readonly allowsLocalDidRecord = true;
|
|
6
|
+
resolve(agentContext: AgentContext, did: string, _parsed: ParsedDid, _didResolutionOptions: DidResolutionOptions): Promise<DidResolutionResult>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HederaDidResolver = void 0;
|
|
4
|
+
const core_1 = require("@credo-ts/core");
|
|
5
|
+
const ledger_1 = require("../ledger");
|
|
6
|
+
class HederaDidResolver {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.supportedMethods = ['hedera'];
|
|
9
|
+
this.allowsCaching = true;
|
|
10
|
+
this.allowsLocalDidRecord = true;
|
|
11
|
+
}
|
|
12
|
+
async resolve(agentContext, did,
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
14
|
+
_parsed,
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
16
|
+
_didResolutionOptions) {
|
|
17
|
+
try {
|
|
18
|
+
agentContext.config.logger.trace('Try to resolve a did document from ledger');
|
|
19
|
+
const ledgerService = agentContext.dependencyManager.resolve(ledger_1.HederaLedgerService);
|
|
20
|
+
const resolveDidResult = await ledgerService.resolveDid(agentContext, did);
|
|
21
|
+
const didDocument = core_1.JsonTransformer.fromJSON(resolveDidResult.didDocument, core_1.DidDocument);
|
|
22
|
+
return {
|
|
23
|
+
didDocument,
|
|
24
|
+
didDocumentMetadata: resolveDidResult.didDocumentMetadata,
|
|
25
|
+
didResolutionMetadata: resolveDidResult.didResolutionMetadata,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
agentContext.config.logger.debug('Error resolving the did', {
|
|
30
|
+
error,
|
|
31
|
+
did,
|
|
32
|
+
});
|
|
33
|
+
return {
|
|
34
|
+
didDocument: null,
|
|
35
|
+
didDocumentMetadata: {},
|
|
36
|
+
didResolutionMetadata: {
|
|
37
|
+
error: 'notFound',
|
|
38
|
+
message: `Unable to resolve did '${did}': ${error}`,
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.HederaDidResolver = HederaDidResolver;
|
|
45
|
+
//# sourceMappingURL=HederaDidResolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|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CD,8CAsCC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HederaDidResolver = exports.HederaDidRegistrar = void 0;
|
|
4
|
+
var HederaDidRegistrar_1 = require("./HederaDidRegistrar");
|
|
5
|
+
Object.defineProperty(exports, "HederaDidRegistrar", { enumerable: true, get: function () { return HederaDidRegistrar_1.HederaDidRegistrar; } });
|
|
6
|
+
var HederaDidResolver_1 = require("./HederaDidResolver");
|
|
7
|
+
Object.defineProperty(exports, "HederaDidResolver", { enumerable: true, get: function () { return HederaDidResolver_1.HederaDidResolver; } });
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/dids/index.ts"],"names":[],"mappings":";;;AAAA,2DAAyD;AAAhD,wHAAA,kBAAkB,OAAA;AAC3B,yDAAuD;AAA9C,sHAAA,iBAAiB,OAAA"}
|
package/build/index.d.ts
ADDED
package/build/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./anoncreds"), exports);
|
|
18
|
+
__exportStar(require("./dids"), exports);
|
|
19
|
+
__exportStar(require("./ledger"), exports);
|
|
20
|
+
__exportStar(require("./HederaModule"), exports);
|
|
21
|
+
__exportStar(require("./HederaModuleConfig"), exports);
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA2B;AAC3B,yCAAsB;AACtB,2CAAwB;AACxB,iDAA8B;AAC9B,uDAAoC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { GetCredentialDefinitionReturn, GetRevocationRegistryDefinitionReturn, GetRevocationStatusListReturn, GetSchemaReturn, RegisterCredentialDefinitionOptions, RegisterCredentialDefinitionReturn, RegisterRevocationRegistryDefinitionOptions, RegisterRevocationRegistryDefinitionReturn, RegisterRevocationStatusListOptions, RegisterRevocationStatusListReturn, RegisterSchemaOptions, RegisterSchemaReturn } from '@credo-ts/anoncreds';
|
|
2
|
+
import { type AgentContext, Buffer, DidCreateOptions, DidDeactivateOptions, DidUpdateOptions, Key } from '@credo-ts/core';
|
|
3
|
+
import { HederaNetwork } from '@hiero-did-sdk/client';
|
|
4
|
+
import { DIDResolution } from '@hiero-did-sdk/core';
|
|
5
|
+
import { CreateDIDResult, DeactivateDIDResult, UpdateDIDResult } from '@hiero-did-sdk/registrar';
|
|
6
|
+
import { HederaModuleConfig } from '../HederaModuleConfig';
|
|
7
|
+
export interface HederaDidCreateOptions extends DidCreateOptions {
|
|
8
|
+
method: 'hedera';
|
|
9
|
+
options?: {
|
|
10
|
+
network?: HederaNetwork | string;
|
|
11
|
+
};
|
|
12
|
+
secret?: {
|
|
13
|
+
privateKey?: Buffer;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export interface HederaCreateDidResult extends CreateDIDResult {
|
|
17
|
+
rootKey: Key;
|
|
18
|
+
}
|
|
19
|
+
export declare class HederaLedgerService {
|
|
20
|
+
private readonly config;
|
|
21
|
+
private readonly clientService;
|
|
22
|
+
private readonly cache;
|
|
23
|
+
constructor(config: HederaModuleConfig);
|
|
24
|
+
resolveDid(agentContext: AgentContext, did: string): Promise<DIDResolution>;
|
|
25
|
+
createDid(agentContext: AgentContext, props: HederaDidCreateOptions): Promise<HederaCreateDidResult>;
|
|
26
|
+
updateDid(agentContext: AgentContext, props: DidUpdateOptions): Promise<UpdateDIDResult>;
|
|
27
|
+
deactivateDid(agentContext: AgentContext, props: DidDeactivateOptions): Promise<DeactivateDIDResult>;
|
|
28
|
+
getSchema(agentContext: AgentContext, schemaId: string): Promise<GetSchemaReturn>;
|
|
29
|
+
registerSchema(agentContext: AgentContext, options: RegisterSchemaOptions): Promise<RegisterSchemaReturn>;
|
|
30
|
+
getCredentialDefinition(agentContext: AgentContext, credentialDefinitionId: string): Promise<GetCredentialDefinitionReturn>;
|
|
31
|
+
registerCredentialDefinition(agentContext: AgentContext, options: RegisterCredentialDefinitionOptions): Promise<RegisterCredentialDefinitionReturn>;
|
|
32
|
+
getRevocationRegistryDefinition(agentContext: AgentContext, revocationRegistryDefinitionId: string): Promise<GetRevocationRegistryDefinitionReturn>;
|
|
33
|
+
registerRevocationRegistryDefinition(agentContext: AgentContext, options: RegisterRevocationRegistryDefinitionOptions): Promise<RegisterRevocationRegistryDefinitionReturn>;
|
|
34
|
+
getRevocationStatusList(agentContext: AgentContext, revocationRegistryId: string, timestamp: number): Promise<GetRevocationStatusListReturn>;
|
|
35
|
+
registerRevocationStatusList(agentContext: AgentContext, options: RegisterRevocationStatusListOptions): Promise<RegisterRevocationStatusListReturn>;
|
|
36
|
+
private getHederaHcsTopicReader;
|
|
37
|
+
private getPublisher;
|
|
38
|
+
private getHederaAnonCredsRegistry;
|
|
39
|
+
private getDidDocumentEntryId;
|
|
40
|
+
private getDidDocumentPropertyDiff;
|
|
41
|
+
private signRequests;
|
|
42
|
+
private prepareDidUpdates;
|
|
43
|
+
private getUpdateMethod;
|
|
44
|
+
private getIssuerKeySigner;
|
|
45
|
+
}
|
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
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;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.HederaLedgerService = void 0;
|
|
13
|
+
const core_1 = require("@credo-ts/core");
|
|
14
|
+
const anoncreds_1 = require("@hiero-did-sdk/anoncreds");
|
|
15
|
+
const cache_1 = require("@hiero-did-sdk/cache");
|
|
16
|
+
const client_1 = require("@hiero-did-sdk/client");
|
|
17
|
+
const core_2 = require("@hiero-did-sdk/core");
|
|
18
|
+
const registrar_1 = require("@hiero-did-sdk/registrar");
|
|
19
|
+
const resolver_1 = require("@hiero-did-sdk/resolver");
|
|
20
|
+
const HederaModuleConfig_1 = require("../HederaModuleConfig");
|
|
21
|
+
const CredoPublisher_1 = require("./publisher/CredoPublisher");
|
|
22
|
+
const CredoSigner_1 = require("./signer/CredoSigner");
|
|
23
|
+
const utils_1 = require("./utils");
|
|
24
|
+
let HederaLedgerService = class HederaLedgerService {
|
|
25
|
+
constructor(config) {
|
|
26
|
+
this.config = config;
|
|
27
|
+
this.clientService = new client_1.HederaClientService(config.options);
|
|
28
|
+
this.cache = this.config.options.cache ?? new cache_1.LRUMemoryCache(50);
|
|
29
|
+
}
|
|
30
|
+
async resolveDid(agentContext, did) {
|
|
31
|
+
const topicReader = this.getHederaHcsTopicReader(agentContext);
|
|
32
|
+
return await (0, resolver_1.resolveDID)(did, 'application/ld+json;profile="https://w3id.org/did-resolution"', { topicReader });
|
|
33
|
+
}
|
|
34
|
+
async createDid(agentContext, props) {
|
|
35
|
+
const { options, secret, didDocument } = props;
|
|
36
|
+
return this.clientService.withClient({ networkName: options?.network }, async (client) => {
|
|
37
|
+
const topicReader = this.getHederaHcsTopicReader(agentContext);
|
|
38
|
+
const controller = typeof didDocument?.controller === 'string'
|
|
39
|
+
? didDocument?.controller
|
|
40
|
+
: Array.isArray(didDocument?.controller)
|
|
41
|
+
? didDocument?.controller[0]
|
|
42
|
+
: undefined;
|
|
43
|
+
if (secret?.privateKey && !(0, core_1.isValidPrivateKey)(secret.privateKey, core_1.KeyType.Ed25519)) {
|
|
44
|
+
throw new Error('Unsupported private key provided');
|
|
45
|
+
}
|
|
46
|
+
const rootKey = await agentContext.wallet.createKey({ keyType: core_1.KeyType.Ed25519, privateKey: secret?.privateKey });
|
|
47
|
+
const publisher = await this.getPublisher(agentContext, client, rootKey);
|
|
48
|
+
const { state, signingRequest } = await (0, registrar_1.generateCreateDIDRequest)({
|
|
49
|
+
controller,
|
|
50
|
+
multibasePublicKey: rootKey.fingerprint,
|
|
51
|
+
topicReader,
|
|
52
|
+
}, {
|
|
53
|
+
client,
|
|
54
|
+
publisher,
|
|
55
|
+
});
|
|
56
|
+
const signature = await agentContext.wallet.sign({
|
|
57
|
+
key: rootKey,
|
|
58
|
+
data: core_1.Buffer.from(signingRequest.serializedPayload),
|
|
59
|
+
});
|
|
60
|
+
const createDidDocumentResult = await (0, registrar_1.submitCreateDIDRequest)({ state, signature, topicReader }, {
|
|
61
|
+
client,
|
|
62
|
+
publisher,
|
|
63
|
+
});
|
|
64
|
+
if (didDocument) {
|
|
65
|
+
const updateDidDocumentResult = await this.updateDid(agentContext, {
|
|
66
|
+
did: createDidDocumentResult.did,
|
|
67
|
+
didDocumentOperation: 'setDidDocument',
|
|
68
|
+
didDocument,
|
|
69
|
+
options: { ...options },
|
|
70
|
+
});
|
|
71
|
+
return {
|
|
72
|
+
...updateDidDocumentResult,
|
|
73
|
+
rootKey,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
...createDidDocumentResult,
|
|
78
|
+
rootKey,
|
|
79
|
+
};
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
async updateDid(agentContext, props) {
|
|
83
|
+
const { did, didDocumentOperation, didDocument } = props;
|
|
84
|
+
if (!didDocumentOperation) {
|
|
85
|
+
throw new Error('DidDocumentOperation is required');
|
|
86
|
+
}
|
|
87
|
+
const { network: networkName } = (0, core_2.parseDID)(did);
|
|
88
|
+
return this.clientService.withClient({ networkName }, async (client) => {
|
|
89
|
+
const topicReader = this.getHederaHcsTopicReader(agentContext);
|
|
90
|
+
const { didDocument: currentResolvedDidDocument } = await (0, resolver_1.resolveDID)(did, 'application/ld+json;profile="https://w3id.org/did-resolution"', { topicReader });
|
|
91
|
+
if (!currentResolvedDidDocument) {
|
|
92
|
+
throw new Error(`DID ${did} not found`);
|
|
93
|
+
}
|
|
94
|
+
const rootKey = (0, utils_1.getRootKeyForHederaDid)(currentResolvedDidDocument);
|
|
95
|
+
const currentCredoDidDocument = new core_1.DidDocument({
|
|
96
|
+
...currentResolvedDidDocument,
|
|
97
|
+
service: currentResolvedDidDocument.service?.map((s) => new core_1.DidDocumentService(s)),
|
|
98
|
+
});
|
|
99
|
+
const didUpdates = this.prepareDidUpdates(currentCredoDidDocument, didDocument, didDocumentOperation);
|
|
100
|
+
const publisher = await this.getPublisher(agentContext, client, rootKey);
|
|
101
|
+
const { states, signingRequests } = await (0, registrar_1.generateUpdateDIDRequest)({
|
|
102
|
+
did,
|
|
103
|
+
updates: didUpdates.build(),
|
|
104
|
+
topicReader,
|
|
105
|
+
}, {
|
|
106
|
+
client,
|
|
107
|
+
publisher,
|
|
108
|
+
});
|
|
109
|
+
const signatures = await this.signRequests(signingRequests, agentContext.wallet, rootKey);
|
|
110
|
+
return await (0, registrar_1.submitUpdateDIDRequest)({
|
|
111
|
+
states,
|
|
112
|
+
signatures,
|
|
113
|
+
topicReader,
|
|
114
|
+
}, {
|
|
115
|
+
client,
|
|
116
|
+
publisher,
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
async deactivateDid(agentContext, props) {
|
|
121
|
+
const { did } = props;
|
|
122
|
+
const didRepository = agentContext.dependencyManager.resolve(core_1.DidRepository);
|
|
123
|
+
const didRecord = await didRepository.findCreatedDid(agentContext, did);
|
|
124
|
+
if (!didRecord?.didDocument) {
|
|
125
|
+
throw new Error(`DID record for ${did} is not found`);
|
|
126
|
+
}
|
|
127
|
+
const rootKey = (0, utils_1.getRootKeyForHederaDid)(didRecord.didDocument);
|
|
128
|
+
const { network: networkName } = (0, core_2.parseDID)(props.did);
|
|
129
|
+
return this.clientService.withClient({ networkName }, async (client) => {
|
|
130
|
+
const topicReader = this.getHederaHcsTopicReader(agentContext);
|
|
131
|
+
const publisher = await this.getPublisher(agentContext, client, rootKey);
|
|
132
|
+
const { state, signingRequest } = await (0, registrar_1.generateDeactivateDIDRequest)({
|
|
133
|
+
did,
|
|
134
|
+
topicReader,
|
|
135
|
+
}, {
|
|
136
|
+
client,
|
|
137
|
+
publisher,
|
|
138
|
+
});
|
|
139
|
+
const signature = await agentContext.wallet.sign({
|
|
140
|
+
key: rootKey,
|
|
141
|
+
data: core_1.Buffer.from(signingRequest.serializedPayload),
|
|
142
|
+
});
|
|
143
|
+
return await (0, registrar_1.submitDeactivateDIDRequest)({
|
|
144
|
+
state,
|
|
145
|
+
signature,
|
|
146
|
+
topicReader,
|
|
147
|
+
}, {
|
|
148
|
+
client,
|
|
149
|
+
publisher,
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
getSchema(agentContext, schemaId) {
|
|
154
|
+
const registry = this.getHederaAnonCredsRegistry(agentContext);
|
|
155
|
+
return registry.getSchema(schemaId);
|
|
156
|
+
}
|
|
157
|
+
async registerSchema(agentContext, options) {
|
|
158
|
+
const registry = this.getHederaAnonCredsRegistry(agentContext);
|
|
159
|
+
const issuerKeySigner = await this.getIssuerKeySigner(agentContext, options.schema.issuerId);
|
|
160
|
+
return registry.registerSchema({ ...options, issuerKeySigner });
|
|
161
|
+
}
|
|
162
|
+
getCredentialDefinition(agentContext, credentialDefinitionId) {
|
|
163
|
+
const registry = this.getHederaAnonCredsRegistry(agentContext);
|
|
164
|
+
return registry.getCredentialDefinition(credentialDefinitionId);
|
|
165
|
+
}
|
|
166
|
+
async registerCredentialDefinition(agentContext, options) {
|
|
167
|
+
const registry = this.getHederaAnonCredsRegistry(agentContext);
|
|
168
|
+
const issuerKeySigner = await this.getIssuerKeySigner(agentContext, options.credentialDefinition.issuerId);
|
|
169
|
+
return await registry.registerCredentialDefinition({
|
|
170
|
+
...options,
|
|
171
|
+
issuerKeySigner,
|
|
172
|
+
options: {
|
|
173
|
+
supportRevocation: !!options.options?.supportRevocation,
|
|
174
|
+
},
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
getRevocationRegistryDefinition(agentContext, revocationRegistryDefinitionId) {
|
|
178
|
+
const registry = this.getHederaAnonCredsRegistry(agentContext);
|
|
179
|
+
return registry.getRevocationRegistryDefinition(revocationRegistryDefinitionId);
|
|
180
|
+
}
|
|
181
|
+
async registerRevocationRegistryDefinition(agentContext, options) {
|
|
182
|
+
const registry = this.getHederaAnonCredsRegistry(agentContext);
|
|
183
|
+
const issuerKeySigner = await this.getIssuerKeySigner(agentContext, options.revocationRegistryDefinition.issuerId);
|
|
184
|
+
return await registry.registerRevocationRegistryDefinition({
|
|
185
|
+
...options,
|
|
186
|
+
issuerKeySigner,
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
getRevocationStatusList(agentContext, revocationRegistryId, timestamp) {
|
|
190
|
+
const registry = this.getHederaAnonCredsRegistry(agentContext);
|
|
191
|
+
return registry.getRevocationStatusList(revocationRegistryId, timestamp);
|
|
192
|
+
}
|
|
193
|
+
async registerRevocationStatusList(agentContext, options) {
|
|
194
|
+
const registry = this.getHederaAnonCredsRegistry(agentContext);
|
|
195
|
+
const issuerKeySigner = await this.getIssuerKeySigner(agentContext, options.revocationStatusList.issuerId);
|
|
196
|
+
return await registry.registerRevocationStatusList({
|
|
197
|
+
...options,
|
|
198
|
+
issuerKeySigner,
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
202
|
+
getHederaHcsTopicReader(_agentContext) {
|
|
203
|
+
return new resolver_1.TopicReaderHederaHcs({ ...this.config.options, cache: this.cache });
|
|
204
|
+
}
|
|
205
|
+
async getPublisher(agentContext, client, key) {
|
|
206
|
+
return new CredoPublisher_1.CredoPublisher(agentContext, client, key);
|
|
207
|
+
}
|
|
208
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
209
|
+
getHederaAnonCredsRegistry(_agentContext) {
|
|
210
|
+
return new anoncreds_1.HederaAnoncredsRegistry({ ...this.config.options, cache: this.cache });
|
|
211
|
+
}
|
|
212
|
+
getDidDocumentEntryId(item) {
|
|
213
|
+
const id = typeof item === 'string' ? item : item.id;
|
|
214
|
+
return id.includes('#') ? `#${id.split('#').pop()}` : id;
|
|
215
|
+
}
|
|
216
|
+
getDidDocumentPropertyDiff(originalEntries = [], updatedEntries = []) {
|
|
217
|
+
const originalIds = new Set(originalEntries.map((item) => this.getDidDocumentEntryId(item)));
|
|
218
|
+
const updatedIds = new Set(updatedEntries.map((item) => this.getDidDocumentEntryId(item)));
|
|
219
|
+
const unchangedEntries = updatedEntries.filter((item) => originalIds.has(this.getDidDocumentEntryId(item)));
|
|
220
|
+
const newEntries = updatedEntries.filter((item) => !originalIds.has(this.getDidDocumentEntryId(item)));
|
|
221
|
+
const removedEntries = originalEntries.filter((item) => !updatedIds.has(this.getDidDocumentEntryId(item)));
|
|
222
|
+
return { unchangedEntries, newEntries, removedEntries };
|
|
223
|
+
}
|
|
224
|
+
async signRequests(signingRequests, wallet, signingKey) {
|
|
225
|
+
const result = {};
|
|
226
|
+
for (const [key, request] of Object.entries(signingRequests)) {
|
|
227
|
+
result[key] = await wallet.sign({
|
|
228
|
+
key: signingKey,
|
|
229
|
+
data: core_1.Buffer.from(request.serializedPayload),
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
return result;
|
|
233
|
+
}
|
|
234
|
+
prepareDidUpdates(originalDocument, newDocument, operation) {
|
|
235
|
+
const builder = new registrar_1.DIDUpdateBuilder();
|
|
236
|
+
const properties = [
|
|
237
|
+
'service',
|
|
238
|
+
'verificationMethod',
|
|
239
|
+
'assertionMethod',
|
|
240
|
+
'authentication',
|
|
241
|
+
'capabilityDelegation',
|
|
242
|
+
'capabilityInvocation',
|
|
243
|
+
'keyAgreement',
|
|
244
|
+
];
|
|
245
|
+
for (const property of properties) {
|
|
246
|
+
const { unchangedEntries, newEntries, removedEntries } = this.getDidDocumentPropertyDiff(originalDocument[property], newDocument[property]);
|
|
247
|
+
if (operation === 'setDidDocument') {
|
|
248
|
+
for (const entry of removedEntries) {
|
|
249
|
+
const entryId = this.getDidDocumentEntryId(entry);
|
|
250
|
+
if (entryId === core_2.DID_ROOT_KEY_ID)
|
|
251
|
+
continue;
|
|
252
|
+
const builderMethod = this.getUpdateMethod(builder, property, 'remove');
|
|
253
|
+
builderMethod(entryId);
|
|
254
|
+
}
|
|
255
|
+
for (const entry of newEntries) {
|
|
256
|
+
if (this.getDidDocumentEntryId(entry) === core_2.DID_ROOT_KEY_ID)
|
|
257
|
+
continue;
|
|
258
|
+
const builderMethod = this.getUpdateMethod(builder, property, 'add');
|
|
259
|
+
builderMethod(entry);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
if (operation === 'addToDidDocument') {
|
|
263
|
+
for (const entry of newEntries) {
|
|
264
|
+
if (this.getDidDocumentEntryId(entry) === core_2.DID_ROOT_KEY_ID)
|
|
265
|
+
continue;
|
|
266
|
+
const builderMethod = this.getUpdateMethod(builder, property, 'add');
|
|
267
|
+
builderMethod(entry);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
if (operation === 'removeFromDidDocument') {
|
|
271
|
+
for (const entry of unchangedEntries) {
|
|
272
|
+
const entryId = this.getDidDocumentEntryId(entry);
|
|
273
|
+
if (entryId === core_2.DID_ROOT_KEY_ID)
|
|
274
|
+
continue;
|
|
275
|
+
const builderMethod = this.getUpdateMethod(builder, property, 'remove');
|
|
276
|
+
builderMethod(entryId);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
return builder;
|
|
281
|
+
}
|
|
282
|
+
getUpdateMethod(builder, property, action
|
|
283
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
284
|
+
) {
|
|
285
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
286
|
+
const methodMap = {
|
|
287
|
+
service: {
|
|
288
|
+
add: (item) => builder.addService(item),
|
|
289
|
+
remove: (id) => builder.removeService(id),
|
|
290
|
+
},
|
|
291
|
+
verificationMethod: {
|
|
292
|
+
add: (item) => builder.addVerificationMethod(item),
|
|
293
|
+
remove: (id) => builder.removeVerificationMethod(id),
|
|
294
|
+
},
|
|
295
|
+
assertionMethod: {
|
|
296
|
+
add: (item) => builder.addAssertionMethod(item),
|
|
297
|
+
remove: (id) => builder.removeAssertionMethod(id),
|
|
298
|
+
},
|
|
299
|
+
authentication: {
|
|
300
|
+
add: (item) => builder.addAuthenticationMethod(item),
|
|
301
|
+
remove: (id) => builder.removeAuthenticationMethod(id),
|
|
302
|
+
},
|
|
303
|
+
capabilityDelegation: {
|
|
304
|
+
add: (item) => builder.addCapabilityDelegationMethod(item),
|
|
305
|
+
remove: (id) => builder.removeCapabilityDelegationMethod(id),
|
|
306
|
+
},
|
|
307
|
+
capabilityInvocation: {
|
|
308
|
+
add: (item) => builder.addCapabilityInvocationMethod(item),
|
|
309
|
+
remove: (id) => builder.removeCapabilityInvocationMethod(id),
|
|
310
|
+
},
|
|
311
|
+
keyAgreement: {
|
|
312
|
+
add: (item) => builder.addKeyAgreementMethod(item),
|
|
313
|
+
remove: (id) => builder.removeKeyAgreementMethod(id),
|
|
314
|
+
},
|
|
315
|
+
};
|
|
316
|
+
const propertyMethods = methodMap[property];
|
|
317
|
+
if (!propertyMethods) {
|
|
318
|
+
return () => builder;
|
|
319
|
+
}
|
|
320
|
+
return propertyMethods[action];
|
|
321
|
+
}
|
|
322
|
+
async getIssuerKeySigner(agentContext, issuerId) {
|
|
323
|
+
const didRepository = agentContext.dependencyManager.resolve(core_1.DidRepository);
|
|
324
|
+
const didRecord = await didRepository.findCreatedDid(agentContext, issuerId);
|
|
325
|
+
if (!didRecord?.didDocument) {
|
|
326
|
+
throw new Error(`Created DID document for ${issuerId} is not found`);
|
|
327
|
+
}
|
|
328
|
+
const issuerKey = (0, utils_1.getRootKeyForHederaDid)(didRecord.didDocument);
|
|
329
|
+
return new CredoSigner_1.CredoSigner(agentContext, issuerKey);
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
exports.HederaLedgerService = HederaLedgerService;
|
|
333
|
+
exports.HederaLedgerService = HederaLedgerService = __decorate([
|
|
334
|
+
(0, core_1.injectable)(),
|
|
335
|
+
__metadata("design:paramtypes", [HederaModuleConfig_1.HederaModuleConfig])
|
|
336
|
+
], HederaLedgerService);
|
|
337
|
+
//# sourceMappingURL=HederaLedgerService.js.map
|