@cheqd/sdk 5.4.0-develop.3 → 5.4.1-develop.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (146) hide show
  1. package/build/esm/package.json +1 -1
  2. package/package.json +1 -1
  3. package/build/esm/cjs/src/index.d.ts +0 -142
  4. package/build/esm/cjs/src/index.d.ts.map +0 -1
  5. package/build/esm/cjs/src/index.js +0 -184
  6. package/build/esm/cjs/src/index.js.map +0 -1
  7. package/build/esm/cjs/src/modules/_.d.ts +0 -81
  8. package/build/esm/cjs/src/modules/_.d.ts.map +0 -1
  9. package/build/esm/cjs/src/modules/_.js +0 -93
  10. package/build/esm/cjs/src/modules/_.js.map +0 -1
  11. package/build/esm/cjs/src/modules/did.d.ts +0 -490
  12. package/build/esm/cjs/src/modules/did.d.ts.map +0 -1
  13. package/build/esm/cjs/src/modules/did.js +0 -1274
  14. package/build/esm/cjs/src/modules/did.js.map +0 -1
  15. package/build/esm/cjs/src/modules/feeabstraction.d.ts +0 -429
  16. package/build/esm/cjs/src/modules/feeabstraction.d.ts.map +0 -1
  17. package/build/esm/cjs/src/modules/feeabstraction.js +0 -474
  18. package/build/esm/cjs/src/modules/feeabstraction.js.map +0 -1
  19. package/build/esm/cjs/src/modules/feemarket.d.ts +0 -244
  20. package/build/esm/cjs/src/modules/feemarket.d.ts.map +0 -1
  21. package/build/esm/cjs/src/modules/feemarket.js +0 -297
  22. package/build/esm/cjs/src/modules/feemarket.js.map +0 -1
  23. package/build/esm/cjs/src/modules/oracle.d.ts +0 -563
  24. package/build/esm/cjs/src/modules/oracle.d.ts.map +0 -1
  25. package/build/esm/cjs/src/modules/oracle.js +0 -784
  26. package/build/esm/cjs/src/modules/oracle.js.map +0 -1
  27. package/build/esm/cjs/src/modules/resource.d.ts +0 -332
  28. package/build/esm/cjs/src/modules/resource.d.ts.map +0 -1
  29. package/build/esm/cjs/src/modules/resource.js +0 -575
  30. package/build/esm/cjs/src/modules/resource.js.map +0 -1
  31. package/build/esm/cjs/src/querier.d.ts +0 -83
  32. package/build/esm/cjs/src/querier.d.ts.map +0 -1
  33. package/build/esm/cjs/src/querier.js +0 -138
  34. package/build/esm/cjs/src/querier.js.map +0 -1
  35. package/build/esm/cjs/src/registry.d.ts +0 -18
  36. package/build/esm/cjs/src/registry.d.ts.map +0 -1
  37. package/build/esm/cjs/src/registry.js +0 -23
  38. package/build/esm/cjs/src/registry.js.map +0 -1
  39. package/build/esm/cjs/src/signer.d.ts +0 -250
  40. package/build/esm/cjs/src/signer.d.ts.map +0 -1
  41. package/build/esm/cjs/src/signer.js +0 -617
  42. package/build/esm/cjs/src/signer.js.map +0 -1
  43. package/build/esm/cjs/src/types.d.ts +0 -221
  44. package/build/esm/cjs/src/types.d.ts.map +0 -1
  45. package/build/esm/cjs/src/types.js.map +0 -1
  46. package/build/esm/cjs/src/utils.d.ts +0 -233
  47. package/build/esm/cjs/src/utils.d.ts.map +0 -1
  48. package/build/esm/cjs/src/utils.js +0 -571
  49. package/build/esm/cjs/src/utils.js.map +0 -1
  50. package/build/esm/esm/src/types.js +0 -43
  51. package/build/types/cjs/src/index.d.ts +0 -142
  52. package/build/types/cjs/src/index.d.ts.map +0 -1
  53. package/build/types/cjs/src/modules/_.d.ts +0 -81
  54. package/build/types/cjs/src/modules/_.d.ts.map +0 -1
  55. package/build/types/cjs/src/modules/did.d.ts +0 -490
  56. package/build/types/cjs/src/modules/did.d.ts.map +0 -1
  57. package/build/types/cjs/src/modules/feeabstraction.d.ts +0 -429
  58. package/build/types/cjs/src/modules/feeabstraction.d.ts.map +0 -1
  59. package/build/types/cjs/src/modules/feemarket.d.ts +0 -244
  60. package/build/types/cjs/src/modules/feemarket.d.ts.map +0 -1
  61. package/build/types/cjs/src/modules/oracle.d.ts +0 -563
  62. package/build/types/cjs/src/modules/oracle.d.ts.map +0 -1
  63. package/build/types/cjs/src/modules/resource.d.ts +0 -332
  64. package/build/types/cjs/src/modules/resource.d.ts.map +0 -1
  65. package/build/types/cjs/src/querier.d.ts +0 -83
  66. package/build/types/cjs/src/querier.d.ts.map +0 -1
  67. package/build/types/cjs/src/registry.d.ts +0 -18
  68. package/build/types/cjs/src/registry.d.ts.map +0 -1
  69. package/build/types/cjs/src/signer.d.ts +0 -250
  70. package/build/types/cjs/src/signer.d.ts.map +0 -1
  71. package/build/types/cjs/src/types.d.ts +0 -221
  72. package/build/types/cjs/src/types.d.ts.map +0 -1
  73. package/build/types/cjs/src/utils.d.ts +0 -233
  74. package/build/types/cjs/src/utils.d.ts.map +0 -1
  75. /package/build/esm/{esm/src/index.d.ts → index.d.ts} +0 -0
  76. /package/build/esm/{esm/src/index.d.ts.map → index.d.ts.map} +0 -0
  77. /package/build/esm/{esm/src/index.js → index.js} +0 -0
  78. /package/build/esm/{esm/src/index.js.map → index.js.map} +0 -0
  79. /package/build/esm/{esm/src/modules → modules}/_.d.ts +0 -0
  80. /package/build/esm/{esm/src/modules → modules}/_.d.ts.map +0 -0
  81. /package/build/esm/{esm/src/modules → modules}/_.js +0 -0
  82. /package/build/esm/{esm/src/modules → modules}/_.js.map +0 -0
  83. /package/build/esm/{esm/src/modules → modules}/did.d.ts +0 -0
  84. /package/build/esm/{esm/src/modules → modules}/did.d.ts.map +0 -0
  85. /package/build/esm/{esm/src/modules → modules}/did.js +0 -0
  86. /package/build/esm/{esm/src/modules → modules}/did.js.map +0 -0
  87. /package/build/esm/{esm/src/modules → modules}/feeabstraction.d.ts +0 -0
  88. /package/build/esm/{esm/src/modules → modules}/feeabstraction.d.ts.map +0 -0
  89. /package/build/esm/{esm/src/modules → modules}/feeabstraction.js +0 -0
  90. /package/build/esm/{esm/src/modules → modules}/feeabstraction.js.map +0 -0
  91. /package/build/esm/{esm/src/modules → modules}/feemarket.d.ts +0 -0
  92. /package/build/esm/{esm/src/modules → modules}/feemarket.d.ts.map +0 -0
  93. /package/build/esm/{esm/src/modules → modules}/feemarket.js +0 -0
  94. /package/build/esm/{esm/src/modules → modules}/feemarket.js.map +0 -0
  95. /package/build/esm/{esm/src/modules → modules}/oracle.d.ts +0 -0
  96. /package/build/esm/{esm/src/modules → modules}/oracle.d.ts.map +0 -0
  97. /package/build/esm/{esm/src/modules → modules}/oracle.js +0 -0
  98. /package/build/esm/{esm/src/modules → modules}/oracle.js.map +0 -0
  99. /package/build/esm/{esm/src/modules → modules}/resource.d.ts +0 -0
  100. /package/build/esm/{esm/src/modules → modules}/resource.d.ts.map +0 -0
  101. /package/build/esm/{esm/src/modules → modules}/resource.js +0 -0
  102. /package/build/esm/{esm/src/modules → modules}/resource.js.map +0 -0
  103. /package/build/esm/{esm/src/querier.d.ts → querier.d.ts} +0 -0
  104. /package/build/esm/{esm/src/querier.d.ts.map → querier.d.ts.map} +0 -0
  105. /package/build/esm/{esm/src/querier.js → querier.js} +0 -0
  106. /package/build/esm/{esm/src/querier.js.map → querier.js.map} +0 -0
  107. /package/build/esm/{esm/src/registry.d.ts → registry.d.ts} +0 -0
  108. /package/build/esm/{esm/src/registry.d.ts.map → registry.d.ts.map} +0 -0
  109. /package/build/esm/{esm/src/registry.js → registry.js} +0 -0
  110. /package/build/esm/{esm/src/registry.js.map → registry.js.map} +0 -0
  111. /package/build/esm/{esm/src/signer.d.ts → signer.d.ts} +0 -0
  112. /package/build/esm/{esm/src/signer.d.ts.map → signer.d.ts.map} +0 -0
  113. /package/build/esm/{esm/src/signer.js → signer.js} +0 -0
  114. /package/build/esm/{esm/src/signer.js.map → signer.js.map} +0 -0
  115. /package/build/esm/{esm/src/types.d.ts → types.d.ts} +0 -0
  116. /package/build/esm/{esm/src/types.d.ts.map → types.d.ts.map} +0 -0
  117. /package/build/esm/{cjs/src/types.js → types.js} +0 -0
  118. /package/build/esm/{esm/src/types.js.map → types.js.map} +0 -0
  119. /package/build/esm/{esm/src/utils.d.ts → utils.d.ts} +0 -0
  120. /package/build/esm/{esm/src/utils.d.ts.map → utils.d.ts.map} +0 -0
  121. /package/build/esm/{esm/src/utils.js → utils.js} +0 -0
  122. /package/build/esm/{esm/src/utils.js.map → utils.js.map} +0 -0
  123. /package/build/types/{esm/src/index.d.ts → index.d.ts} +0 -0
  124. /package/build/types/{esm/src/index.d.ts.map → index.d.ts.map} +0 -0
  125. /package/build/types/{esm/src/modules → modules}/_.d.ts +0 -0
  126. /package/build/types/{esm/src/modules → modules}/_.d.ts.map +0 -0
  127. /package/build/types/{esm/src/modules → modules}/did.d.ts +0 -0
  128. /package/build/types/{esm/src/modules → modules}/did.d.ts.map +0 -0
  129. /package/build/types/{esm/src/modules → modules}/feeabstraction.d.ts +0 -0
  130. /package/build/types/{esm/src/modules → modules}/feeabstraction.d.ts.map +0 -0
  131. /package/build/types/{esm/src/modules → modules}/feemarket.d.ts +0 -0
  132. /package/build/types/{esm/src/modules → modules}/feemarket.d.ts.map +0 -0
  133. /package/build/types/{esm/src/modules → modules}/oracle.d.ts +0 -0
  134. /package/build/types/{esm/src/modules → modules}/oracle.d.ts.map +0 -0
  135. /package/build/types/{esm/src/modules → modules}/resource.d.ts +0 -0
  136. /package/build/types/{esm/src/modules → modules}/resource.d.ts.map +0 -0
  137. /package/build/types/{esm/src/querier.d.ts → querier.d.ts} +0 -0
  138. /package/build/types/{esm/src/querier.d.ts.map → querier.d.ts.map} +0 -0
  139. /package/build/types/{esm/src/registry.d.ts → registry.d.ts} +0 -0
  140. /package/build/types/{esm/src/registry.d.ts.map → registry.d.ts.map} +0 -0
  141. /package/build/types/{esm/src/signer.d.ts → signer.d.ts} +0 -0
  142. /package/build/types/{esm/src/signer.d.ts.map → signer.d.ts.map} +0 -0
  143. /package/build/types/{esm/src/types.d.ts → types.d.ts} +0 -0
  144. /package/build/types/{esm/src/types.d.ts.map → types.d.ts.map} +0 -0
  145. /package/build/types/{esm/src/utils.d.ts → utils.d.ts} +0 -0
  146. /package/build/types/{esm/src/utils.d.ts.map → utils.d.ts.map} +0 -0
