@cheqd/sdk 3.0.2-develop.1 → 3.0.2-develop.2
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/package.json +8 -2
- package/.github/ISSUE_TEMPLATE/bug-report.yml +0 -74
- package/.github/ISSUE_TEMPLATE/config.yml +0 -14
- package/.github/ISSUE_TEMPLATE/feature-request.yaml +0 -27
- package/.github/dependabot.yml +0 -43
- package/.github/linters/.commitlint.rules.cjs +0 -37
- package/.github/linters/.eslintrc.json +0 -18
- package/.github/linters/.markdown-lint.yml +0 -139
- package/.github/linters/mlc_config.json +0 -13
- package/.github/workflows/build.yml +0 -26
- package/.github/workflows/cleanup-actions.yml +0 -45
- package/.github/workflows/cleanup-cache-automatic.yml +0 -24
- package/.github/workflows/cleanup-cache-manual.yml +0 -21
- package/.github/workflows/codeql.yml +0 -40
- package/.github/workflows/dispatch.yml +0 -30
- package/.github/workflows/lint.yml +0 -51
- package/.github/workflows/pull-request.yml +0 -48
- package/.github/workflows/release.yml +0 -42
- package/.github/workflows/test.yml +0 -66
- package/.releaserc.json +0 -61
- package/CHANGELOG.md +0 -320
- package/CODE_OF_CONDUCT.md +0 -81
- package/NOTICE.md +0 -10
- package/SECURITY.md +0 -12
- package/docker/Dockerfile +0 -55
- package/docker/entrypoint.sh +0 -58
- package/docker/localnet/build-latest.env +0 -7
- package/docker/localnet/container-env/observer-0.env +0 -13
- package/docker/localnet/container-env/seed-0.env +0 -17
- package/docker/localnet/container-env/validator-0.env +0 -13
- package/docker/localnet/container-env/validator-1.env +0 -13
- package/docker/localnet/container-env/validator-2.env +0 -13
- package/docker/localnet/container-env/validator-3.env +0 -13
- package/docker/localnet/docker-compose.yml +0 -281
- package/docker/localnet/gen-network-config.sh +0 -259
- package/docker/localnet/import-keys.sh +0 -31
- package/jest.config.cjs +0 -20
- package/src/index.ts +0 -192
- package/src/modules/_.ts +0 -61
- package/src/modules/did.ts +0 -601
- package/src/modules/resource.ts +0 -247
- package/src/querier.ts +0 -36
- package/src/registry.ts +0 -13
- package/src/signer.ts +0 -297
- package/src/types.ts +0 -110
- package/src/utils.ts +0 -246
- package/tests/index.test.ts +0 -155
- package/tests/modules/did.test.ts +0 -985
- package/tests/modules/resource.test.ts +0 -991
- package/tests/signer.test.ts +0 -202
- package/tests/testutils.test.ts +0 -29
- package/tests/utils.test.ts +0 -77
- package/tsconfig.cjs.json +0 -8
- package/tsconfig.esm.json +0 -8
- package/tsconfig.json +0 -84
- package/tsconfig.types.json +0 -10
package/src/modules/did.ts
DELETED
|
@@ -1,601 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createPagination,
|
|
3
|
-
createProtobufRpcClient,
|
|
4
|
-
DeliverTxResponse,
|
|
5
|
-
QueryClient
|
|
6
|
-
} from "@cosmjs/stargate"
|
|
7
|
-
import {
|
|
8
|
-
AbstractCheqdSDKModule,
|
|
9
|
-
MinimalImportableCheqdSDKModule
|
|
10
|
-
} from './_.js';
|
|
11
|
-
import { CheqdSigningStargateClient } from "../signer.js"
|
|
12
|
-
import {
|
|
13
|
-
DIDDocument,
|
|
14
|
-
DidStdFee,
|
|
15
|
-
IContext,
|
|
16
|
-
ISignInputs,
|
|
17
|
-
QueryExtensionSetup,
|
|
18
|
-
SpecValidationResult,
|
|
19
|
-
VerificationMethods,
|
|
20
|
-
DIDDocumentWithMetadata
|
|
21
|
-
} from '../types.js';
|
|
22
|
-
import {
|
|
23
|
-
MsgCreateDidDoc,
|
|
24
|
-
MsgCreateDidDocPayload,
|
|
25
|
-
MsgCreateDidDocResponse,
|
|
26
|
-
MsgDeactivateDidDoc,
|
|
27
|
-
MsgDeactivateDidDocPayload,
|
|
28
|
-
MsgDeactivateDidDocResponse,
|
|
29
|
-
MsgUpdateDidDoc,
|
|
30
|
-
MsgUpdateDidDocPayload,
|
|
31
|
-
MsgUpdateDidDocResponse,
|
|
32
|
-
protobufPackage,
|
|
33
|
-
QueryClientImpl,
|
|
34
|
-
Service,
|
|
35
|
-
SignInfo,
|
|
36
|
-
VerificationMethod,
|
|
37
|
-
QueryAllDidDocVersionsMetadataResponse,
|
|
38
|
-
DidDocWithMetadata,
|
|
39
|
-
DidDoc,
|
|
40
|
-
Metadata
|
|
41
|
-
} from "@cheqd/ts-proto/cheqd/did/v2/index.js"
|
|
42
|
-
import {
|
|
43
|
-
EncodeObject,
|
|
44
|
-
GeneratedType
|
|
45
|
-
} from "@cosmjs/proto-signing"
|
|
46
|
-
import { v4 } from "uuid"
|
|
47
|
-
import { assert } from "@cosmjs/utils";
|
|
48
|
-
import { PageRequest } from "@cheqd/ts-proto/cosmos/base/query/v1beta1/pagination.js";
|
|
49
|
-
import { CheqdQuerier } from "../querier.js";
|
|
50
|
-
import { DIDDocumentMetadata } from "did-resolver";
|
|
51
|
-
|
|
52
|
-
export const defaultDidExtensionKey = "did" as const
|
|
53
|
-
|
|
54
|
-
export const contexts = {
|
|
55
|
-
W3CDIDv1: "https://www.w3.org/ns/did/v1",
|
|
56
|
-
W3CSuiteEd255192020: "https://w3id.org/security/suites/ed25519-2020/v1",
|
|
57
|
-
W3CSuiteEd255192018: "https://w3id.org/security/suites/ed25519-2018/v1",
|
|
58
|
-
W3CSuiteJws2020: "https://w3id.org/security/suites/jws-2020/v1",
|
|
59
|
-
} as const
|
|
60
|
-
|
|
61
|
-
export const protobufLiterals = {
|
|
62
|
-
MsgCreateDidDoc: "MsgCreateDidDoc",
|
|
63
|
-
MsgCreateDidDocResponse: "MsgCreateDidDocResponse",
|
|
64
|
-
MsgUpdateDidDoc: "MsgUpdateDidDoc",
|
|
65
|
-
MsgUpdateDidDocResponse: "MsgUpdateDidDocResponse",
|
|
66
|
-
MsgDeactivateDidDoc: "MsgDeactivateDidDoc",
|
|
67
|
-
MsgDeactivateDidDocResponse: "MsgDeactivateDidDocResponse",
|
|
68
|
-
} as const
|
|
69
|
-
export const typeUrlMsgCreateDidDoc = `/${protobufPackage}.${protobufLiterals.MsgCreateDidDoc}`
|
|
70
|
-
export const typeUrlMsgCreateDidDocResponse = `/${protobufPackage}.${protobufLiterals.MsgCreateDidDocResponse}`
|
|
71
|
-
export const typeUrlMsgUpdateDidDoc = `/${protobufPackage}.${protobufLiterals.MsgUpdateDidDoc}`
|
|
72
|
-
export const typeUrlMsgUpdateDidDocResponse = `/${protobufPackage}.${protobufLiterals.MsgUpdateDidDocResponse}`
|
|
73
|
-
export const typeUrlMsgDeactivateDidDoc = `/${protobufPackage}.${protobufLiterals.MsgDeactivateDidDoc}`
|
|
74
|
-
export const typeUrlMsgDeactivateDidDocResponse = `/${protobufPackage}.${protobufLiterals.MsgDeactivateDidDocResponse}`
|
|
75
|
-
|
|
76
|
-
export interface MsgCreateDidDocEncodeObject extends EncodeObject {
|
|
77
|
-
readonly typeUrl: typeof typeUrlMsgCreateDidDoc,
|
|
78
|
-
readonly value: Partial<MsgCreateDidDoc>
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export function isMsgCreateDidDocEncodeObject(obj: EncodeObject): obj is MsgCreateDidDocEncodeObject {
|
|
82
|
-
return obj.typeUrl === typeUrlMsgCreateDidDoc
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export function isMsgUpdateDidDocEncodeObject(obj: EncodeObject): obj is MsgUpdateDidDocEncodeObject {
|
|
86
|
-
return obj.typeUrl === typeUrlMsgUpdateDidDoc
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export function isMsgDeactivateDidDocEncodeObject(obj: EncodeObject): obj is MsgDeactivateDidDocEncodeObject {
|
|
90
|
-
return obj.typeUrl === typeUrlMsgDeactivateDidDoc
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export interface MsgCreateDidDocResponseEncodeObject extends EncodeObject {
|
|
94
|
-
readonly typeUrl: typeof typeUrlMsgCreateDidDocResponse,
|
|
95
|
-
readonly value: Partial<MsgCreateDidDocResponse>
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
export function MsgCreateDidDocResponseEncodeObject(obj: EncodeObject): obj is MsgCreateDidDocResponseEncodeObject {
|
|
99
|
-
return obj.typeUrl === typeUrlMsgCreateDidDocResponse
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export interface MsgUpdateDidDocEncodeObject extends EncodeObject {
|
|
103
|
-
readonly typeUrl: typeof typeUrlMsgUpdateDidDoc,
|
|
104
|
-
readonly value: Partial<MsgUpdateDidDoc>
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
export function MsgUpdateDidDocEncodeObject(obj: EncodeObject): obj is MsgUpdateDidDocEncodeObject {
|
|
108
|
-
return obj.typeUrl === typeUrlMsgUpdateDidDoc
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
export interface MsgUpdateDidDocResponseEncodeObject extends EncodeObject {
|
|
112
|
-
readonly typeUrl: typeof typeUrlMsgUpdateDidDocResponse,
|
|
113
|
-
readonly value: Partial<MsgUpdateDidDocResponse>
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
export function MsgUpdateDidDocResponseEncodeObject(obj: EncodeObject): obj is MsgUpdateDidDocResponseEncodeObject {
|
|
117
|
-
return obj.typeUrl === typeUrlMsgUpdateDidDocResponse
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
export interface MsgDeactivateDidDocEncodeObject extends EncodeObject {
|
|
121
|
-
readonly typeUrl: typeof typeUrlMsgDeactivateDidDoc,
|
|
122
|
-
readonly value: Partial<MsgDeactivateDidDoc>
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
export function MsgDeactivateDidDocEncodeObject(obj: EncodeObject): obj is MsgUpdateDidDocEncodeObject {
|
|
126
|
-
return obj.typeUrl === typeUrlMsgDeactivateDidDoc
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
export interface MsgDeactivateDidDocResponseEncodeObject extends EncodeObject {
|
|
130
|
-
readonly typeUrl: typeof typeUrlMsgDeactivateDidDocResponse,
|
|
131
|
-
readonly value: Partial<MsgDeactivateDidDocResponse>
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
export function MsgDeactiveDidDocResponseEncodeObject(obj: EncodeObject): obj is MsgDeactivateDidDocResponseEncodeObject {
|
|
135
|
-
return obj.typeUrl === typeUrlMsgUpdateDidDocResponse
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
export type MinimalImportableDIDModule = MinimalImportableCheqdSDKModule<DIDModule>
|
|
140
|
-
|
|
141
|
-
export type DidExtension = {
|
|
142
|
-
readonly [defaultDidExtensionKey]: {
|
|
143
|
-
readonly didDoc: (id: string) => Promise<DidDocWithMetadata>
|
|
144
|
-
readonly didDocVersion: (id: string, versionId: string) => Promise<DidDocWithMetadata>
|
|
145
|
-
readonly allDidDocVersionsMetadata: (id: string, paginationKey?: Uint8Array) => Promise<QueryAllDidDocVersionsMetadataResponse>
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
export const setupDidExtension = (base: QueryClient): DidExtension => {
|
|
150
|
-
const rpc = createProtobufRpcClient(base)
|
|
151
|
-
|
|
152
|
-
const queryService = new QueryClientImpl(rpc)
|
|
153
|
-
|
|
154
|
-
return {
|
|
155
|
-
[defaultDidExtensionKey]: {
|
|
156
|
-
didDoc: async (id: string) => {
|
|
157
|
-
const { value } = await queryService.DidDoc({ id })
|
|
158
|
-
assert(value)
|
|
159
|
-
return value
|
|
160
|
-
},
|
|
161
|
-
didDocVersion: async (id: string, versionId: string) => {
|
|
162
|
-
const { value } = await queryService.DidDocVersion({ id, version: versionId })
|
|
163
|
-
assert(value)
|
|
164
|
-
return value
|
|
165
|
-
},
|
|
166
|
-
allDidDocVersionsMetadata: async (id: string, paginationKey?: Uint8Array) => {
|
|
167
|
-
const response = await queryService.AllDidDocVersionsMetadata({ id, pagination: createPagination(paginationKey) as PageRequest | undefined })
|
|
168
|
-
return response
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
} as DidExtension
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
export class DIDModule extends AbstractCheqdSDKModule {
|
|
175
|
-
static readonly registryTypes: Iterable<[string, GeneratedType]> = [
|
|
176
|
-
[typeUrlMsgCreateDidDoc, MsgCreateDidDoc],
|
|
177
|
-
[typeUrlMsgCreateDidDocResponse, MsgCreateDidDocResponse],
|
|
178
|
-
[typeUrlMsgUpdateDidDoc, MsgUpdateDidDoc],
|
|
179
|
-
[typeUrlMsgUpdateDidDocResponse, MsgUpdateDidDocResponse],
|
|
180
|
-
[typeUrlMsgDeactivateDidDoc, MsgDeactivateDidDoc],
|
|
181
|
-
[typeUrlMsgDeactivateDidDocResponse, MsgDeactivateDidDocResponse],
|
|
182
|
-
]
|
|
183
|
-
|
|
184
|
-
static readonly baseMinimalDenom = 'ncheq' as const
|
|
185
|
-
|
|
186
|
-
static readonly fees = {
|
|
187
|
-
DefaultCreateDidDocFee: { amount: '50000000000', denom: DIDModule.baseMinimalDenom } as const,
|
|
188
|
-
DefaultUpdateDidDocFee: { amount: '25000000000', denom: DIDModule.baseMinimalDenom } as const,
|
|
189
|
-
DefaultDeactivateDidDocFee: { amount: '10000000000', denom: DIDModule.baseMinimalDenom } as const,
|
|
190
|
-
} as const
|
|
191
|
-
|
|
192
|
-
static readonly querierExtensionSetup: QueryExtensionSetup<DidExtension> = setupDidExtension
|
|
193
|
-
|
|
194
|
-
querier: CheqdQuerier & DidExtension
|
|
195
|
-
|
|
196
|
-
constructor(signer: CheqdSigningStargateClient, querier: CheqdQuerier & DidExtension) {
|
|
197
|
-
super(signer, querier)
|
|
198
|
-
this.querier = querier
|
|
199
|
-
this.methods = {
|
|
200
|
-
createDidDocTx: this.createDidDocTx.bind(this),
|
|
201
|
-
updateDidDocTx: this.updateDidDocTx.bind(this),
|
|
202
|
-
deactivateDidDocTx: this.deactivateDidDocTx.bind(this),
|
|
203
|
-
queryDidDoc: this.queryDidDoc.bind(this),
|
|
204
|
-
queryDidDocVersion: this.queryDidDocVersion.bind(this),
|
|
205
|
-
queryAllDidDocVersionsMetadata: this.queryAllDidDocVersionsMetadata.bind(this),
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
public getRegistryTypes(): Iterable<[string, GeneratedType]> {
|
|
210
|
-
return DIDModule.registryTypes
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
public getQuerierExtensionSetup(): QueryExtensionSetup<DidExtension> {
|
|
214
|
-
return DIDModule.querierExtensionSetup
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
async createDidDocTx(signInputs: ISignInputs[] | SignInfo[], didPayload: DIDDocument, address: string, fee?: DidStdFee | 'auto' | number, memo?: string, versionId?: string, context?: IContext): Promise<DeliverTxResponse> {
|
|
218
|
-
if (!this._signer) {
|
|
219
|
-
this._signer = context!.sdk!.signer
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
if (!versionId || versionId === '') {
|
|
223
|
-
versionId = v4()
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
const { valid, error, protobufVerificationMethod, protobufService } = await DIDModule.validateSpecCompliantPayload(didPayload)
|
|
227
|
-
|
|
228
|
-
if (!valid) {
|
|
229
|
-
throw new Error(`DID payload is not spec compliant: ${error}`)
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
const payload = MsgCreateDidDocPayload.fromPartial({
|
|
233
|
-
context: <string[]>didPayload?.['@context'],
|
|
234
|
-
id: didPayload.id,
|
|
235
|
-
controller: <string[]>didPayload.controller,
|
|
236
|
-
verificationMethod: protobufVerificationMethod,
|
|
237
|
-
authentication: <string[]>didPayload.authentication,
|
|
238
|
-
assertionMethod: <string[]>didPayload.assertionMethod,
|
|
239
|
-
capabilityInvocation: <string[]>didPayload.capabilityInvocation,
|
|
240
|
-
capabilityDelegation: <string[]>didPayload.capabilityDelegation,
|
|
241
|
-
keyAgreement: <string[]>didPayload.keyAgreement,
|
|
242
|
-
service: protobufService,
|
|
243
|
-
alsoKnownAs: <string[]>didPayload.alsoKnownAs,
|
|
244
|
-
versionId: versionId
|
|
245
|
-
})
|
|
246
|
-
|
|
247
|
-
let signatures: SignInfo[]
|
|
248
|
-
if(ISignInputs.isSignInput(signInputs)) {
|
|
249
|
-
signatures = await this._signer.signcreateDidDocTx(signInputs, payload)
|
|
250
|
-
} else {
|
|
251
|
-
signatures = signInputs
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
const value: MsgCreateDidDoc = {
|
|
255
|
-
payload,
|
|
256
|
-
signatures
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
const createDidMsg: MsgCreateDidDocEncodeObject = {
|
|
260
|
-
typeUrl: typeUrlMsgCreateDidDoc,
|
|
261
|
-
value
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
if (address === '') {
|
|
265
|
-
address = (await context!.sdk!.options.wallet.getAccounts())[0].address
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
if (!fee) {
|
|
269
|
-
fee = await DIDModule.generateCreateDidDocFees(address)
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
return this._signer.signAndBroadcast(
|
|
273
|
-
address,
|
|
274
|
-
[createDidMsg],
|
|
275
|
-
fee!,
|
|
276
|
-
memo
|
|
277
|
-
)
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
async updateDidDocTx(signInputs: ISignInputs[] | SignInfo[], didPayload: DIDDocument, address: string, fee?: DidStdFee | 'auto' | number, memo?: string, versionId?: string, context?: IContext): Promise<DeliverTxResponse> {
|
|
281
|
-
if (!this._signer) {
|
|
282
|
-
this._signer = context!.sdk!.signer
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
if (!versionId || versionId === '') {
|
|
286
|
-
versionId = v4()
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
const { valid, error, protobufVerificationMethod, protobufService } = await DIDModule.validateSpecCompliantPayload(didPayload)
|
|
290
|
-
|
|
291
|
-
if (!valid) {
|
|
292
|
-
throw new Error(`DID payload is not spec compliant: ${error}`)
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
const payload = MsgUpdateDidDocPayload.fromPartial({
|
|
296
|
-
context: <string[]>didPayload?.['@context'],
|
|
297
|
-
id: didPayload.id,
|
|
298
|
-
controller: <string[]>didPayload.controller,
|
|
299
|
-
verificationMethod: protobufVerificationMethod,
|
|
300
|
-
authentication: <string[]>didPayload.authentication,
|
|
301
|
-
assertionMethod: <string[]>didPayload.assertionMethod,
|
|
302
|
-
capabilityInvocation: <string[]>didPayload.capabilityInvocation,
|
|
303
|
-
capabilityDelegation: <string[]>didPayload.capabilityDelegation,
|
|
304
|
-
keyAgreement: <string[]>didPayload.keyAgreement,
|
|
305
|
-
service: protobufService,
|
|
306
|
-
alsoKnownAs: <string[]>didPayload.alsoKnownAs,
|
|
307
|
-
versionId: versionId
|
|
308
|
-
})
|
|
309
|
-
let signatures: SignInfo[]
|
|
310
|
-
if(ISignInputs.isSignInput(signInputs)) {
|
|
311
|
-
signatures = await this._signer.signupdateDidDocTx(signInputs, payload)
|
|
312
|
-
} else {
|
|
313
|
-
signatures = signInputs
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
const value: MsgUpdateDidDoc = {
|
|
317
|
-
payload,
|
|
318
|
-
signatures
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
const updateDidMsg: MsgUpdateDidDocEncodeObject = {
|
|
322
|
-
typeUrl: typeUrlMsgUpdateDidDoc,
|
|
323
|
-
value
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
if (address === '') {
|
|
327
|
-
address = (await context!.sdk!.options.wallet.getAccounts())[0].address
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
if (!fee) {
|
|
331
|
-
fee = await DIDModule.generateUpdateDidDocFees(address)
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
return this._signer.signAndBroadcast(
|
|
335
|
-
address,
|
|
336
|
-
[updateDidMsg],
|
|
337
|
-
fee!,
|
|
338
|
-
memo
|
|
339
|
-
)
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
async deactivateDidDocTx(signInputs: ISignInputs[] | SignInfo[], didPayload: DIDDocument, address: string, fee?: DidStdFee | 'auto' | number, memo?: string, versionId?: string, context?: IContext): Promise<DeliverTxResponse> {
|
|
343
|
-
if (!this._signer) {
|
|
344
|
-
this._signer = context!.sdk!.signer
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
if (!versionId || versionId === '') {
|
|
348
|
-
versionId = v4()
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
const { valid, error, protobufVerificationMethod } = await DIDModule.validateSpecCompliantPayload(didPayload)
|
|
352
|
-
|
|
353
|
-
if (!valid) {
|
|
354
|
-
throw new Error(`DID payload is not spec compliant: ${error}`)
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
const payload = MsgDeactivateDidDocPayload.fromPartial({
|
|
358
|
-
id: didPayload.id,
|
|
359
|
-
versionId: versionId
|
|
360
|
-
})
|
|
361
|
-
|
|
362
|
-
let signatures: SignInfo[]
|
|
363
|
-
if(ISignInputs.isSignInput(signInputs)) {
|
|
364
|
-
signatures = await this._signer.signdeactivateDidDocTx(signInputs, payload, protobufVerificationMethod!)
|
|
365
|
-
} else {
|
|
366
|
-
signatures = signInputs
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
const value: MsgDeactivateDidDoc = {
|
|
370
|
-
payload,
|
|
371
|
-
signatures
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
const deactivateDidMsg: MsgDeactivateDidDocEncodeObject = {
|
|
375
|
-
typeUrl: typeUrlMsgDeactivateDidDoc,
|
|
376
|
-
value
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
if (address === '') {
|
|
380
|
-
address = (await context!.sdk!.options.wallet.getAccounts())[0].address
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
if (!fee) {
|
|
384
|
-
fee = await DIDModule.generateDeactivateDidDocFees(address)
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
return this._signer.signAndBroadcast(
|
|
388
|
-
address,
|
|
389
|
-
[deactivateDidMsg],
|
|
390
|
-
fee!,
|
|
391
|
-
memo
|
|
392
|
-
)
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
async queryDidDoc(id: string, context?: IContext): Promise<DIDDocumentWithMetadata> {
|
|
396
|
-
if (!this.querier) {
|
|
397
|
-
this.querier = context!.sdk!.querier
|
|
398
|
-
}
|
|
399
|
-
const { didDoc, metadata } = await this.querier[defaultDidExtensionKey].didDoc(id)
|
|
400
|
-
return {
|
|
401
|
-
didDocument: await DIDModule.toSpecCompliantPayload(didDoc!),
|
|
402
|
-
didDocumentMetadata: await DIDModule.toSpecCompliantMetadata(metadata!)
|
|
403
|
-
} as DIDDocumentWithMetadata
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
async queryDidDocVersion(id: string, versionId: string, context?: IContext): Promise<DIDDocumentWithMetadata> {
|
|
407
|
-
if (!this.querier) {
|
|
408
|
-
this.querier = context!.sdk!.querier
|
|
409
|
-
}
|
|
410
|
-
const { didDoc, metadata } = await this.querier[defaultDidExtensionKey].didDocVersion(id, versionId)
|
|
411
|
-
return {
|
|
412
|
-
didDocument: await DIDModule.toSpecCompliantPayload(didDoc!),
|
|
413
|
-
didDocumentMetadata: await DIDModule.toSpecCompliantMetadata(metadata!)
|
|
414
|
-
} as DIDDocumentWithMetadata
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
async queryAllDidDocVersionsMetadata(id: string, context?: IContext): Promise<{ didDocumentVersionsMetadata: DIDDocumentMetadata[], pagination: QueryAllDidDocVersionsMetadataResponse['pagination']}> {
|
|
418
|
-
if (!this.querier) {
|
|
419
|
-
this.querier = context!.sdk!.querier
|
|
420
|
-
}
|
|
421
|
-
const { versions, pagination } = await this.querier[defaultDidExtensionKey].allDidDocVersionsMetadata(id)
|
|
422
|
-
return {
|
|
423
|
-
didDocumentVersionsMetadata: await Promise.all(versions.map(async (m) => await DIDModule.toSpecCompliantMetadata(m))),
|
|
424
|
-
pagination
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
static async validateSpecCompliantPayload(didDocument: DIDDocument): Promise<SpecValidationResult> {
|
|
429
|
-
// id is required, validated on both compile and runtime
|
|
430
|
-
if (!didDocument?.id) return { valid: false, error: 'id is required' }
|
|
431
|
-
|
|
432
|
-
// verificationMethod is required
|
|
433
|
-
if (!didDocument?.verificationMethod) return { valid: false, error: 'verificationMethod is required' }
|
|
434
|
-
|
|
435
|
-
// verificationMethod must be an array
|
|
436
|
-
if (!Array.isArray(didDocument?.verificationMethod)) return { valid: false, error: 'verificationMethod must be an array' }
|
|
437
|
-
|
|
438
|
-
// verificationMethod types must be supported
|
|
439
|
-
const protoVerificationMethod = didDocument.verificationMethod.map((vm) => {
|
|
440
|
-
switch (vm?.type) {
|
|
441
|
-
case VerificationMethods.Ed255192020:
|
|
442
|
-
if (!vm?.publicKeyMultibase) throw new Error('publicKeyMultibase is required')
|
|
443
|
-
|
|
444
|
-
return VerificationMethod.fromPartial({
|
|
445
|
-
id: vm.id,
|
|
446
|
-
controller: vm.controller,
|
|
447
|
-
verificationMethodType: VerificationMethods.Ed255192020,
|
|
448
|
-
verificationMaterial: vm.publicKeyMultibase,
|
|
449
|
-
})
|
|
450
|
-
case VerificationMethods.JWK:
|
|
451
|
-
if (!vm?.publicKeyJwk) throw new Error('publicKeyJwk is required')
|
|
452
|
-
|
|
453
|
-
return VerificationMethod.fromPartial({
|
|
454
|
-
id: vm.id,
|
|
455
|
-
controller: vm.controller,
|
|
456
|
-
verificationMethodType: VerificationMethods.JWK,
|
|
457
|
-
verificationMaterial: JSON.stringify(vm.publicKeyJwk),
|
|
458
|
-
})
|
|
459
|
-
case VerificationMethods.Ed255192018:
|
|
460
|
-
if (!vm?.publicKeyBase58) throw new Error('publicKeyBase58 is required')
|
|
461
|
-
|
|
462
|
-
return VerificationMethod.fromPartial({
|
|
463
|
-
id: vm.id,
|
|
464
|
-
controller: vm.controller,
|
|
465
|
-
verificationMethodType: VerificationMethods.Ed255192018,
|
|
466
|
-
verificationMaterial: vm.publicKeyBase58,
|
|
467
|
-
})
|
|
468
|
-
default:
|
|
469
|
-
throw new Error('Unsupported verificationMethod type')
|
|
470
|
-
}
|
|
471
|
-
})
|
|
472
|
-
|
|
473
|
-
const protoService = didDocument?.service?.map((s) => {
|
|
474
|
-
return Service.fromPartial({
|
|
475
|
-
id: s?.id,
|
|
476
|
-
serviceType: s?.type,
|
|
477
|
-
serviceEndpoint: <string[]>s?.serviceEndpoint,
|
|
478
|
-
})
|
|
479
|
-
})
|
|
480
|
-
|
|
481
|
-
return { valid: true, protobufVerificationMethod: protoVerificationMethod, protobufService: protoService } as SpecValidationResult
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
static async toSpecCompliantPayload(protobufDidDocument: DidDoc): Promise<DIDDocument> {
|
|
485
|
-
const verificationMethod = protobufDidDocument.verificationMethod.map((vm) => {
|
|
486
|
-
switch (vm.verificationMethodType) {
|
|
487
|
-
case VerificationMethods.Ed255192020:
|
|
488
|
-
if (!protobufDidDocument.context.includes(contexts.W3CSuiteEd255192020))
|
|
489
|
-
protobufDidDocument.context = [...protobufDidDocument.context, contexts.W3CSuiteEd255192020]
|
|
490
|
-
return {
|
|
491
|
-
id: vm.id,
|
|
492
|
-
type: vm.verificationMethodType,
|
|
493
|
-
controller: vm.controller,
|
|
494
|
-
publicKeyMultibase: vm.verificationMaterial,
|
|
495
|
-
}
|
|
496
|
-
case VerificationMethods.JWK:
|
|
497
|
-
if (!protobufDidDocument.context.includes(contexts.W3CSuiteJws2020))
|
|
498
|
-
protobufDidDocument.context = [...protobufDidDocument.context, contexts.W3CSuiteJws2020]
|
|
499
|
-
return {
|
|
500
|
-
id: vm.id,
|
|
501
|
-
type: vm.verificationMethodType,
|
|
502
|
-
controller: vm.controller,
|
|
503
|
-
publicKeyJwk: JSON.parse(vm.verificationMaterial),
|
|
504
|
-
}
|
|
505
|
-
case VerificationMethods.Ed255192018:
|
|
506
|
-
if (!protobufDidDocument.context.includes(contexts.W3CSuiteEd255192018))
|
|
507
|
-
protobufDidDocument.context = [...protobufDidDocument.context, contexts.W3CSuiteEd255192018]
|
|
508
|
-
return {
|
|
509
|
-
id: vm.id,
|
|
510
|
-
type: vm.verificationMethodType,
|
|
511
|
-
controller: vm.controller,
|
|
512
|
-
publicKeyBase58: vm.verificationMaterial,
|
|
513
|
-
}
|
|
514
|
-
default:
|
|
515
|
-
throw new Error('Unsupported verificationMethod type') // should never happen
|
|
516
|
-
}
|
|
517
|
-
})
|
|
518
|
-
|
|
519
|
-
const service = protobufDidDocument.service.map((s) => {
|
|
520
|
-
return {
|
|
521
|
-
id: s.id,
|
|
522
|
-
type: s.serviceType,
|
|
523
|
-
serviceEndpoint: s.serviceEndpoint,
|
|
524
|
-
}
|
|
525
|
-
})
|
|
526
|
-
|
|
527
|
-
const context = function () {
|
|
528
|
-
if (protobufDidDocument.context.includes(contexts.W3CDIDv1))
|
|
529
|
-
return protobufDidDocument.context
|
|
530
|
-
|
|
531
|
-
return [contexts.W3CDIDv1, ...protobufDidDocument.context]
|
|
532
|
-
}()
|
|
533
|
-
|
|
534
|
-
const specCompliant = {
|
|
535
|
-
'@context': context,
|
|
536
|
-
id: protobufDidDocument.id,
|
|
537
|
-
controller: protobufDidDocument.controller,
|
|
538
|
-
verificationMethod: verificationMethod,
|
|
539
|
-
authentication: protobufDidDocument.authentication,
|
|
540
|
-
assertionMethod: protobufDidDocument.assertionMethod,
|
|
541
|
-
capabilityInvocation: protobufDidDocument.capabilityInvocation,
|
|
542
|
-
capabilityDelegation: protobufDidDocument.capabilityDelegation,
|
|
543
|
-
keyAgreement: protobufDidDocument.keyAgreement,
|
|
544
|
-
service: service,
|
|
545
|
-
alsoKnownAs: protobufDidDocument.alsoKnownAs,
|
|
546
|
-
} as DIDDocument
|
|
547
|
-
|
|
548
|
-
if (!protobufDidDocument.authentication?.length) delete specCompliant.authentication
|
|
549
|
-
if (!protobufDidDocument.assertionMethod?.length) delete specCompliant.assertionMethod
|
|
550
|
-
if (!protobufDidDocument.capabilityInvocation?.length) delete specCompliant.capabilityInvocation
|
|
551
|
-
if (!protobufDidDocument.capabilityDelegation?.length) delete specCompliant.capabilityDelegation
|
|
552
|
-
if (!protobufDidDocument.keyAgreement?.length) delete specCompliant.keyAgreement
|
|
553
|
-
if (!protobufDidDocument.service?.length) delete specCompliant.service
|
|
554
|
-
if (!protobufDidDocument.alsoKnownAs?.length) delete specCompliant.alsoKnownAs
|
|
555
|
-
|
|
556
|
-
return specCompliant
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
static async toSpecCompliantMetadata(protobufDidDocument: Metadata): Promise<DIDDocumentMetadata> {
|
|
560
|
-
return {
|
|
561
|
-
created: protobufDidDocument.created?.toISOString(),
|
|
562
|
-
updated: protobufDidDocument.updated?.toISOString(),
|
|
563
|
-
deactivated: protobufDidDocument.deactivated,
|
|
564
|
-
versionId: protobufDidDocument.versionId,
|
|
565
|
-
nextVersionId: protobufDidDocument?.nextVersionId,
|
|
566
|
-
}
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
static async generateCreateDidDocFees(feePayer: string, granter?: string): Promise<DidStdFee> {
|
|
570
|
-
return {
|
|
571
|
-
amount: [
|
|
572
|
-
DIDModule.fees.DefaultCreateDidDocFee
|
|
573
|
-
],
|
|
574
|
-
gas: '360000',
|
|
575
|
-
payer: feePayer,
|
|
576
|
-
granter: granter
|
|
577
|
-
} as DidStdFee
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
static async generateUpdateDidDocFees(feePayer: string, granter?: string): Promise<DidStdFee> {
|
|
581
|
-
return {
|
|
582
|
-
amount: [
|
|
583
|
-
DIDModule.fees.DefaultUpdateDidDocFee
|
|
584
|
-
],
|
|
585
|
-
gas: '360000',
|
|
586
|
-
payer: feePayer,
|
|
587
|
-
granter: granter
|
|
588
|
-
} as DidStdFee
|
|
589
|
-
}
|
|
590
|
-
|
|
591
|
-
static async generateDeactivateDidDocFees(feePayer: string, granter?: string): Promise<DidStdFee> {
|
|
592
|
-
return {
|
|
593
|
-
amount: [
|
|
594
|
-
DIDModule.fees.DefaultDeactivateDidDocFee
|
|
595
|
-
],
|
|
596
|
-
gas: '360000',
|
|
597
|
-
payer: feePayer,
|
|
598
|
-
granter: granter
|
|
599
|
-
} as DidStdFee
|
|
600
|
-
}
|
|
601
|
-
}
|