@cheqd/sdk 1.4.0 → 1.5.0-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/.github/workflows/build.yml +3 -2
- package/.github/workflows/dispatch.yml +7 -1
- package/.github/workflows/test.yml +66 -0
- package/CHANGELOG.md +22 -0
- package/build/index.d.ts +1 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +1 -3
- package/build/index.js.map +1 -1
- package/build/modules/did.d.ts +41 -28
- package/build/modules/did.d.ts.map +1 -1
- package/build/modules/did.js +78 -30
- package/build/modules/did.js.map +1 -1
- package/build/modules/resource.d.ts +4 -4
- package/build/modules/resource.d.ts.map +1 -1
- package/build/modules/resource.js +14 -33
- package/build/modules/resource.js.map +1 -1
- package/build/signer.d.ts +4 -4
- package/build/signer.d.ts.map +1 -1
- package/build/signer.js +27 -16
- package/build/signer.js.map +1 -1
- package/build/types.d.ts +239 -1
- package/build/types.d.ts.map +1 -1
- package/build/types.js +127 -2
- package/build/types.js.map +1 -1
- package/build/utils.d.ts +5 -17
- package/build/utils.d.ts.map +1 -1
- package/build/utils.js +52 -60
- package/build/utils.js.map +1 -1
- package/docker/Dockerfile +55 -0
- package/docker/entrypoint.sh +58 -0
- package/docker/localnet/build-latest.env +7 -0
- package/docker/localnet/container-env/observer-0.env +13 -0
- package/docker/localnet/container-env/seed-0.env +17 -0
- package/docker/localnet/container-env/validator-0.env +13 -0
- package/docker/localnet/container-env/validator-1.env +13 -0
- package/docker/localnet/container-env/validator-2.env +13 -0
- package/docker/localnet/container-env/validator-3.env +13 -0
- package/docker/localnet/docker-compose.yml +281 -0
- package/docker/localnet/gen-network-config.sh +259 -0
- package/docker/localnet/import-keys.sh +31 -0
- package/package.json +2 -2
- package/src/index.ts +1 -3
- package/src/modules/did.ts +118 -44
- package/src/modules/resource.ts +10 -33
- package/src/signer.ts +29 -16
- package/src/types.ts +160 -2
- package/src/utils.ts +67 -70
- package/tests/modules/did.test.ts +69 -9
- package/tests/modules/resource.test.ts +6 -4
- package/tests/signer.test.ts +25 -23
- package/tests/testutils.test.ts +43 -25
- package/tests/utils.test.ts +22 -2
package/src/modules/did.ts
CHANGED
|
@@ -1,65 +1,98 @@
|
|
|
1
1
|
import { createProtobufRpcClient, DeliverTxResponse, QueryClient } from "@cosmjs/stargate"
|
|
2
|
-
/* import { QueryClientImpl } from '@cheqd/ts-proto/cheqd/v1/query' */
|
|
2
|
+
/* import { QueryClientImpl } from '@cheqd/ts-proto/cheqd/did/v1/query' */
|
|
3
3
|
import { CheqdExtension, AbstractCheqdSDKModule, MinimalImportableCheqdSDKModule } from "./_"
|
|
4
4
|
import { CheqdSigningStargateClient } from "../signer"
|
|
5
|
-
import { DidStdFee, IContext, ISignInputs } from "../types"
|
|
6
|
-
import {
|
|
5
|
+
import { DidStdFee, IContext, ISignInputs, MsgCreateDidPayload, MsgDeactivateDidPayload, MsgUpdateDidPayload, VerificationMethodPayload } from "../types"
|
|
6
|
+
import {
|
|
7
|
+
MsgCreateDidDoc,
|
|
8
|
+
MsgCreateDidDocResponse,
|
|
9
|
+
MsgDeactivateDidDoc,
|
|
10
|
+
MsgDeactivateDidDocPayload,
|
|
11
|
+
MsgDeactivateDidDocResponse,
|
|
12
|
+
MsgUpdateDidDoc,
|
|
13
|
+
MsgUpdateDidDocResponse,
|
|
14
|
+
protobufPackage,
|
|
15
|
+
SignInfo
|
|
16
|
+
} from "@cheqd/ts-proto/cheqd/did/v2"
|
|
7
17
|
import { EncodeObject, GeneratedType } from "@cosmjs/proto-signing"
|
|
8
18
|
|
|
9
|
-
export const
|
|
10
|
-
export const
|
|
11
|
-
export const
|
|
12
|
-
export const
|
|
19
|
+
export const typeUrlMsgCreateDidDoc = `/${protobufPackage}.MsgCreateDidDoc`
|
|
20
|
+
export const typeUrlMsgCreateDidDocResponse = `/${protobufPackage}.MsgCreateDidDocResponse`
|
|
21
|
+
export const typeUrlMsgUpdateDidDoc = `/${protobufPackage}.MsgUpdateDidDoc`
|
|
22
|
+
export const typeUrlMsgUpdateDidDocResponse = `/${protobufPackage}.MsgUpdateDidDocResponse`
|
|
23
|
+
export const typeUrlMsgDeactivateDidDoc = `/${protobufPackage}.MsgDeactivateDidDoc`
|
|
24
|
+
export const typeUrlMsgDeactivateDidDocResponse = `/${protobufPackage}.MsgDeactivateDidDocResponse`
|
|
13
25
|
|
|
14
|
-
export interface
|
|
15
|
-
readonly typeUrl: typeof
|
|
16
|
-
readonly value: Partial<
|
|
26
|
+
export interface MsgCreateDidDocEncodeObject extends EncodeObject {
|
|
27
|
+
readonly typeUrl: typeof typeUrlMsgCreateDidDoc,
|
|
28
|
+
readonly value: Partial<MsgCreateDidDoc>
|
|
17
29
|
}
|
|
18
30
|
|
|
19
|
-
export function
|
|
20
|
-
return obj.typeUrl ===
|
|
31
|
+
export function isMsgCreateDidDocEncodeObject(obj: EncodeObject): obj is MsgCreateDidDocEncodeObject {
|
|
32
|
+
return obj.typeUrl === typeUrlMsgCreateDidDoc
|
|
21
33
|
}
|
|
22
34
|
|
|
23
|
-
export interface
|
|
24
|
-
readonly typeUrl: typeof
|
|
25
|
-
readonly value: Partial<
|
|
35
|
+
export interface MsgCreateDidDocResponseEncodeObject extends EncodeObject {
|
|
36
|
+
readonly typeUrl: typeof typeUrlMsgCreateDidDocResponse,
|
|
37
|
+
readonly value: Partial<MsgCreateDidDocResponse>
|
|
26
38
|
}
|
|
27
39
|
|
|
28
|
-
export function
|
|
29
|
-
return obj.typeUrl ===
|
|
40
|
+
export function MsgCreateDidDocResponseEncodeObject(obj: EncodeObject): obj is MsgCreateDidDocResponseEncodeObject {
|
|
41
|
+
return obj.typeUrl === typeUrlMsgCreateDidDocResponse
|
|
30
42
|
}
|
|
31
43
|
|
|
32
|
-
export interface
|
|
33
|
-
readonly typeUrl: typeof
|
|
34
|
-
readonly value: Partial<
|
|
44
|
+
export interface MsgUpdateDidDocEncodeObject extends EncodeObject {
|
|
45
|
+
readonly typeUrl: typeof typeUrlMsgUpdateDidDoc,
|
|
46
|
+
readonly value: Partial<MsgUpdateDidDoc>
|
|
35
47
|
}
|
|
36
48
|
|
|
37
|
-
export function
|
|
38
|
-
return obj.typeUrl ===
|
|
49
|
+
export function MsgUpdateDidDocEncodeObject(obj: EncodeObject): obj is MsgUpdateDidDocEncodeObject {
|
|
50
|
+
return obj.typeUrl === typeUrlMsgUpdateDidDoc
|
|
39
51
|
}
|
|
40
52
|
|
|
41
|
-
export interface
|
|
42
|
-
readonly typeUrl: typeof
|
|
43
|
-
readonly value: Partial<
|
|
53
|
+
export interface MsgUpdateDidDocResponseEncodeObject extends EncodeObject {
|
|
54
|
+
readonly typeUrl: typeof typeUrlMsgUpdateDidDocResponse,
|
|
55
|
+
readonly value: Partial<MsgUpdateDidDocResponse>
|
|
44
56
|
}
|
|
45
57
|
|
|
46
|
-
export function
|
|
47
|
-
return obj.typeUrl ===
|
|
58
|
+
export function MsgUpdateDidDocResponseEncodeObject(obj: EncodeObject): obj is MsgUpdateDidDocResponseEncodeObject {
|
|
59
|
+
return obj.typeUrl === typeUrlMsgUpdateDidDocResponse
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface MsgDeactivateDidDocEncodeObject extends EncodeObject {
|
|
63
|
+
readonly typeUrl: typeof typeUrlMsgDeactivateDidDoc,
|
|
64
|
+
readonly value: Partial<MsgDeactivateDidDoc>
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function MsgDeactivateDidDocEncodeObject(obj: EncodeObject): obj is MsgUpdateDidDocEncodeObject {
|
|
68
|
+
return obj.typeUrl === typeUrlMsgDeactivateDidDoc
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface MsgDeactivateDidDocResponseEncodeObject extends EncodeObject {
|
|
72
|
+
readonly typeUrl: typeof typeUrlMsgDeactivateDidDocResponse,
|
|
73
|
+
readonly value: Partial<MsgDeactivateDidDocResponse>
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function MsgDeactiveDidDocResponseEncodeObject(obj: EncodeObject): obj is MsgDeactivateDidDocResponseEncodeObject {
|
|
77
|
+
return obj.typeUrl === typeUrlMsgUpdateDidDocResponse
|
|
48
78
|
}
|
|
49
79
|
|
|
50
80
|
export class DIDModule extends AbstractCheqdSDKModule {
|
|
51
81
|
static readonly registryTypes: Iterable<[string, GeneratedType]> = [
|
|
52
|
-
[
|
|
53
|
-
[
|
|
54
|
-
[
|
|
55
|
-
[
|
|
82
|
+
[typeUrlMsgCreateDidDoc, MsgCreateDidDoc],
|
|
83
|
+
[typeUrlMsgCreateDidDocResponse, MsgCreateDidDocResponse],
|
|
84
|
+
[typeUrlMsgUpdateDidDoc, MsgUpdateDidDoc],
|
|
85
|
+
[typeUrlMsgUpdateDidDocResponse, MsgUpdateDidDocResponse],
|
|
86
|
+
[typeUrlMsgDeactivateDidDoc, MsgDeactivateDidDoc],
|
|
87
|
+
[typeUrlMsgDeactivateDidDocResponse, MsgDeactivateDidDocResponse],
|
|
56
88
|
]
|
|
57
89
|
|
|
58
90
|
constructor(signer: CheqdSigningStargateClient) {
|
|
59
91
|
super(signer)
|
|
60
92
|
this.methods = {
|
|
61
93
|
createDidTx: this.createDidTx.bind(this),
|
|
62
|
-
updateDidTx: this.updateDidTx.bind(this)
|
|
94
|
+
updateDidTx: this.updateDidTx.bind(this),
|
|
95
|
+
deactivateDidTx: this.deactivateDidTx.bind(this),
|
|
63
96
|
}
|
|
64
97
|
}
|
|
65
98
|
|
|
@@ -67,21 +100,26 @@ export class DIDModule extends AbstractCheqdSDKModule {
|
|
|
67
100
|
return DIDModule.registryTypes
|
|
68
101
|
}
|
|
69
102
|
|
|
70
|
-
async createDidTx(signInputs: ISignInputs[], didPayload: Partial<MsgCreateDidPayload>, address: string, fee: DidStdFee | 'auto' | number, memo?: string, context?: IContext): Promise<DeliverTxResponse> {
|
|
103
|
+
async createDidTx(signInputs: ISignInputs[] | SignInfo[], didPayload: Partial<MsgCreateDidPayload>, address: string, fee: DidStdFee | 'auto' | number, memo?: string, context?: IContext): Promise<DeliverTxResponse> {
|
|
71
104
|
if (!this._signer) {
|
|
72
105
|
this._signer = context!.sdk!.signer
|
|
73
106
|
}
|
|
74
107
|
|
|
75
|
-
const payload = MsgCreateDidPayload.
|
|
76
|
-
|
|
108
|
+
const payload = MsgCreateDidPayload.transformPayload(didPayload)
|
|
109
|
+
let signatures: SignInfo[]
|
|
110
|
+
if(ISignInputs.isSignInput(signInputs)) {
|
|
111
|
+
signatures = await this._signer.signCreateDidTx(signInputs, payload)
|
|
112
|
+
} else {
|
|
113
|
+
signatures = signInputs
|
|
114
|
+
}
|
|
77
115
|
|
|
78
|
-
const value:
|
|
116
|
+
const value: MsgCreateDidDoc = {
|
|
79
117
|
payload,
|
|
80
118
|
signatures
|
|
81
119
|
}
|
|
82
120
|
|
|
83
|
-
const createDidMsg:
|
|
84
|
-
typeUrl:
|
|
121
|
+
const createDidMsg: MsgCreateDidDocEncodeObject = {
|
|
122
|
+
typeUrl: typeUrlMsgCreateDidDoc,
|
|
85
123
|
value
|
|
86
124
|
}
|
|
87
125
|
|
|
@@ -93,21 +131,26 @@ export class DIDModule extends AbstractCheqdSDKModule {
|
|
|
93
131
|
)
|
|
94
132
|
}
|
|
95
133
|
|
|
96
|
-
async updateDidTx(signInputs: ISignInputs[], didPayload: Partial<MsgUpdateDidPayload>, address: string, fee: DidStdFee | 'auto' | number, memo?: string, context?: IContext): Promise<DeliverTxResponse> {
|
|
134
|
+
async updateDidTx(signInputs: ISignInputs[] | SignInfo[], didPayload: Partial<MsgUpdateDidPayload>, address: string, fee: DidStdFee | 'auto' | number, memo?: string, context?: IContext): Promise<DeliverTxResponse> {
|
|
97
135
|
if (!this._signer) {
|
|
98
136
|
this._signer = context!.sdk!.signer
|
|
99
137
|
}
|
|
100
138
|
|
|
101
|
-
const payload =
|
|
102
|
-
|
|
139
|
+
const payload = MsgCreateDidPayload.transformPayload(didPayload)
|
|
140
|
+
let signatures: SignInfo[]
|
|
141
|
+
if(ISignInputs.isSignInput(signInputs)) {
|
|
142
|
+
signatures = await this._signer.signUpdateDidTx(signInputs, payload)
|
|
143
|
+
} else {
|
|
144
|
+
signatures = signInputs
|
|
145
|
+
}
|
|
103
146
|
|
|
104
|
-
const value:
|
|
147
|
+
const value: MsgUpdateDidDoc = {
|
|
105
148
|
payload,
|
|
106
149
|
signatures
|
|
107
150
|
}
|
|
108
151
|
|
|
109
|
-
const updateDidMsg:
|
|
110
|
-
typeUrl:
|
|
152
|
+
const updateDidMsg: MsgUpdateDidDocEncodeObject = {
|
|
153
|
+
typeUrl: typeUrlMsgUpdateDidDoc,
|
|
111
154
|
value
|
|
112
155
|
}
|
|
113
156
|
|
|
@@ -118,6 +161,37 @@ export class DIDModule extends AbstractCheqdSDKModule {
|
|
|
118
161
|
memo
|
|
119
162
|
)
|
|
120
163
|
}
|
|
164
|
+
|
|
165
|
+
async deactivateDidTx(signInputs: ISignInputs[] | SignInfo[], didPayload: MsgDeactivateDidPayload, address: string, fee: DidStdFee | 'auto' | number, memo?: string, context?: IContext): Promise<DeliverTxResponse> {
|
|
166
|
+
if (!this._signer) {
|
|
167
|
+
this._signer = context!.sdk!.signer
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const payload = MsgDeactivateDidDocPayload.fromPartial({id: didPayload.id, versionId: didPayload.versionId})
|
|
171
|
+
let signatures: SignInfo[]
|
|
172
|
+
if(ISignInputs.isSignInput(signInputs)) {
|
|
173
|
+
signatures = await this._signer.signDeactivateDidTx(signInputs, payload, didPayload.verificationMethod.map((e)=>VerificationMethodPayload.transformPayload(e)))
|
|
174
|
+
} else {
|
|
175
|
+
signatures = signInputs
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const value: MsgDeactivateDidDoc = {
|
|
179
|
+
payload,
|
|
180
|
+
signatures
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
const deactivateDidMsg: MsgDeactivateDidDocEncodeObject = {
|
|
184
|
+
typeUrl: typeUrlMsgDeactivateDidDoc,
|
|
185
|
+
value
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
return this._signer.signAndBroadcast(
|
|
189
|
+
address,
|
|
190
|
+
[deactivateDidMsg],
|
|
191
|
+
fee,
|
|
192
|
+
memo
|
|
193
|
+
)
|
|
194
|
+
}
|
|
121
195
|
}
|
|
122
196
|
|
|
123
197
|
export type MinimalImportableDIDModule = MinimalImportableCheqdSDKModule<DIDModule>
|
package/src/modules/resource.ts
CHANGED
|
@@ -2,9 +2,9 @@ import { AbstractCheqdSDKModule, MinimalImportableCheqdSDKModule } from "./_"
|
|
|
2
2
|
import { CheqdSigningStargateClient } from "../signer"
|
|
3
3
|
import { EncodeObject, GeneratedType } from "@cosmjs/proto-signing"
|
|
4
4
|
import { DidStdFee, IContext, ISignInputs } from '../types';
|
|
5
|
-
import { MsgCreateResource, MsgCreateResourcePayload, MsgCreateResourceResponse, protobufPackage } from "@cheqd/ts-proto/resource/
|
|
5
|
+
import { MsgCreateResource, MsgCreateResourcePayload, MsgCreateResourceResponse, protobufPackage } from "@cheqd/ts-proto/cheqd/resource/v2"
|
|
6
6
|
import { DeliverTxResponse } from "@cosmjs/stargate"
|
|
7
|
-
import {
|
|
7
|
+
import { SignInfo } from "@cheqd/ts-proto/cheqd/did/v2";
|
|
8
8
|
|
|
9
9
|
export const typeUrlMsgCreateResource = `/${protobufPackage}.MsgCreateResource`
|
|
10
10
|
export const typeUrlMsgCreateResourceResponse = `/${protobufPackage}.MsgCreateResourceResponse`
|
|
@@ -35,37 +35,14 @@ export class ResourceModule extends AbstractCheqdSDKModule {
|
|
|
35
35
|
return []
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if (message.collectionId !== "") {
|
|
46
|
-
writer.uint32(10).string(message.collectionId);
|
|
47
|
-
}
|
|
48
|
-
if (message.id !== "") {
|
|
49
|
-
writer.uint32(18).string(message.id);
|
|
50
|
-
}
|
|
51
|
-
if (message.name !== "") {
|
|
52
|
-
writer.uint32(26).string(message.name);
|
|
53
|
-
}
|
|
54
|
-
if (message.resourceType !== "") {
|
|
55
|
-
writer.uint32(34).string(message.resourceType);
|
|
38
|
+
static async signPayload(payload: MsgCreateResourcePayload, signInputs: ISignInputs[] | SignInfo[]): Promise<MsgCreateResource> {
|
|
39
|
+
const signBytes = MsgCreateResourcePayload.encode(payload).finish()
|
|
40
|
+
let signatures: SignInfo[]
|
|
41
|
+
if(ISignInputs.isSignInput(signInputs)) {
|
|
42
|
+
signatures = await CheqdSigningStargateClient.signIdentityTx(signBytes, signInputs)
|
|
43
|
+
} else {
|
|
44
|
+
signatures = signInputs
|
|
56
45
|
}
|
|
57
|
-
if (message.data.length !== 0) {
|
|
58
|
-
// Animo coded assigns index 5 to this property. In proto definitions it's 6.
|
|
59
|
-
// Since we use amino on node + non default property indexing, we need to encode it manually.
|
|
60
|
-
writer.uint32(42).bytes(message.data);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return writer.finish();
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
static async signPayload(payload: MsgCreateResourcePayload, signInputs: ISignInputs[]): Promise<MsgCreateResource> {
|
|
67
|
-
const signBytes = ResourceModule.getMsgCreateResourcePayloadAminoSignBytes(payload)
|
|
68
|
-
const signatures = await CheqdSigningStargateClient.signIdentityTx(signBytes, signInputs)
|
|
69
46
|
|
|
70
47
|
return {
|
|
71
48
|
payload,
|
|
@@ -73,7 +50,7 @@ export class ResourceModule extends AbstractCheqdSDKModule {
|
|
|
73
50
|
}
|
|
74
51
|
}
|
|
75
52
|
|
|
76
|
-
async createResourceTx(signInputs: ISignInputs[], resourcePayload: Partial<MsgCreateResourcePayload>, address: string, fee: DidStdFee | 'auto' | number, memo?: string, context?: IContext): Promise<DeliverTxResponse> {
|
|
53
|
+
async createResourceTx(signInputs: ISignInputs[] | SignInfo[], resourcePayload: Partial<MsgCreateResourcePayload>, address: string, fee: DidStdFee | 'auto' | number, memo?: string, context?: IContext): Promise<DeliverTxResponse> {
|
|
77
54
|
if (!this._signer) {
|
|
78
55
|
this._signer = context!.sdk!.signer
|
|
79
56
|
}
|
package/src/signer.ts
CHANGED
|
@@ -3,11 +3,9 @@ import { EncodeObject, isOfflineDirectSigner, OfflineSigner, encodePubkey, TxBod
|
|
|
3
3
|
import { DeliverTxResponse, GasPrice, HttpEndpoint, QueryClient, SigningStargateClient, SigningStargateClientOptions, calculateFee, SignerData } from "@cosmjs/stargate"
|
|
4
4
|
import { Tendermint34Client } from "@cosmjs/tendermint-rpc"
|
|
5
5
|
import { createDefaultCheqdRegistry } from "./registry"
|
|
6
|
-
import {
|
|
7
|
-
import { DidStdFee, ISignInputs, TSignerAlgo, VerificationMethods } from './types';
|
|
8
|
-
import { VerificationMethod } from '@cheqd/ts-proto/cheqd/v1/did'
|
|
6
|
+
import { MsgCreateDidDocPayload, SignInfo, MsgUpdateDidDocPayload, MsgDeactivateDidDocPayload, VerificationMethod } from '@cheqd/ts-proto/cheqd/did/v2';
|
|
7
|
+
import { DidStdFee, ISignInputs, TSignerAlgo, VerificationMethodPayload, VerificationMethods } from './types';
|
|
9
8
|
import { base64ToBytes, EdDSASigner, hexToBytes, Signer, ES256Signer, ES256KSigner } from 'did-jwt';
|
|
10
|
-
import { toString } from 'uint8arrays'
|
|
11
9
|
import { assert, assertDefined } from '@cosmjs/utils'
|
|
12
10
|
import { encodeSecp256k1Pubkey } from '@cosmjs/amino'
|
|
13
11
|
import { Int53 } from '@cosmjs/math'
|
|
@@ -178,11 +176,11 @@ export class CheqdSigningStargateClient extends SigningStargateClient {
|
|
|
178
176
|
}
|
|
179
177
|
|
|
180
178
|
verificationMethods.forEach((verificationMethod) => {
|
|
181
|
-
if (!(Object.values(VerificationMethods) as string[]).includes(verificationMethod.
|
|
182
|
-
throw new Error(`Unsupported verification method type: ${verificationMethod.
|
|
179
|
+
if (!(Object.values(VerificationMethods) as string[]).includes(verificationMethod.verificationMethodType ?? '')) {
|
|
180
|
+
throw new Error(`Unsupported verification method type: ${verificationMethod.verificationMethodType}`)
|
|
183
181
|
}
|
|
184
|
-
if (!this.didSigners[verificationMethod.
|
|
185
|
-
this.didSigners[verificationMethod.
|
|
182
|
+
if (!this.didSigners[verificationMethod.verificationMethodType ?? '']) {
|
|
183
|
+
this.didSigners[verificationMethod.verificationMethodType ?? ''] = EdDSASigner
|
|
186
184
|
}
|
|
187
185
|
})
|
|
188
186
|
|
|
@@ -191,37 +189,52 @@ export class CheqdSigningStargateClient extends SigningStargateClient {
|
|
|
191
189
|
|
|
192
190
|
async getDidSigner(verificationMethodId: string, verificationMethods: Partial<VerificationMethod>[]): Promise<(secretKey: Uint8Array) => Signer> {
|
|
193
191
|
await this.checkDidSigners(verificationMethods)
|
|
194
|
-
const verificationMethod = verificationMethods.find(method => method.id === verificationMethodId)?.
|
|
192
|
+
const verificationMethod = verificationMethods.find(method => method.id === verificationMethodId)?.verificationMethodType
|
|
195
193
|
if (!verificationMethod) {
|
|
196
194
|
throw new Error(`Verification method for ${verificationMethodId} not found`)
|
|
197
195
|
}
|
|
198
196
|
return this.didSigners[verificationMethod]!
|
|
199
197
|
}
|
|
200
198
|
|
|
201
|
-
async signCreateDidTx(signInputs: ISignInputs[], payload:
|
|
199
|
+
async signCreateDidTx(signInputs: ISignInputs[], payload: MsgCreateDidDocPayload): Promise<SignInfo[]> {
|
|
202
200
|
await this.checkDidSigners(payload?.verificationMethod)
|
|
203
201
|
|
|
204
|
-
const signBytes =
|
|
202
|
+
const signBytes = MsgCreateDidDocPayload.encode(payload).finish()
|
|
205
203
|
const signInfos: SignInfo[] = await Promise.all(signInputs.map(async (signInput) => {
|
|
206
204
|
return {
|
|
207
205
|
verificationMethodId: signInput.verificationMethodId,
|
|
208
206
|
// TODO: We can't rely on `payload.verificationMethod` here because `CreateResourceTx` doesn't have it
|
|
209
|
-
signature:
|
|
207
|
+
signature: base64ToBytes((await (await this.getDidSigner(signInput.verificationMethodId, payload.verificationMethod))(hexToBytes(signInput.privateKeyHex))(signBytes)) as string)
|
|
210
208
|
}
|
|
211
209
|
}))
|
|
212
210
|
|
|
213
211
|
return signInfos
|
|
214
212
|
}
|
|
215
213
|
|
|
216
|
-
async signUpdateDidTx(signInputs: ISignInputs[], payload:
|
|
214
|
+
async signUpdateDidTx(signInputs: ISignInputs[], payload: MsgUpdateDidDocPayload): Promise<SignInfo[]> {
|
|
217
215
|
await this.checkDidSigners(payload?.verificationMethod)
|
|
218
216
|
|
|
219
|
-
const signBytes =
|
|
217
|
+
const signBytes = MsgUpdateDidDocPayload.encode(payload).finish()
|
|
220
218
|
const signInfos: SignInfo[] = await Promise.all(signInputs.map(async (signInput) => {
|
|
221
219
|
return {
|
|
222
220
|
verificationMethodId: signInput.verificationMethodId,
|
|
223
221
|
// TODO: We can't rely on `payload.verificationMethod` here because `CreateResourceTx` doesn't have it
|
|
224
|
-
signature:
|
|
222
|
+
signature: base64ToBytes((await (await this.getDidSigner(signInput.verificationMethodId, payload.verificationMethod))(hexToBytes(signInput.privateKeyHex))(signBytes)) as string)
|
|
223
|
+
}
|
|
224
|
+
}))
|
|
225
|
+
|
|
226
|
+
return signInfos
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
async signDeactivateDidTx(signInputs: ISignInputs[], payload: MsgDeactivateDidDocPayload, verificationMethod: VerificationMethod[]): Promise<SignInfo[]> {
|
|
230
|
+
await this.checkDidSigners(verificationMethod)
|
|
231
|
+
|
|
232
|
+
const signBytes = MsgDeactivateDidDocPayload.encode(payload).finish()
|
|
233
|
+
const signInfos: SignInfo[] = await Promise.all(signInputs.map(async (signInput) => {
|
|
234
|
+
return {
|
|
235
|
+
verificationMethodId: signInput.verificationMethodId,
|
|
236
|
+
// TODO: We can't rely on `payload.verificationMethod` here because `CreateResourceTx` doesn't have it
|
|
237
|
+
signature: base64ToBytes((await (await this.getDidSigner(signInput.verificationMethodId, verificationMethod))(hexToBytes(signInput.privateKeyHex))(signBytes)) as string)
|
|
225
238
|
}
|
|
226
239
|
}))
|
|
227
240
|
|
|
@@ -254,7 +267,7 @@ export class CheqdSigningStargateClient extends SigningStargateClient {
|
|
|
254
267
|
|
|
255
268
|
signInfos.push({
|
|
256
269
|
verificationMethodId: signInput.verificationMethodId,
|
|
257
|
-
signature:
|
|
270
|
+
signature: base64ToBytes(signature)
|
|
258
271
|
});
|
|
259
272
|
}
|
|
260
273
|
|
package/src/types.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { CheqdSDK } from "."
|
|
2
2
|
import { Coin } from "@cosmjs/proto-signing"
|
|
3
3
|
import { Signer } from "did-jwt"
|
|
4
|
+
import { MsgCreateDidDocPayload, MsgDeactivateDidDocPayload, MsgUpdateDidDocPayload, VerificationMethod, Service } from "@cheqd/ts-proto/cheqd/did/v2"
|
|
5
|
+
import { DeepPartial, Exact } from "cosmjs-types/confio/proofs"
|
|
4
6
|
|
|
5
7
|
export enum CheqdNetwork {
|
|
6
8
|
Mainnet = 'mainnet',
|
|
@@ -18,7 +20,8 @@ export interface IContext {
|
|
|
18
20
|
}
|
|
19
21
|
|
|
20
22
|
export enum VerificationMethods {
|
|
21
|
-
|
|
23
|
+
Ed255192020 = 'Ed25519VerificationKey2020',
|
|
24
|
+
Ed255192018 = 'Ed25519VerificationKey2018',
|
|
22
25
|
JWK = 'JsonWebKey2020',
|
|
23
26
|
}
|
|
24
27
|
|
|
@@ -37,6 +40,12 @@ export interface ISignInputs {
|
|
|
37
40
|
privateKeyHex: string
|
|
38
41
|
}
|
|
39
42
|
|
|
43
|
+
export const ISignInputs = {
|
|
44
|
+
isSignInput(object: Object[]): object is ISignInputs[] {
|
|
45
|
+
return object.some((x)=> 'privateKeyHex' in x)
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
40
49
|
export interface IKeyPair {
|
|
41
50
|
publicKey: string
|
|
42
51
|
privateKey: string
|
|
@@ -66,4 +75,153 @@ export interface DidStdFee {
|
|
|
66
75
|
readonly gas: string
|
|
67
76
|
payer?: string
|
|
68
77
|
granter?: string
|
|
69
|
-
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export interface MsgDeactivateDidPayload extends MsgDeactivateDidDocPayload {
|
|
81
|
+
verificationMethod: VerificationMethodPayload[]
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface MsgCreateDidPayload extends Omit<MsgCreateDidDocPayload, 'verificationMethod' | 'service'> {
|
|
85
|
+
verificationMethod: VerificationMethodPayload[]
|
|
86
|
+
service: ServicePayload[]
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export const MsgCreateDidPayload = {
|
|
90
|
+
transformPayload<I extends Exact<DeepPartial<MsgCreateDidPayload>, I>>(message: I): MsgCreateDidDocPayload {
|
|
91
|
+
const obj: any = {};
|
|
92
|
+
if (message.context) {
|
|
93
|
+
obj.context = message.context
|
|
94
|
+
} else {
|
|
95
|
+
obj.context = [];
|
|
96
|
+
}
|
|
97
|
+
message.id !== undefined && (obj.id = message.id);
|
|
98
|
+
if (message.controller) {
|
|
99
|
+
obj.controller = message.controller
|
|
100
|
+
}
|
|
101
|
+
if (message.verificationMethod) {
|
|
102
|
+
obj.verificationMethod = message.verificationMethod.map((e) => e ? VerificationMethodPayload.transformPayload(e) : undefined);
|
|
103
|
+
}
|
|
104
|
+
if (message.authentication) {
|
|
105
|
+
obj.authentication = message.authentication
|
|
106
|
+
}
|
|
107
|
+
if (message.assertionMethod) {
|
|
108
|
+
obj.assertionMethod = message.assertionMethod
|
|
109
|
+
}
|
|
110
|
+
if (message.capabilityInvocation) {
|
|
111
|
+
obj.capabilityInvocation = message.capabilityInvocation
|
|
112
|
+
}
|
|
113
|
+
if (message.capabilityDelegation) {
|
|
114
|
+
obj.capabilityDelegation = message.capabilityDelegation
|
|
115
|
+
}
|
|
116
|
+
if (message.keyAgreement) {
|
|
117
|
+
obj.keyAgreement = message.keyAgreement
|
|
118
|
+
}
|
|
119
|
+
if (message.alsoKnownAs) {
|
|
120
|
+
obj.alsoKnownAs = message.alsoKnownAs
|
|
121
|
+
}
|
|
122
|
+
if (message.service) {
|
|
123
|
+
obj.service = message.service.map((e) => e ? {id: e.id, serviceEndpoint: e.serviceEndpoint, serviceType: e.type} as Service : undefined);
|
|
124
|
+
}
|
|
125
|
+
message.versionId !== undefined && (obj.versionId = message.versionId);
|
|
126
|
+
return MsgCreateDidDocPayload.fromPartial(obj);
|
|
127
|
+
},
|
|
128
|
+
|
|
129
|
+
fromPartial<I extends Exact<DeepPartial<MsgCreateDidPayload>, I>>(object: I): MsgCreateDidPayload {
|
|
130
|
+
const message = createBaseMsgCreateDidPayload();
|
|
131
|
+
message.context = object.context?.map((e) => e) || [];
|
|
132
|
+
message.id = object.id ?? "";
|
|
133
|
+
message.controller = object.controller?.map((e) => e) || [];
|
|
134
|
+
message.verificationMethod = object.verificationMethod?.map((e) => VerificationMethodPayload.fromPartial(e)) || [];
|
|
135
|
+
message.authentication = object.authentication?.map((e) => e) || [];
|
|
136
|
+
message.assertionMethod = object.assertionMethod?.map((e) => e) || [];
|
|
137
|
+
message.capabilityInvocation = object.capabilityInvocation?.map((e) => e) || [];
|
|
138
|
+
message.capabilityDelegation = object.capabilityDelegation?.map((e) => e) || [];
|
|
139
|
+
message.keyAgreement = object.keyAgreement?.map((e) => e) || [];
|
|
140
|
+
message.alsoKnownAs = object.alsoKnownAs?.map((e) => e) || [];
|
|
141
|
+
message.service = object.service?.map((e) => ServicePayload.fromPartial(e)) || [];
|
|
142
|
+
message.versionId = object.versionId ?? "";
|
|
143
|
+
return message;
|
|
144
|
+
},
|
|
145
|
+
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function createBaseMsgCreateDidPayload(): MsgCreateDidPayload {
|
|
149
|
+
return {
|
|
150
|
+
context: [],
|
|
151
|
+
id: "",
|
|
152
|
+
controller: [],
|
|
153
|
+
verificationMethod: [],
|
|
154
|
+
authentication: [],
|
|
155
|
+
assertionMethod: [],
|
|
156
|
+
capabilityInvocation: [],
|
|
157
|
+
capabilityDelegation: [],
|
|
158
|
+
keyAgreement: [],
|
|
159
|
+
alsoKnownAs: [],
|
|
160
|
+
service: [],
|
|
161
|
+
versionId: "",
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export interface VerificationMethodPayload {
|
|
166
|
+
id: string;
|
|
167
|
+
type: string;
|
|
168
|
+
controller: string;
|
|
169
|
+
publicKeyBase58?: string;
|
|
170
|
+
publicKeyMultibase?: string;
|
|
171
|
+
publicKeyJWK?: any;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export const VerificationMethodPayload = {
|
|
175
|
+
fromPartial<I extends Exact<DeepPartial<VerificationMethodPayload>, I>>(object: I): VerificationMethodPayload {
|
|
176
|
+
const message = createBaseVerificationMethod();
|
|
177
|
+
message.id = object.id ?? "";
|
|
178
|
+
message.type = object.type ?? "";
|
|
179
|
+
message.controller = object.controller ?? "";
|
|
180
|
+
if(object.publicKeyMultibase) {
|
|
181
|
+
message.publicKeyMultibase = object.publicKeyMultibase;
|
|
182
|
+
} else if (object.publicKeyBase58) {
|
|
183
|
+
message.publicKeyBase58 = object.publicKeyBase58;
|
|
184
|
+
} else if (object.publicKeyJWK) {
|
|
185
|
+
message.publicKeyJWK = object.publicKeyJWK;
|
|
186
|
+
}
|
|
187
|
+
return message;
|
|
188
|
+
},
|
|
189
|
+
|
|
190
|
+
transformPayload<I extends Exact<DeepPartial<VerificationMethodPayload>, I>>(payload: I): VerificationMethod {
|
|
191
|
+
return {
|
|
192
|
+
id: payload.id ?? "",
|
|
193
|
+
controller: payload.controller ?? "",
|
|
194
|
+
verificationMethodType: payload.type ?? "",
|
|
195
|
+
verificationMaterial: payload.publicKeyBase58 || payload.publicKeyMultibase || JSON.stringify(payload.publicKeyJWK) || ""
|
|
196
|
+
} as VerificationMethod
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function createBaseVerificationMethod(): VerificationMethodPayload {
|
|
201
|
+
return { id: "", type: "", controller: "" };
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export interface ServicePayload {
|
|
205
|
+
id: string;
|
|
206
|
+
type: string;
|
|
207
|
+
serviceEndpoint: string[];
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export const ServicePayload = {
|
|
211
|
+
fromPartial<I extends Exact<DeepPartial<ServicePayload>, I>>(object: I): ServicePayload {
|
|
212
|
+
const message = createBaseService();
|
|
213
|
+
message.id = object.id ?? "";
|
|
214
|
+
message.type = object.type ?? "";
|
|
215
|
+
message.serviceEndpoint = object.serviceEndpoint?.map((e) => e) || [];
|
|
216
|
+
return message;
|
|
217
|
+
},
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function createBaseService(): ServicePayload {
|
|
221
|
+
return { id: "", type: "", serviceEndpoint: [] };
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export interface MsgUpdateDidPayload extends Omit<MsgUpdateDidDocPayload, 'verificationMethod' | 'service'> {
|
|
225
|
+
verificationMethod: VerificationMethodPayload[]
|
|
226
|
+
service: ServicePayload[]
|
|
227
|
+
}
|