@@ -1,1274 +0,0 @@
1
- import { createPagination, createProtobufRpcClient } from '@cosmjs/stargate-cjs';
2
- import { AbstractCheqdSDKModule } from './_';
3
- import { ISignInputs, VerificationMethods, CheqdNetwork, } from '../types';
4
- import { MsgCreateDidDoc, MsgCreateDidDocPayload, MsgCreateDidDocResponse, MsgDeactivateDidDoc, MsgDeactivateDidDocPayload, MsgDeactivateDidDocResponse, MsgUpdateDidDoc, MsgUpdateDidDocPayload, MsgUpdateDidDocResponse, protobufPackage, QueryClientImpl, VerificationMethod, } from '@cheqd/ts-proto-cjs/cheqd/did/v2/index';
5
- import { parseCoins } from '@cosmjs/proto-signing-cjs';
6
- import { v4 } from 'uuid-cjs';
7
- import { assert } from '@cosmjs/utils-cjs';
8
- import { CheqdQuerier } from '../querier';
9
- import { denormalizeService, normalizeAuthentication, normalizeController, normalizeService } from '../utils';
10
- import { defaultOracleExtensionKey, MovingAverages, WMAStrategies } from './oracle';
11
- import { Coin } from 'cosmjs-types/cosmos/base/v1beta1/coin';
12
- /** Default extension key for DID-related query operations */
13
- export const defaultDidExtensionKey = 'did';
14
- /**
15
- * Standard W3C and DID-related context URIs used in DID documents.
16
- * These contexts define the semantic meaning of properties in DID documents.
17
- */
18
- export const contexts = {
19
- /** W3C DID Core v1 context */
20
- W3CDIDv1: 'https://www.w3.org/ns/did/v1',
21
- /** Ed25519 Signature Suite 2020 context */
22
- W3CSuiteEd255192020: 'https://w3id.org/security/suites/ed25519-2020/v1',
23
- /** Ed25519 Signature Suite 2018 context */
24
- W3CSuiteEd255192018: 'https://w3id.org/security/suites/ed25519-2018/v1',
25
- /** JSON Web Signature Suite 2020 context */
26
- W3CSuiteJws2020: 'https://w3id.org/security/suites/jws-2020/v1',
27
- /** Linked Domains context for domain verification */
28
- LinkedDomainsContext: 'https://identity.foundation/.well-known/did-configuration/v1',
29
- };
30
- /**
31
- * Protobuf message type literals for DID operations.
32
- * Used for consistent message type identification across the module.
33
- */
34
- export const protobufLiterals = {
35
- /** Create DID document message type */
36
- MsgCreateDidDoc: 'MsgCreateDidDoc',
37
- /** Create DID document response message type */
38
- MsgCreateDidDocResponse: 'MsgCreateDidDocResponse',
39
- /** Update DID document message type */
40
- MsgUpdateDidDoc: 'MsgUpdateDidDoc',
41
- /** Update DID document response message type */
42
- MsgUpdateDidDocResponse: 'MsgUpdateDidDocResponse',
43
- /** Deactivate DID document message type */
44
- MsgDeactivateDidDoc: 'MsgDeactivateDidDoc',
45
- /** Deactivate DID document response message type */
46
- MsgDeactivateDidDocResponse: 'MsgDeactivateDidDocResponse',
47
- };
48
- /** Type URL for MsgCreateDidDoc messages */
49
- export const typeUrlMsgCreateDidDoc = `/${protobufPackage}.${protobufLiterals.MsgCreateDidDoc}`;
50
- /** Type URL for MsgCreateDidDocResponse messages */
51
- export const typeUrlMsgCreateDidDocResponse = `/${protobufPackage}.${protobufLiterals.MsgCreateDidDocResponse}`;
52
- /** Type URL for MsgUpdateDidDoc messages */
53
- export const typeUrlMsgUpdateDidDoc = `/${protobufPackage}.${protobufLiterals.MsgUpdateDidDoc}`;
54
- /** Type URL for MsgUpdateDidDocResponse messages */
55
- export const typeUrlMsgUpdateDidDocResponse = `/${protobufPackage}.${protobufLiterals.MsgUpdateDidDocResponse}`;
56
- /** Type URL for MsgDeactivateDidDoc messages */
57
- export const typeUrlMsgDeactivateDidDoc = `/${protobufPackage}.${protobufLiterals.MsgDeactivateDidDoc}`;
58
- /** Type URL for MsgDeactivateDidDocResponse messages */
59
- export const typeUrlMsgDeactivateDidDocResponse = `/${protobufPackage}.${protobufLiterals.MsgDeactivateDidDocResponse}`;
60
- /**
61
- * Type guard function to check if an object is a MsgCreateDidDocEncodeObject.
62
- *
63
- * @param obj - EncodeObject to check
64
- * @returns True if the object is a MsgCreateDidDocEncodeObject
65
- */
66
- export function isMsgCreateDidDocEncodeObject(obj) {
67
- return obj.typeUrl === typeUrlMsgCreateDidDoc;
68
- }
69
- /**
70
- * Type guard function to check if an object is a MsgUpdateDidDocEncodeObject.
71
- *
72
- * @param obj - EncodeObject to check
73
- * @returns True if the object is a MsgUpdateDidDocEncodeObject
74
- */
75
- export function isMsgUpdateDidDocEncodeObject(obj) {
76
- return obj.typeUrl === typeUrlMsgUpdateDidDoc;
77
- }
78
- /**
79
- * Type guard function to check if an object is a MsgDeactivateDidDocEncodeObject.
80
- *
81
- * @param obj - EncodeObject to check
82
- * @returns True if the object is a MsgDeactivateDidDocEncodeObject
83
- */
84
- export function isMsgDeactivateDidDocEncodeObject(obj) {
85
- return obj.typeUrl === typeUrlMsgDeactivateDidDoc;
86
- }
87
- /**
88
- * Type guard function to check if an object is a MsgCreateDidDocResponseEncodeObject.
89
- *
90
- * @param obj - EncodeObject to check
91
- * @returns True if the object is a MsgCreateDidDocResponseEncodeObject
92
- */
93
- export function MsgCreateDidDocResponseEncodeObject(obj) {
94
- return obj.typeUrl === typeUrlMsgCreateDidDocResponse;
95
- }
96
- /**
97
- * Type guard function to check if an object is a MsgUpdateDidDocEncodeObject.
98
- *
99
- * @param obj - EncodeObject to check
100
- * @returns True if the object is a MsgUpdateDidDocEncodeObject
101
- */
102
- export function MsgUpdateDidDocEncodeObject(obj) {
103
- return obj.typeUrl === typeUrlMsgUpdateDidDoc;
104
- }
105
- /**
106
- * Type guard function to check if an object is a MsgUpdateDidDocResponseEncodeObject.
107
- *
108
- * @param obj - EncodeObject to check
109
- * @returns True if the object is a MsgUpdateDidDocResponseEncodeObject
110
- */
111
- export function MsgUpdateDidDocResponseEncodeObject(obj) {
112
- return obj.typeUrl === typeUrlMsgUpdateDidDocResponse;
113
- }
114
- /**
115
- * Type guard function to check if an object is a MsgDeactivateDidDocEncodeObject.
116
- *
117
- * @param obj - EncodeObject to check
118
- * @returns True if the object is a MsgDeactivateDidDocEncodeObject
119
- */
120
- export function MsgDeactivateDidDocEncodeObject(obj) {
121
- return obj.typeUrl === typeUrlMsgDeactivateDidDoc;
122
- }
123
- /**
124
- * Type guard function to check if an object is a MsgDeactivateDidDocResponseEncodeObject.
125
- *
126
- * @param obj - EncodeObject to check
127
- * @returns True if the object is a MsgDeactivateDidDocResponseEncodeObject
128
- */
129
- export function MsgDeactiveDidDocResponseEncodeObject(obj) {
130
- return obj.typeUrl === typeUrlMsgUpdateDidDocResponse;
131
- }
132
- /**
133
- * Sets up the DID extension for the querier client.
134
- * Creates and configures the DID-specific query methods.
135
- *
136
- * @param base - Base QueryClient to extend
137
- * @returns Configured DID extension with query methods
138
- */
139
- export const setupDidExtension = (base) => {
140
- const rpc = createProtobufRpcClient(base);
141
- const queryService = new QueryClientImpl(rpc);
142
- return {
143
- [defaultDidExtensionKey]: {
144
- didDoc: async (id) => {
145
- const { value } = await queryService.DidDoc({ id });
146
- assert(value);
147
- return value;
148
- },
149
- didDocVersion: async (id, versionId) => {
150
- const { value } = await queryService.DidDocVersion({ id, version: versionId });
151
- assert(value);
152
- return value;
153
- },
154
- allDidDocVersionsMetadata: async (id, paginationKey) => {
155
- const response = await queryService.AllDidDocVersionsMetadata({
156
- id,
157
- pagination: createPagination(paginationKey),
158
- });
159
- return response;
160
- },
161
- params: async () => {
162
- const response = await queryService.Params({});
163
- assert(response.params);
164
- return response;
165
- },
166
- },
167
- };
168
- };
169
- /**
170
- * DID Module class providing comprehensive DID document management functionality.
171
- * Handles creation, updates, deactivation, and querying of DID documents on the Cheqd blockchain.
172
- */
173
- export class DIDModule extends AbstractCheqdSDKModule {
174
- // @ts-expect-error underlying type `GeneratedType` is intentionally wider
175
- static registryTypes = [
176
- [typeUrlMsgCreateDidDoc, MsgCreateDidDoc],
177
- [typeUrlMsgCreateDidDocResponse, MsgCreateDidDocResponse],
178
- [typeUrlMsgUpdateDidDoc, MsgUpdateDidDoc],
179
- [typeUrlMsgUpdateDidDocResponse, MsgUpdateDidDocResponse],
180
- [typeUrlMsgDeactivateDidDoc, MsgDeactivateDidDoc],
181
- [typeUrlMsgDeactivateDidDocResponse, MsgDeactivateDidDocResponse],
182
- ];
183
- /** Base denomination for Cheqd network transactions */
184
- static baseMinimalDenom = 'ncheq';
185
- /** Base denomination in USD for Cheqd network transactions */
186
- static baseUsdDenom = 'usd';
187
- /** Default slippage tolerance in base points (BPS) */
188
- static defaultSlippageBps = 500n;
189
- /**
190
- * Standard fee amounts for DID operations.
191
- * These represent the default costs for different DID document operations.
192
- */
193
- static fees = {
194
- /** Default fee for creating a new DID document */
195
- DefaultCreateDidDocFee: { amount: '50000000000', denom: DIDModule.baseMinimalDenom },
196
- /** Default fee for updating an existing DID document */
197
- DefaultUpdateDidDocFee: { amount: '25000000000', denom: DIDModule.baseMinimalDenom },
198
- /** Default fee for deactivating a DID document */
199
- DefaultDeactivateDidDocFee: { amount: '10000000000', denom: DIDModule.baseMinimalDenom },
200
- /** Default fee for creating a new DID document in USD */
201
- DefaultCreateDidDocFeeUSD: { amount: '2000000000000000000', denom: DIDModule.baseUsdDenom },
202
- /** Default fee for updating an existing DID document in USD */
203
- DefaultUpdateDidDocFeeUSD: { amount: '1000000000000000000', denom: DIDModule.baseUsdDenom },
204
- /** Default fee for deactivating a DID document in USD */
205
- DefaultDeactivateDidDocFeeUSD: { amount: '400000000000000000', denom: DIDModule.baseUsdDenom },
206
- };
207
- /**
208
- * Standard gas limits for DID operations.
209
- * These represent the default gas limits for different DID document operations.
210
- */
211
- static gasLimits = {
212
- /** Gas limit for creating a new DID document */
213
- CreateDidDocGasLimit: '360000',
214
- /** Gas limit for updating an existing DID document */
215
- UpdateDidDocGasLimit: '360000',
216
- /** Gas limit for deactivating a DID document */
217
- DeactivateDidDocGasLimit: '360000',
218
- };
219
- /** Querier extension setup function for DID operations */
220
- static querierExtensionSetup = setupDidExtension;
221
- /** Querier instance with DID extension capabilities */
222
- querier;
223
- /**
224
- * Constructs a new DID module instance.
225
- *
226
- * @param signer - Signing client for blockchain transactions
227
- * @param querier - Querier client with DID extension for data retrieval
228
- */
229
- constructor(signer, querier) {
230
- super(signer, querier);
231
- this.querier = querier;
232
- this.methods = {
233
- createDidDocTx: this.createDidDocTx.bind(this),
234
- updateDidDocTx: this.updateDidDocTx.bind(this),
235
- deactivateDidDocTx: this.deactivateDidDocTx.bind(this),
236
- queryDidDoc: this.queryDidDoc.bind(this),
237
- queryDidDocVersion: this.queryDidDocVersion.bind(this),
238
- queryAllDidDocVersionsMetadata: this.queryAllDidDocVersionsMetadata.bind(this),
239
- queryParams: this.queryParams.bind(this),
240
- generateCreateDidDocFees: this.generateCreateDidDocFees.bind(this),
241
- };
242
- }
243
- /**
244
- * Gets the registry types for DID message encoding/decoding.
245
- *
246
- * @returns Iterable of [typeUrl, GeneratedType] pairs for the registry
247
- */
248
- getRegistryTypes() {
249
- return DIDModule.registryTypes;
250
- }
251
- /**
252
- * Gets the querier extension setup for DID operations.
253
- *
254
- * @returns Query extension setup function for DID functionality
255
- */
256
- getQuerierExtensionSetup() {
257
- return DIDModule.querierExtensionSetup;
258
- }
259
- /**
260
- * Creates a new DID document transaction on the blockchain.
261
- * Validates the DID payload and authentication before submission.
262
- *
263
- * @param signInputs - Signing inputs or pre-computed signatures for the transaction
264
- * @param didPayload - DID document payload to create
265
- * @param address - Address of the account submitting the transaction
266
- * @param fee - Transaction fee configuration or 'auto' for automatic calculation
267
- * @param memo - Optional transaction memo
268
- * @param versionId - Optional version identifier for the DID document
269
- * @param feeOptions - Optional fee options for the transaction
270
- * @param context - Optional SDK context for accessing clients
271
- * @returns Promise resolving to the transaction response
272
- * @throws Error if DID payload is not spec compliant or authentication is invalid
273
- */
274
- async createDidDocTx(signInputs, didPayload, address, fee, memo, versionId, feeOptions, context) {
275
- if (!this._signer) {
276
- this._signer = context.sdk.signer;
277
- }
278
- if (!this.querier) {
279
- this.querier = context.sdk.querier;
280
- }
281
- if (!versionId || versionId === '') {
282
- versionId = v4();
283
- }
284
- const { valid, error, protobufVerificationMethod, protobufService } = await DIDModule.validateSpecCompliantPayload(didPayload);
285
- if (!valid) {
286
- throw new Error(`DID payload is not spec compliant: ${error}`);
287
- }
288
- const { valid: authenticationValid, error: authenticationError } = await DIDModule.validateAuthenticationAgainstSignatures(didPayload, signInputs, this.querier);
289
- if (!authenticationValid) {
290
- throw new Error(`DID authentication is not valid: ${authenticationError}`);
291
- }
292
- const payload = MsgCreateDidDocPayload.fromPartial({
293
- context: didPayload?.['@context'],
294
- id: didPayload.id,
295
- controller: didPayload.controller,
296
- verificationMethod: protobufVerificationMethod,
297
- authentication: didPayload.authentication,
298
- assertionMethod: didPayload.assertionMethod,
299
- capabilityInvocation: didPayload.capabilityInvocation,
300
- capabilityDelegation: didPayload.capabilityDelegation,
301
- keyAgreement: didPayload.keyAgreement,
302
- service: protobufService,
303
- alsoKnownAs: didPayload.alsoKnownAs,
304
- versionId: versionId,
305
- });
306
- let signatures;
307
- if (ISignInputs.isSignInput(signInputs)) {
308
- signatures = await this._signer.signCreateDidDocTx(signInputs, payload);
309
- }
310
- else {
311
- signatures = signInputs;
312
- }
313
- const value = {
314
- payload,
315
- signatures,
316
- };
317
- const createDidMsg = {
318
- typeUrl: typeUrlMsgCreateDidDoc,
319
- value,
320
- };
321
- if (address === '') {
322
- address = (await context.sdk.options.wallet.getAccounts())[0].address;
323
- }
324
- if (!fee) {
325
- fee = await this.generateCreateDidDocFees(address, undefined, feeOptions, context);
326
- }
327
- return this._signer.signAndBroadcast(address, [createDidMsg], fee, memo);
328
- }
329
- /**
330
- * Updates an existing DID document transaction on the blockchain.
331
- * Validates the updated DID payload and handles key rotation scenarios.
332
- *
333
- * @param signInputs - Signing inputs or pre-computed signatures for the transaction
334
- * @param didPayload - Updated DID document payload
335
- * @param address - Address of the account submitting the transaction
336
- * @param fee - Transaction fee configuration or 'auto' for automatic calculation
337
- * @param memo - Optional transaction memo
338
- * @param versionId - Optional version identifier for the updated DID document
339
- * @param feeOptions - Optional fee options for the transaction
340
- * @param context - Optional SDK context for accessing clients
341
- * @returns Promise resolving to the transaction response
342
- * @throws Error if DID payload is not spec compliant or authentication is invalid
343
- */
344
- async updateDidDocTx(signInputs, didPayload, address, fee, memo, versionId, feeOptions, context) {
345
- if (!this._signer) {
346
- this._signer = context.sdk.signer;
347
- }
348
- if (!this.querier) {
349
- this.querier = context.sdk.querier;
350
- }
351
- if (!versionId || versionId === '') {
352
- versionId = v4();
353
- }
354
- const { valid, error, protobufVerificationMethod, protobufService } = await DIDModule.validateSpecCompliantPayload(didPayload);
355
- if (!valid) {
356
- throw new Error(`DID payload is not spec compliant: ${error}`);
357
- }
358
- const { valid: authenticationValid, error: authenticationError, externalControllersDocuments, previousDidDocument, } = await DIDModule.validateAuthenticationAgainstSignaturesKeyRotation(didPayload, signInputs, this.querier);
359
- if (!authenticationValid) {
360
- throw new Error(`DID authentication is not valid: ${authenticationError}`);
361
- }
362
- const payload = MsgUpdateDidDocPayload.fromPartial({
363
- context: didPayload?.['@context'],
364
- id: didPayload.id,
365
- controller: didPayload.controller,
366
- verificationMethod: protobufVerificationMethod,
367
- authentication: didPayload.authentication,
368
- assertionMethod: didPayload.assertionMethod,
369
- capabilityInvocation: didPayload.capabilityInvocation,
370
- capabilityDelegation: didPayload.capabilityDelegation,
371
- keyAgreement: didPayload.keyAgreement,
372
- service: protobufService,
373
- alsoKnownAs: didPayload.alsoKnownAs,
374
- versionId: versionId,
375
- });
376
- let signatures;
377
- if (ISignInputs.isSignInput(signInputs)) {
378
- signatures = await this._signer.signUpdateDidDocTx(signInputs, payload, externalControllersDocuments, previousDidDocument);
379
- }
380
- else {
381
- signatures = signInputs;
382
- }
383
- const value = {
384
- payload,
385
- signatures,
386
- };
387
- const updateDidMsg = {
388
- typeUrl: typeUrlMsgUpdateDidDoc,
389
- value,
390
- };
391
- if (address === '') {
392
- address = (await context.sdk.options.wallet.getAccounts())[0].address;
393
- }
394
- if (!fee) {
395
- fee = await this.generateUpdateDidDocFees(address, undefined, feeOptions, context);
396
- }
397
- return this._signer.signAndBroadcast(address, [updateDidMsg], fee, memo);
398
- }
399
- /**
400
- * Deactivates an existing DID document transaction on the blockchain.
401
- * Validates authentication and creates a deactivation transaction.
402
- *
403
- * @param signInputs - Signing inputs or pre-computed signatures for the transaction
404
- * @param didPayload - DID document payload containing the ID to deactivate
405
- * @param address - Address of the account submitting the transaction
406
- * @param fee - Transaction fee configuration or 'auto' for automatic calculation
407
- * @param memo - Optional transaction memo
408
- * @param versionId - Optional version identifier for the deactivation
409
- * @param feeOptions - Optional fee options for the transaction
410
- * @param context - Optional SDK context for accessing clients
411
- * @returns Promise resolving to the transaction response
412
- * @throws Error if DID payload is not spec compliant or authentication is invalid
413
- */
414
- async deactivateDidDocTx(signInputs, didPayload, address, fee, memo, versionId, feeOptions, context) {
415
- if (!this._signer) {
416
- this._signer = context.sdk.signer;
417
- }
418
- if (!versionId || versionId === '') {
419
- versionId = v4();
420
- }
421
- const { valid, error, protobufVerificationMethod } = await DIDModule.validateSpecCompliantPayload(didPayload);
422
- if (!valid) {
423
- throw new Error(`DID payload is not spec compliant: ${error}`);
424
- }
425
- const { valid: authenticationValid, error: authenticationError } = await DIDModule.validateAuthenticationAgainstSignatures(didPayload, signInputs, this.querier);
426
- if (!authenticationValid) {
427
- throw new Error(`DID authentication is not valid: ${authenticationError}`);
428
- }
429
- const payload = MsgDeactivateDidDocPayload.fromPartial({
430
- id: didPayload.id,
431
- versionId: versionId,
432
- });
433
- let signatures;
434
- if (ISignInputs.isSignInput(signInputs)) {
435
- signatures = await this._signer.signDeactivateDidDocTx(signInputs, payload, protobufVerificationMethod);
436
- }
437
- else {
438
- signatures = signInputs;
439
- }
440
- const value = {
441
- payload,
442
- signatures,
443
- };
444
- const deactivateDidMsg = {
445
- typeUrl: typeUrlMsgDeactivateDidDoc,
446
- value,
447
- };
448
- if (address === '') {
449
- address = (await context.sdk.options.wallet.getAccounts())[0].address;
450
- }
451
- if (!fee) {
452
- fee = await this.generateDeactivateDidDocFees(address, undefined, feeOptions, context);
453
- }
454
- return this._signer.signAndBroadcast(address, [deactivateDidMsg], fee, memo);
455
- }
456
- /**
457
- * Queries a DID document by its identifier.
458
- * Retrieves the latest version of the DID document with metadata.
459
- *
460
- * @param id - DID identifier to query
461
- * @param context - Optional SDK context for accessing clients
462
- * @returns Promise resolving to the DID document with metadata
463
- */
464
- async queryDidDoc(id, context) {
465
- if (!this.querier) {
466
- this.querier = context.sdk.querier;
467
- }
468
- const { didDoc, metadata } = await this.querier[defaultDidExtensionKey].didDoc(id);
469
- return {
470
- didDocument: await DIDModule.toSpecCompliantPayload(didDoc),
471
- didDocumentMetadata: await DIDModule.toSpecCompliantMetadata(metadata),
472
- };
473
- }
474
- /**
475
- * Queries a specific version of a DID document by its identifier and version ID.
476
- *
477
- * @param id - DID identifier to query
478
- * @param versionId - Specific version identifier to retrieve
479
- * @param context - Optional SDK context for accessing clients
480
- * @returns Promise resolving to the DID document version with metadata
481
- */
482
- async queryDidDocVersion(id, versionId, context) {
483
- if (!this.querier) {
484
- this.querier = context.sdk.querier;
485
- }
486
- const { didDoc, metadata } = await this.querier[defaultDidExtensionKey].didDocVersion(id, versionId);
487
- return {
488
- didDocument: await DIDModule.toSpecCompliantPayload(didDoc),
489
- didDocumentMetadata: await DIDModule.toSpecCompliantMetadata(metadata),
490
- };
491
- }
492
- /**
493
- * Queries metadata for all versions of a DID document.
494
- * Retrieves version history information for a specific DID.
495
- *
496
- * @param id - DID identifier to query version metadata for
497
- * @param context - Optional SDK context for accessing clients
498
- * @returns Promise resolving to array of version metadata and pagination info
499
- */
500
- async queryAllDidDocVersionsMetadata(id, context) {
501
- if (!this.querier) {
502
- this.querier = context.sdk.querier;
503
- }
504
- const { versions, pagination } = await this.querier[defaultDidExtensionKey].allDidDocVersionsMetadata(id);
505
- return {
506
- didDocumentVersionsMetadata: await Promise.all(versions.map(async (m) => await DIDModule.toSpecCompliantMetadata(m))),
507
- pagination,
508
- };
509
- }
510
- async resolveNetworkForFees(context) {
511
- if (context?.sdk?.options?.rpcUrl) {
512
- return await CheqdQuerier.detectNetwork(context.sdk.options.rpcUrl);
513
- }
514
- return context?.sdk?.options?.network ?? CheqdNetwork.Testnet;
515
- }
516
- async shouldUseOracleFees(context) {
517
- return (await this.resolveNetworkForFees(context)) === CheqdNetwork.Testnet;
518
- }
519
- /**
520
- * Queries the DID module parameters from the blockchain.
521
- * @param context - Optional SDK context for accessing clients
522
- * @returns Promise resolving to the DID module parameters
523
- */
524
- async queryParams(context) {
525
- if (!this.querier) {
526
- this.querier = context.sdk.querier;
527
- }
528
- return this.querier[defaultDidExtensionKey].params();
529
- }
530
- /**
531
- * Generates oracle-powered fees for creating a DID document.
532
- *
533
- * @param feePayer - Address of the account that will pay the transaction fees
534
- * @param granter - Optional address of the account granting fee payment permissions
535
- * @param feeOptions - Options for fetching oracle fees
536
- * @param context - Optional SDK context for accessing clients
537
- * @returns Promise resolving to the fee configuration for DID document creation with oracle fees
538
- */
539
- async generateCreateDidDocFees(feePayer, granter, feeOptions, context) {
540
- if (!this.querier) {
541
- this.querier = context.sdk.querier;
542
- }
543
- if (!(await this.shouldUseOracleFees(context))) {
544
- return DIDModule.generateCreateDidDocFees(feePayer, granter);
545
- }
546
- // fetch fee parameters from the DID module
547
- const feeParams = await this.queryParams(context);
548
- // get the price range for the create operation
549
- const priceRange = await this.getPriceRangeFromParams(feeParams, 'create', feeOptions);
550
- // calculate the oracle fee amount based on the price range and options
551
- return {
552
- amount: [await this.calculateOracleFeeAmount(priceRange, feeOptions, context)],
553
- gas: feeOptions?.gasLimit || DIDModule.gasLimits.CreateDidDocGasLimit,
554
- payer: feePayer,
555
- granter,
556
- };
557
- }
558
- /**
559
- * Generates oracle-powered fees for updating a DID document.
560
- *
561
- * @param feePayer - Address of the account that will pay the transaction fees
562
- * @param granter - Optional address of the account granting fee payment permissions
563
- * @param feeOptions - Options for fetching oracle fees
564
- * @param context - Optional SDK context for accessing clients
565
- * @returns Promise resolving to the fee configuration for DID document update with oracle fees
566
- */
567
- async generateUpdateDidDocFees(feePayer, granter, fetchOptions, context) {
568
- if (!this.querier) {
569
- this.querier = context.sdk.querier;
570
- }
571
- if (!(await this.shouldUseOracleFees(context))) {
572
- return DIDModule.generateUpdateDidDocFees(feePayer, granter);
573
- }
574
- // fetch fee parameters from the DID module
575
- const feeParams = await this.queryParams(context);
576
- // get the price range for the update operation
577
- const priceRange = await this.getPriceRangeFromParams(feeParams, 'update', fetchOptions);
578
- // calculate the oracle fee amount based on the price range and options
579
- return {
580
- amount: [await this.calculateOracleFeeAmount(priceRange, fetchOptions, context)],
581
- gas: fetchOptions?.gasLimit || DIDModule.gasLimits.UpdateDidDocGasLimit,
582
- payer: feePayer,
583
- granter,
584
- };
585
- }
586
- /** Generates oracle-powered fees for deactivating a DID document.
587
- *
588
- * @param feePayer - Address of the account that will pay the transaction fees
589
- * @param granter - Optional address of the account granting fee payment permissions
590
- * @param feeOptions - Options for fetching oracle fees
591
- * @param context - Optional SDK context for accessing clients
592
- * @returns Promise resolving to the fee configuration for DID document deactivation with oracle fees
593
- */
594
- async generateDeactivateDidDocFees(feePayer, granter, feeOptions, context) {
595
- if (!this.querier) {
596
- this.querier = context.sdk.querier;
597
- }
598
- if (!(await this.shouldUseOracleFees(context))) {
599
- return DIDModule.generateDeactivateDidDocFees(feePayer, granter);
600
- }
601
- // fetch fee parameters from the DID module
602
- const feeParams = await this.queryParams(context);
603
- // get the price range for the deactivate operation
604
- const priceRange = await this.getPriceRangeFromParams(feeParams, 'deactivate', feeOptions);
605
- // calculate the oracle fee amount based on the price range and options
606
- return {
607
- amount: [await this.calculateOracleFeeAmount(priceRange, feeOptions, context)],
608
- gas: feeOptions?.gasLimit || DIDModule.gasLimits.DeactivateDidDocGasLimit,
609
- payer: feePayer,
610
- granter,
611
- };
612
- }
613
- /**
614
- * Gets the fee range for a specific DID operation from the module parameters.
615
- * @param feeParams - DID module fee parameters
616
- * @param operation - DID operation type ('create', 'update', 'deactivate')
617
- * @param feeOptions - Options for fee retrieval
618
- * @returns Promise resolving to the fee range for the specified operation
619
- */
620
- async getPriceRangeFromParams(feeParams, operation, feeOptions) {
621
- const operationFees = (() => {
622
- switch (operation) {
623
- case 'create':
624
- return feeParams.params?.createDid.find((fee) => fee.denom === (feeOptions?.feeDenom ?? DIDModule.baseUsdDenom));
625
- case 'update':
626
- return feeParams.params?.updateDid.find((fee) => fee.denom === (feeOptions?.feeDenom ?? DIDModule.baseUsdDenom));
627
- case 'deactivate':
628
- return feeParams.params?.deactivateDid.find((fee) => fee.denom === (feeOptions?.feeDenom ?? DIDModule.baseUsdDenom));
629
- default:
630
- throw new Error('Unsupported operation for fee retrieval');
631
- }
632
- })();
633
- if (!operationFees) {
634
- throw new Error(`Fee parameters not found for operation: ${operation}`);
635
- }
636
- return operationFees;
637
- }
638
- /**
639
- * Calculates the oracle fee amount based on the provided fee range and options.
640
- * @param feeRange - Fee range for the DID operation
641
- * @param feeOptions - Options for fee calculation
642
- * @param context - Optional SDK context for accessing clients
643
- * @returns Promise resolving to the calculated fee amount as a Coin
644
- */
645
- async calculateOracleFeeAmount(feeRange, feeOptions, context) {
646
- if (!this.querier) {
647
- this.querier = context.sdk.querier;
648
- }
649
- if (feeRange.denom !== feeOptions?.feeDenom && feeOptions?.feeDenom !== undefined) {
650
- throw new Error(`Fee denomination mismatch: expected ${feeRange.denom}, got ${feeOptions.feeDenom}`);
651
- }
652
- const wantedFeeAmount = feeRange.denom === DIDModule.baseUsdDenom
653
- ? (feeOptions?.wantedAmountUsd ?? DIDModule.isFixedRange(feeRange))
654
- ? feeRange.minAmount
655
- : feeRange.minAmount
656
- : feeRange.minAmount;
657
- // override fee options, if unassigned - case: moving average type
658
- feeOptions = {
659
- ...feeOptions,
660
- movingAverageType: feeOptions?.movingAverageType || MovingAverages.WMA,
661
- };
662
- // override fee options, if unassigned - case: WMA strategy
663
- feeOptions = {
664
- ...feeOptions,
665
- wmaStrategy: feeOptions?.wmaStrategy || feeOptions?.movingAverageType === MovingAverages.WMA
666
- ? WMAStrategies.BALANCED
667
- : undefined,
668
- };
669
- const convertedFeeAmount = feeRange.denom === DIDModule.baseUsdDenom
670
- ? parseCoins((await this.querier[defaultOracleExtensionKey].convertUSDtoCHEQ(wantedFeeAmount, feeOptions?.movingAverageType, feeOptions?.wmaStrategy, feeOptions?.wmaWeights?.map((w) => BigInt(w)))).amount)[0]
671
- : Coin.fromPartial({ amount: wantedFeeAmount, denom: feeRange.denom });
672
- return feeOptions?.slippageBps
673
- ? DIDModule.applySlippageToCoin(convertedFeeAmount, feeOptions.slippageBps)
674
- : convertedFeeAmount;
675
- }
676
- /**
677
- * Applies slippage to a given coin amount based on the specified basis points.
678
- * @param coin - Coin amount to apply slippage to
679
- * @param slippageBps - Slippage in basis points (bps)
680
- * @returns Coin with adjusted amount after applying slippage
681
- */
682
- static applySlippageToCoin(coin, slippageBps) {
683
- const base = BigInt(coin.amount);
684
- const delta = (base * BigInt(slippageBps)) / BigInt(10_000);
685
- const adjustedAmount = base + delta;
686
- return Coin.fromPartial({ amount: adjustedAmount.toString(), denom: coin.denom });
687
- }
688
- /**
689
- * Checks if a fee range represents a fixed fee (minAmount equals maxAmount).
690
- * @param feeRange - Fee range to check
691
- * @returns True if the fee range is fixed, false otherwise
692
- */
693
- static isFixedRange(feeRange) {
694
- return feeRange.minAmount === feeRange.maxAmount;
695
- }
696
- /**
697
- * Validates a DID document against the Cheqd specification requirements.
698
- * Ensures all required fields are present and verification methods are supported.
699
- *
700
- * @param didDocument - DID document to validate
701
- * @returns Promise resolving to validation result with protobuf conversion or error details
702
- */
703
- static async validateSpecCompliantPayload(didDocument) {
704
- // id is required, validated on both compile and runtime
705
- if (!didDocument?.id)
706
- return { valid: false, error: 'id is required' };
707
- // verificationMethod is required
708
- if (!didDocument?.verificationMethod)
709
- return { valid: false, error: 'verificationMethod is required' };
710
- // verificationMethod must be an array
711
- if (!Array.isArray(didDocument?.verificationMethod))
712
- return { valid: false, error: 'verificationMethod must be an array' };
713
- // verificationMethod types must be supported
714
- const protoVerificationMethod = didDocument.verificationMethod.map((vm) => {
715
- switch (vm?.type) {
716
- case VerificationMethods.Ed255192020:
717
- if (!vm?.publicKeyMultibase)
718
- throw new Error('publicKeyMultibase is required');
719
- return VerificationMethod.fromPartial({
720
- id: vm.id,
721
- controller: vm.controller,
722
- verificationMethodType: VerificationMethods.Ed255192020,
723
- verificationMaterial: vm.publicKeyMultibase,
724
- });
725
- case VerificationMethods.JWK:
726
- if (!vm?.publicKeyJwk)
727
- throw new Error('publicKeyJwk is required');
728
- return VerificationMethod.fromPartial({
729
- id: vm.id,
730
- controller: vm.controller,
731
- verificationMethodType: VerificationMethods.JWK,
732
- verificationMaterial: JSON.stringify(vm.publicKeyJwk),
733
- });
734
- case VerificationMethods.Ed255192018:
735
- if (!vm?.publicKeyBase58)
736
- throw new Error('publicKeyBase58 is required');
737
- return VerificationMethod.fromPartial({
738
- id: vm.id,
739
- controller: vm.controller,
740
- verificationMethodType: VerificationMethods.Ed255192018,
741
- verificationMaterial: vm.publicKeyBase58,
742
- });
743
- default:
744
- throw new Error('Unsupported verificationMethod type');
745
- }
746
- });
747
- const protoService = normalizeService(didDocument);
748
- return {
749
- valid: true,
750
- protobufVerificationMethod: protoVerificationMethod,
751
- protobufService: protoService,
752
- };
753
- }
754
- /**
755
- * Converts a protobuf DID document to a specification-compliant DID document format.
756
- * Handles context inclusion, verification method formatting, and service denormalization.
757
- *
758
- * @param protobufDidDocument - Protobuf DID document to convert
759
- * @returns Promise resolving to a spec-compliant DID document
760
- */
761
- static async toSpecCompliantPayload(protobufDidDocument) {
762
- const verificationMethod = protobufDidDocument.verificationMethod.map((vm) => {
763
- switch (vm.verificationMethodType) {
764
- case VerificationMethods.Ed255192020:
765
- if (!protobufDidDocument.context.includes(contexts.W3CSuiteEd255192020))
766
- protobufDidDocument.context = [...protobufDidDocument.context, contexts.W3CSuiteEd255192020];
767
- return {
768
- id: vm.id,
769
- type: vm.verificationMethodType,
770
- controller: vm.controller,
771
- publicKeyMultibase: vm.verificationMaterial,
772
- };
773
- case VerificationMethods.JWK:
774
- if (!protobufDidDocument.context.includes(contexts.W3CSuiteJws2020))
775
- protobufDidDocument.context = [...protobufDidDocument.context, contexts.W3CSuiteJws2020];
776
- return {
777
- id: vm.id,
778
- type: vm.verificationMethodType,
779
- controller: vm.controller,
780
- publicKeyJwk: JSON.parse(vm.verificationMaterial),
781
- };
782
- case VerificationMethods.Ed255192018:
783
- if (!protobufDidDocument.context.includes(contexts.W3CSuiteEd255192018))
784
- protobufDidDocument.context = [...protobufDidDocument.context, contexts.W3CSuiteEd255192018];
785
- return {
786
- id: vm.id,
787
- type: vm.verificationMethodType,
788
- controller: vm.controller,
789
- publicKeyBase58: vm.verificationMaterial,
790
- };
791
- default:
792
- throw new Error('Unsupported verificationMethod type'); // should never happen
793
- }
794
- });
795
- const service = denormalizeService(protobufDidDocument);
796
- const context = (function () {
797
- if (protobufDidDocument.context.includes(contexts.W3CDIDv1))
798
- return protobufDidDocument.context;
799
- return [contexts.W3CDIDv1, ...protobufDidDocument.context];
800
- })();
801
- const assertionMethod = protobufDidDocument.assertionMethod.map((am) => {
802
- try {
803
- // Check if the assertionMethod is a DID URL
804
- if (!am.startsWith('did:cheqd:')) {
805
- // Parse once if it's a stringified JSON
806
- const parsedAm = JSON.parse(am);
807
- if (typeof parsedAm === 'string') {
808
- // Parse again only if necessary
809
- return JSON.parse(parsedAm);
810
- }
811
- return parsedAm;
812
- }
813
- return am;
814
- }
815
- catch (error) {
816
- throw new Error(`Unsupported assertionMethod type: ${am}`);
817
- }
818
- });
819
- const specCompliant = {
820
- '@context': context,
821
- id: protobufDidDocument.id,
822
- controller: protobufDidDocument.controller,
823
- verificationMethod: verificationMethod,
824
- authentication: protobufDidDocument.authentication,
825
- assertionMethod: assertionMethod,
826
- capabilityInvocation: protobufDidDocument.capabilityInvocation,
827
- capabilityDelegation: protobufDidDocument.capabilityDelegation,
828
- keyAgreement: protobufDidDocument.keyAgreement,
829
- service: service,
830
- alsoKnownAs: protobufDidDocument.alsoKnownAs,
831
- };
832
- if (!protobufDidDocument.authentication?.length)
833
- delete specCompliant.authentication;
834
- if (!protobufDidDocument.assertionMethod?.length)
835
- delete specCompliant.assertionMethod;
836
- if (!protobufDidDocument.capabilityInvocation?.length)
837
- delete specCompliant.capabilityInvocation;
838
- if (!protobufDidDocument.capabilityDelegation?.length)
839
- delete specCompliant.capabilityDelegation;
840
- if (!protobufDidDocument.keyAgreement?.length)
841
- delete specCompliant.keyAgreement;
842
- if (!protobufDidDocument.service?.length)
843
- delete specCompliant.service;
844
- if (!protobufDidDocument.alsoKnownAs?.length)
845
- delete specCompliant.alsoKnownAs;
846
- return specCompliant;
847
- }
848
- /**
849
- * Converts protobuf metadata to specification-compliant DID document metadata format.
850
- * Handles date formatting and optional field normalization.
851
- *
852
- * @param protobufDidDocument - Protobuf metadata to convert
853
- * @returns Promise resolving to spec-compliant DID document metadata
854
- */
855
- static async toSpecCompliantMetadata(protobufDidDocument) {
856
- return {
857
- created: protobufDidDocument.created?.toISOString(),
858
- updated: protobufDidDocument.updated?.toISOString(),
859
- deactivated: protobufDidDocument.deactivated,
860
- versionId: protobufDidDocument.versionId,
861
- nextVersionId: protobufDidDocument?.nextVersionId,
862
- previousVersionId: protobufDidDocument?.previousVersionId,
863
- };
864
- }
865
- /**
866
- * Validates that provided signatures match the authentication requirements in a DID document.
867
- * Checks signature count, authentication presence, and controller authorization.
868
- *
869
- * @param didDocument - DID document containing authentication requirements
870
- * @param signatures - Array of signatures to validate against authentication
871
- * @param querier - Optional querier for retrieving external controller documents
872
- * @param externalControllersDidDocuments - Optional pre-loaded external controller documents
873
- * @returns Promise resolving to validation result with error details if invalid
874
- */
875
- static async validateAuthenticationAgainstSignatures(didDocument, signatures, querier, externalControllersDidDocuments) {
876
- // validate signatures - case: no signatures
877
- if (!signatures || !signatures.length)
878
- return { valid: false, error: 'signatures are required' };
879
- // validate authentication - case: no authentication when at least one verificationMethod
880
- if ((!didDocument.authentication || !didDocument.authentication.length) &&
881
- didDocument.verificationMethod?.length)
882
- return { valid: false, error: 'authentication is required' };
883
- const normalizedAuthentication = normalizeAuthentication(didDocument);
884
- // define unique authentication
885
- const uniqueAuthentication = new Set(normalizedAuthentication);
886
- // validate authentication - case: authentication contains duplicates
887
- if (uniqueAuthentication.size < normalizedAuthentication.length)
888
- return {
889
- valid: false,
890
- error: `authentication contains duplicate key references: duplicate key reference ${Array.from(uniqueAuthentication).find((a) => normalizeAuthentication(didDocument).filter((aa) => aa === a).length > 1)}`,
891
- };
892
- // define unique signatures - shallow, only verificationMethodId, no signature
893
- const uniqueSignatures = new Set(signatures.map((s) => s.verificationMethodId));
894
- // validate signatures - case: signatures contain duplicates
895
- if (uniqueSignatures.size < signatures.length)
896
- return {
897
- valid: false,
898
- error: `signatures contain duplicates: duplicate signature for key reference ${Array.from(uniqueSignatures).find((s) => signatures.filter((ss) => ss.verificationMethodId === s).length > 1)}`,
899
- };
900
- // validate authentication - case: authentication contains invalid key references
901
- if (!Array.from(uniqueAuthentication).every((a) => didDocument.verificationMethod?.some((vm) => vm.id === a)))
902
- return {
903
- valid: false,
904
- error: `authentication contains invalid key references: invalid key reference ${Array.from(uniqueAuthentication).find((a) => !didDocument.verificationMethod?.some((vm) => vm.id === a))}`,
905
- };
906
- // define whether external controller or not
907
- const externalController = normalizeController(didDocument).some((c) => c !== didDocument.id);
908
- // validate authentication - case: authentication matches signatures, unique, if no external controller
909
- if (!Array.from(uniqueAuthentication).every((a) => uniqueSignatures.has(a)) && !externalController)
910
- return {
911
- valid: false,
912
- error: `authentication does not match signatures: signature from key ${Array.from(uniqueAuthentication).find((a) => !uniqueSignatures.has(a))} is missing`,
913
- };
914
- // validate signatures - case: authentication matches signatures, unique, excessive signatures, no external controller
915
- if (!Array.from(uniqueSignatures).every((s) => uniqueAuthentication.has(s)) && !externalController)
916
- return {
917
- valid: false,
918
- error: `authentication does not match signatures: signature from key ${Array.from(uniqueSignatures).find((s) => !uniqueAuthentication.has(s))} is not required`,
919
- };
920
- // return, if no external controller
921
- if (!externalController)
922
- return { valid: true };
923
- // require querier
924
- if (!querier)
925
- throw new Error('querier is required for external controller validation');
926
- // get external controllers
927
- const externalControllers = normalizeController(didDocument).filter((c) => c !== didDocument.id);
928
- // get external controllers' documents
929
- const externalControllersDocuments = await Promise.all(externalControllers?.map(async (c) => {
930
- // compute index of external controller's document, if provided
931
- const externalControllerDocumentIndex = externalControllersDidDocuments?.findIndex((d) => d.id === c);
932
- // get external controller's document, if provided
933
- if (externalControllerDocumentIndex !== undefined && externalControllerDocumentIndex !== -1)
934
- return externalControllersDidDocuments?.[externalControllerDocumentIndex];
935
- // fetch external controller's document
936
- const protobufDocument = await querier[defaultDidExtensionKey].didDoc(c);
937
- // throw, if not found
938
- if (!protobufDocument || !protobufDocument.didDoc)
939
- throw new Error(`Document for controller ${c} not found`);
940
- // convert to spec compliant payload
941
- return await DIDModule.toSpecCompliantPayload(protobufDocument.didDoc);
942
- }));
943
- // define unique required signatures
944
- const uniqueRequiredSignatures = new Set(externalControllersDocuments.concat(didDocument).flatMap((d) => (d ? normalizeAuthentication(d) : [])));
945
- // validate authentication - case: authentication matches signatures, unique, if external controller
946
- if (!Array.from(uniqueRequiredSignatures).every((a) => uniqueSignatures.has(a)))
947
- return {
948
- valid: false,
949
- error: `authentication does not match signatures: signature from key ${Array.from(uniqueRequiredSignatures).find((a) => !uniqueSignatures.has(a))} is missing`,
950
- };
951
- // validate authentication - case: authentication matches signatures, unique, excessive signatures, if external controller
952
- if (uniqueRequiredSignatures.size < uniqueSignatures.size)
953
- return {
954
- valid: false,
955
- error: `authentication does not match signatures: signature from key ${Array.from(uniqueSignatures).find((s) => !uniqueRequiredSignatures.has(s))} is not required`,
956
- };
957
- // return valid
958
- return { valid: true };
959
- }
960
- /**
961
- * Validates authentication against signatures for key rotation scenarios.
962
- * Handles validation during DID document updates where keys may have changed.
963
- *
964
- * @param didDocument - Updated DID document to validate
965
- * @param signatures - Array of signatures to validate
966
- * @param querier - Querier for retrieving previous DID document and controllers
967
- * @param previousDidDocument - Optional previous version of the DID document
968
- * @param externalControllersDidDocuments - Optional pre-loaded external controller documents
969
- * @returns Promise resolving to validation result with controller documents and previous document
970
- */
971
- static async validateAuthenticationAgainstSignaturesKeyRotation(didDocument, signatures, querier, previousDidDocument, externalControllersDidDocuments) {
972
- // validate signatures - case: no signatures
973
- if (!signatures || !signatures.length)
974
- return { valid: false, error: 'signatures are required' };
975
- // validate authentication - case: no authentication when at least one verificationMethod
976
- if ((!didDocument.authentication || !didDocument.authentication.length) &&
977
- didDocument.verificationMethod?.length)
978
- return { valid: false, error: 'authentication is required' };
979
- // define unique authentication
980
- const authentication = normalizeAuthentication(didDocument);
981
- const uniqueAuthentication = new Set(authentication);
982
- // validate authentication - case: authentication contains duplicates
983
- if (uniqueAuthentication.size < authentication.length)
984
- return {
985
- valid: false,
986
- error: `authentication contains duplicate key references: duplicate key reference ${Array.from(uniqueAuthentication).find((a) => normalizeAuthentication(didDocument).filter((aa) => aa === a).length > 1)}`,
987
- };
988
- // define unique signatures
989
- const uniqueSignatures = new Set(signatures.map((s) => s.verificationMethodId));
990
- // validate authentication - case: authentication contains invalid key references
991
- if (!Array.from(uniqueAuthentication).every((a) => didDocument.verificationMethod?.some((vm) => vm.id === a)))
992
- return {
993
- valid: false,
994
- error: `authentication contains invalid key references: invalid key reference ${Array.from(uniqueAuthentication).find((a) => !didDocument.verificationMethod?.some((vm) => vm.id === a))}`,
995
- };
996
- // lookup previous document
997
- if (!previousDidDocument) {
998
- // get previous document
999
- const previousDocument = await querier[defaultDidExtensionKey].didDoc(didDocument.id);
1000
- // throw, if not found
1001
- if (!previousDocument || !previousDocument.didDoc)
1002
- throw new Error('Previous did document not found');
1003
- previousDidDocument = await DIDModule.toSpecCompliantPayload(previousDocument.didDoc);
1004
- }
1005
- const controllers = normalizeController(didDocument);
1006
- const previousControllers = normalizeController(previousDidDocument);
1007
- // define whether external controller or not
1008
- const externalController = controllers.concat(previousControllers).some((c) => c !== didDocument.id);
1009
- // define whether key rotation or not (same ID, different material)
1010
- const keyRotation = !!didDocument.verificationMethod?.some((vm) => previousDidDocument?.verificationMethod?.some((pvm) => pvm.id === vm.id &&
1011
- (pvm.publicKeyBase58 !== vm.publicKeyBase58 ||
1012
- pvm.publicKeyMultibase !== vm.publicKeyMultibase ||
1013
- pvm.publicKeyJwk?.x !== vm.publicKeyJwk?.x)));
1014
- // define whether key replacement or not (different IDs in authentication)
1015
- const currentAuthenticationIds = new Set(normalizeAuthentication(didDocument));
1016
- const previousAuthenticationIds = new Set(normalizeAuthentication(previousDidDocument));
1017
- const removedKeys = Array.from(previousAuthenticationIds).filter((id) => !currentAuthenticationIds.has(id));
1018
- const addedKeys = Array.from(currentAuthenticationIds).filter((id) => !previousAuthenticationIds.has(id));
1019
- const keyReplacement = removedKeys.length > 0 && addedKeys.length > 0;
1020
- // define controller rotation
1021
- const controllerRotation = !controllers.every((c) => previousControllers.includes(c)) ||
1022
- !previousControllers.every((c) => controllers.includes(c));
1023
- // define rotated controllers
1024
- const rotatedControllers = controllerRotation
1025
- ? previousControllers.filter((c) => !controllers.includes(c))
1026
- : [];
1027
- // define unique union of authentication
1028
- const previousAuthentication = normalizeAuthentication(previousDidDocument);
1029
- const uniqueUnionAuthentication = new Set([...uniqueAuthentication, ...previousAuthentication]);
1030
- // validate authentication - case: authentication matches signatures, unique, if no external controller, no key rotation, no key replacement
1031
- if (!Array.from(uniqueUnionAuthentication).every((a) => uniqueSignatures.has(a)) &&
1032
- !externalController &&
1033
- !keyRotation &&
1034
- !keyReplacement)
1035
- return {
1036
- valid: false,
1037
- error: `authentication does not match signatures: signature from key ${Array.from(uniqueAuthentication).find((a) => !uniqueSignatures.has(a))} is missing`,
1038
- };
1039
- // define rotated keys
1040
- const rotatedKeys = keyRotation
1041
- ? didDocument.verificationMethod?.filter((vm) => previousDidDocument?.verificationMethod?.some((pvm) => pvm.id === vm.id &&
1042
- (pvm.publicKeyBase58 !== vm.publicKeyBase58 ||
1043
- pvm.publicKeyMultibase !== vm.publicKeyMultibase ||
1044
- pvm.publicKeyJwk?.x !== vm.publicKeyJwk?.x)))
1045
- : [];
1046
- // define unique union of signatures required, including key replacement logic
1047
- let uniqueUnionSignaturesRequired = new Set();
1048
- if (keyRotation && keyReplacement) {
1049
- // Combined operation: Both key rotation AND key replacement happening
1050
- // Need signatures from:
1051
- // 1. All rotated keys (both old and new material for same ID)
1052
- // 2. All added keys (new keys being added)
1053
- // 3. All removed keys (old keys being removed)
1054
- const rotatedKeySignatures = authentication
1055
- .filter((a) => rotatedKeys?.find((rk) => a === rk.id))
1056
- .map((a) => `${a}(document0)`);
1057
- const previousRotatedKeySignatures = previousAuthentication
1058
- .filter((a) => rotatedKeys?.find((rk) => a === rk.id))
1059
- .map((a) => `${a}(document1)`);
1060
- const newKeySignatures = addedKeys
1061
- .filter((keyId) => !rotatedKeys?.find((rk) => keyId === rk.id))
1062
- .map((keyId) => `${keyId}(document0)`);
1063
- const oldKeySignatures = removedKeys
1064
- .filter((keyId) => previousAuthentication.includes(keyId))
1065
- .map((keyId) => `${keyId}(document1)`);
1066
- uniqueUnionSignaturesRequired = new Set([
1067
- ...rotatedKeySignatures,
1068
- ...previousRotatedKeySignatures,
1069
- ...newKeySignatures,
1070
- ...oldKeySignatures,
1071
- ]);
1072
- }
1073
- else if (keyRotation) {
1074
- // Key rotation only (same ID, different material)
1075
- uniqueUnionSignaturesRequired = new Set([
1076
- ...authentication.filter((a) => rotatedKeys?.find((rk) => a === rk.id)).map((a) => `${a}(document0)`),
1077
- ...previousAuthentication.map((a) => `${a}(document1)`),
1078
- ]);
1079
- }
1080
- else if (keyReplacement) {
1081
- // Key replacement only (different IDs in authentication)
1082
- // For key replacement, we need signatures from:
1083
- // 1. The new keys (from current document)
1084
- // 2. The old keys that are being replaced (from previous document)
1085
- const newKeySignatures = addedKeys.map((keyId) => `${keyId}(document0)`);
1086
- const oldKeySignatures = removedKeys
1087
- .filter((keyId) => previousAuthentication.includes(keyId)) // Only if they were in authentication
1088
- .map((keyId) => `${keyId}(document1)`);
1089
- uniqueUnionSignaturesRequired = new Set([...newKeySignatures, ...oldKeySignatures]);
1090
- }
1091
- else {
1092
- const oldKeySignatures = removedKeys
1093
- .filter((keyId) => previousAuthentication.includes(keyId)) // Only if they were in authentication
1094
- .map((keyId) => `${keyId}(document1)`);
1095
- // current authentication and any removed authentication key signatures
1096
- uniqueUnionSignaturesRequired = new Set([
1097
- ...authentication.map((a) => `${a}(document0)`),
1098
- ...oldKeySignatures,
1099
- ]);
1100
- }
1101
- // define frequency of unique union of signatures required
1102
- const uniqueUnionSignaturesRequiredFrequency = new Map([...uniqueUnionSignaturesRequired].map((s) => [s.replace(new RegExp(/\(document\d+\)/), ''), 0]));
1103
- // count frequency of unique union of signatures required
1104
- uniqueUnionSignaturesRequired.forEach((s) => {
1105
- // define key
1106
- const key = s.replace(new RegExp(/\(document\d+\)/), '');
1107
- // increment frequency
1108
- uniqueUnionSignaturesRequiredFrequency.set(key, uniqueUnionSignaturesRequiredFrequency.get(key) + 1);
1109
- });
1110
- // define frequency of signatures provided
1111
- const uniqueSignaturesFrequency = new Map(signatures.map((s) => [s.verificationMethodId, 0]));
1112
- // count frequency of signatures provided
1113
- signatures.forEach((s) => {
1114
- // increment frequency
1115
- uniqueSignaturesFrequency.set(s.verificationMethodId, uniqueSignaturesFrequency.get(s.verificationMethodId) + 1);
1116
- });
1117
- // validate signatures - case: authentication matches signatures, unique, excessive signatures, no external controller
1118
- if (Array.from(uniqueSignaturesFrequency).filter(([k, f]) => uniqueUnionSignaturesRequiredFrequency.get(k) === undefined ||
1119
- (uniqueUnionSignaturesRequiredFrequency.get(k) &&
1120
- uniqueUnionSignaturesRequiredFrequency.get(k) < f)).length &&
1121
- !externalController)
1122
- return {
1123
- valid: false,
1124
- error: `authentication does not match signatures: signature from key ${Array.from(uniqueSignaturesFrequency).find(([k, f]) => uniqueUnionSignaturesRequiredFrequency.get(k) === undefined || uniqueUnionSignaturesRequiredFrequency.get(k) < f)?.[0]} is not required`,
1125
- };
1126
- // validate signatures - case: authentication matches signatures, unique, missing signatures, no external controller
1127
- if (Array.from(uniqueSignaturesFrequency).filter(([k, f]) => uniqueUnionSignaturesRequiredFrequency.get(k) && uniqueUnionSignaturesRequiredFrequency.get(k) > f).length &&
1128
- !externalController)
1129
- return {
1130
- valid: false,
1131
- error: `authentication does not match signatures: signature from key ${Array.from(uniqueSignaturesFrequency).find(([k, f]) => uniqueUnionSignaturesRequiredFrequency.get(k) > f)?.[0]} is missing`,
1132
- };
1133
- // validate signatures - case: all required keys must have signatures provided (check for completely missing keys)
1134
- if (!externalController) {
1135
- const missingKeys = Array.from(uniqueUnionSignaturesRequiredFrequency.keys()).filter((requiredKey) => !uniqueSignaturesFrequency.has(requiredKey));
1136
- if (missingKeys.length > 0) {
1137
- return {
1138
- valid: false,
1139
- error: `authentication does not match signatures: signature from key ${missingKeys[0]} is missing`,
1140
- };
1141
- }
1142
- }
1143
- // require querier
1144
- if (!querier)
1145
- throw new Error('querier is required for external controller validation');
1146
- // get external controllers
1147
- // Only include rotated controllers if they are external (not the current DID itself)
1148
- const externalRotatedControllers = rotatedControllers.filter((c) => c !== didDocument.id);
1149
- const externalControllers = controllers?.filter((c) => c !== didDocument.id).concat(externalRotatedControllers);
1150
- // get external controllers' documents
1151
- const externalControllersDocuments = await Promise.all(externalControllers?.map(async (c) => {
1152
- // compute index of external controller's document, if provided
1153
- const externalControllerDocumentIndex = externalControllersDidDocuments?.findIndex((d) => d.id === c);
1154
- // get external controller's document, if provided
1155
- if (externalControllerDocumentIndex !== undefined && externalControllerDocumentIndex !== -1)
1156
- return externalControllersDidDocuments[externalControllerDocumentIndex];
1157
- // fetch external controller's document
1158
- const protobufDocument = await querier[defaultDidExtensionKey].didDoc(c);
1159
- // throw, if not found
1160
- if (!protobufDocument || !protobufDocument.didDoc)
1161
- throw new Error(`Document for controller ${c} not found`);
1162
- // convert to spec compliant payload
1163
- return await DIDModule.toSpecCompliantPayload(protobufDocument.didDoc);
1164
- }));
1165
- // define unique required signatures, delimited, with external controllers
1166
- const uniqueUnionSignaturesRequiredWithExternalControllers = new Set([
1167
- ...uniqueUnionSignaturesRequired,
1168
- ...externalControllersDocuments
1169
- .flatMap((d) => normalizeAuthentication(d))
1170
- .map((a) => `${a}(document${externalControllersDocuments.findIndex((d) => normalizeAuthentication(d).includes(a))})`),
1171
- ]);
1172
- // add rotated controller keys to unique required signatures, if any
1173
- if (controllerRotation) {
1174
- // walk through rotated controllers
1175
- rotatedControllers.forEach((c) => {
1176
- // get rotated controller's document index
1177
- const rotatedControllerDocumentIndex = externalControllersDocuments.findIndex((d) => d?.id === c);
1178
- // early return, if no document
1179
- if (rotatedControllerDocumentIndex === -1)
1180
- return;
1181
- // get rotated controller's document
1182
- const rotatedControllerDocument = externalControllersDocuments[rotatedControllerDocumentIndex];
1183
- // add rotated controller's authentication to unique required signatures
1184
- rotatedControllerDocument.authentication?.forEach((a) => uniqueUnionSignaturesRequiredWithExternalControllers.add(`${a}(document${rotatedControllerDocumentIndex})`));
1185
- });
1186
- }
1187
- // define frequency of unique union of signatures required, with external controllers
1188
- const uniqueUnionSignaturesRequiredWithExternalControllersFrequency = new Map([...uniqueUnionSignaturesRequiredWithExternalControllers].map((s) => [
1189
- s.replace(new RegExp(/\(document\d+\)/), ''),
1190
- 0,
1191
- ]));
1192
- // count frequency of unique union of signatures required, with external controllers
1193
- uniqueUnionSignaturesRequiredWithExternalControllers.forEach((s) => {
1194
- // define key
1195
- const key = s.replace(new RegExp(/\(document\d+\)/), '');
1196
- // increment frequency
1197
- uniqueUnionSignaturesRequiredWithExternalControllersFrequency.set(key, uniqueUnionSignaturesRequiredWithExternalControllersFrequency.get(key) + 1);
1198
- });
1199
- // define frequency of signatures provided, with external controllers
1200
- const uniqueSignaturesFrequencyWithExternalControllers = new Map(signatures.map((s) => [s.verificationMethodId, 0]));
1201
- // count frequency of signatures provided, with external controllers
1202
- signatures.forEach((s) => {
1203
- // increment frequency
1204
- uniqueSignaturesFrequencyWithExternalControllers.set(s.verificationMethodId, uniqueSignaturesFrequencyWithExternalControllers.get(s.verificationMethodId) + 1);
1205
- });
1206
- // validate signatures - case: authentication matches signatures, unique, excessive signatures, with external controllers
1207
- if (Array.from(uniqueSignaturesFrequencyWithExternalControllers).filter(([k, f]) => uniqueUnionSignaturesRequiredWithExternalControllersFrequency.get(k) === undefined ||
1208
- (uniqueUnionSignaturesRequiredWithExternalControllersFrequency.get(k) &&
1209
- uniqueUnionSignaturesRequiredWithExternalControllersFrequency.get(k) < f)).length &&
1210
- externalController)
1211
- return {
1212
- valid: false,
1213
- error: `authentication does not match signatures: signature from key ${Array.from(uniqueSignaturesFrequencyWithExternalControllers).find(([k, f]) => uniqueUnionSignaturesRequiredWithExternalControllersFrequency.get(k) === undefined || uniqueUnionSignaturesRequiredWithExternalControllersFrequency.get(k) < f)?.[0]} is not required`,
1214
- };
1215
- // validate signatures - case: authentication matches signatures, unique, missing signatures, with external controllers
1216
- if (Array.from(uniqueSignaturesFrequencyWithExternalControllers).filter(([k, f]) => uniqueUnionSignaturesRequiredWithExternalControllersFrequency.get(k) &&
1217
- uniqueUnionSignaturesRequiredWithExternalControllersFrequency.get(k) > f).length &&
1218
- externalController)
1219
- return {
1220
- valid: false,
1221
- error: `authentication does not match signatures: signature from key ${Array.from(uniqueSignaturesFrequencyWithExternalControllers).find(([k, f]) => uniqueUnionSignaturesRequiredWithExternalControllersFrequency.get(k) > f)?.[0]} is missing`,
1222
- };
1223
- // return valid
1224
- return { valid: true, previousDidDocument, externalControllersDocuments };
1225
- }
1226
- /**
1227
- * Generates standard fees for creating a DID document.
1228
- *
1229
- * @param feePayer - Address of the account that will pay the transaction fees
1230
- * @param granter - Optional address of the account granting fee payment permissions
1231
- * @returns Promise resolving to the fee configuration for DID document creation
1232
- */
1233
- static async generateCreateDidDocFees(feePayer, granter) {
1234
- return {
1235
- amount: [DIDModule.fees.DefaultCreateDidDocFee],
1236
- gas: '360000',
1237
- payer: feePayer,
1238
- granter: granter,
1239
- };
1240
- }
1241
- /**
1242
- * Generates fee configuration for DID document update transactions.
1243
- * Uses default update fees and gas requirements.
1244
- *
1245
- * @param feePayer - Address of the account that will pay the transaction fees
1246
- * @param granter - Optional address of the account granting fee payment permissions
1247
- * @returns Promise resolving to the fee configuration for DID document updates
1248
- */
1249
- static async generateUpdateDidDocFees(feePayer, granter) {
1250
- return {
1251
- amount: [DIDModule.fees.DefaultUpdateDidDocFee],
1252
- gas: '360000',
1253
- payer: feePayer,
1254
- granter: granter,
1255
- };
1256
- }
1257
- /**
1258
- * Generates fee configuration for DID document deactivation transactions.
1259
- * Uses default deactivation fees and gas requirements.
1260
- *
1261
- * @param feePayer - Address of the account that will pay the transaction fees
1262
- * @param granter - Optional address of the account granting fee payment permissions
1263
- * @returns Promise resolving to the fee configuration for DID document deactivation
1264
- */
1265
- static async generateDeactivateDidDocFees(feePayer, granter) {
1266
- return {
1267
- amount: [DIDModule.fees.DefaultDeactivateDidDocFee],
1268
- gas: '360000',
1269
- payer: feePayer,
1270
- granter: granter,
1271
- };
1272
- }
1273
- }
1274
- //# sourceMappingURL=did.js.map