@cheqd/sdk 1.5.0-develop.3 → 2.0.0-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.
- package/CHANGELOG.md +11 -0
- package/build/index.d.ts +4 -2
- package/build/index.d.ts.map +1 -1
- package/build/index.js +2 -0
- package/build/index.js.map +1 -1
- package/build/modules/did.d.ts +31 -4
- package/build/modules/did.d.ts.map +1 -1
- package/build/modules/did.js +163 -14
- package/build/modules/did.js.map +1 -1
- package/build/modules/resource.d.ts +22 -0
- package/build/modules/resource.d.ts.map +1 -1
- package/build/modules/resource.js +43 -3
- package/build/modules/resource.js.map +1 -1
- package/build/signer.d.ts.map +1 -1
- package/build/signer.js +0 -13
- package/build/signer.js.map +1 -1
- package/build/types.d.ts +10 -236
- package/build/types.d.ts.map +1 -1
- package/build/types.js +1 -120
- package/build/types.js.map +1 -1
- package/build/utils.d.ts +5 -5
- package/build/utils.d.ts.map +1 -1
- package/build/utils.js +70 -20
- package/build/utils.js.map +1 -1
- package/package.json +3 -2
- package/src/index.ts +5 -2
- package/src/modules/did.ts +189 -16
- package/src/modules/resource.ts +48 -2
- package/src/signer.ts +2 -17
- package/src/types.ts +14 -156
- package/src/utils.ts +85 -38
- package/tests/index.test.ts +5 -6
- package/tests/modules/did.test.ts +390 -80
- package/tests/modules/resource.test.ts +160 -27
- package/tests/signer.test.ts +55 -31
- package/tests/testutils.test.ts +3 -148
- package/tests/utils.test.ts +4 -4
package/build/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createDidPayload = exports.createDidVerificationMethod = exports.createVerificationKeys = exports.createKeyPairHex = exports.createKeyPairBase64 = exports.createKeyPairRaw = exports.createSignInputsFromImportableEd25519Key = exports.isEqualKeyValuePair = void 0;
|
|
3
|
+
exports.validateSpecCompliantPayload = exports.createDidPayload = exports.createDidVerificationMethod = exports.createVerificationKeys = exports.createKeyPairHex = exports.createKeyPairBase64 = exports.createKeyPairRaw = exports.createSignInputsFromImportableEd25519Key = exports.isEqualKeyValuePair = void 0;
|
|
4
4
|
const types_1 = require("./types");
|
|
5
5
|
const uint8arrays_1 = require("uint8arrays");
|
|
6
6
|
const basics_1 = require("multiformats/basics");
|
|
@@ -8,8 +8,8 @@ const did_jwt_1 = require("did-jwt");
|
|
|
8
8
|
const ed25519_1 = require("@stablelib/ed25519");
|
|
9
9
|
const uuid_1 = require("uuid");
|
|
10
10
|
const crypto_1 = require("crypto");
|
|
11
|
-
|
|
12
|
-
const
|
|
11
|
+
const v2_1 = require("@cheqd/ts-proto/cheqd/did/v2");
|
|
12
|
+
const MULTICODEC_ED25519_HEADER = new Uint8Array([0xed, 0x01]);
|
|
13
13
|
function isEqualKeyValuePair(kv1, kv2) {
|
|
14
14
|
return kv1.every((item, index) => item.key === kv2[index].key && item.value === kv2[index].value);
|
|
15
15
|
}
|
|
@@ -21,7 +21,7 @@ function createSignInputsFromImportableEd25519Key(key, verificationMethod) {
|
|
|
21
21
|
for (const method of verificationMethod) {
|
|
22
22
|
switch (method === null || method === void 0 ? void 0 : method.type) {
|
|
23
23
|
case types_1.VerificationMethods.Ed255192020:
|
|
24
|
-
const publicKeyMultibase =
|
|
24
|
+
const publicKeyMultibase = toMultibaseRaw(publicKey);
|
|
25
25
|
if (method.publicKeyMultibase === publicKeyMultibase) {
|
|
26
26
|
return {
|
|
27
27
|
verificationMethodId: method.id,
|
|
@@ -37,20 +37,17 @@ function createSignInputsFromImportableEd25519Key(key, verificationMethod) {
|
|
|
37
37
|
};
|
|
38
38
|
}
|
|
39
39
|
case types_1.VerificationMethods.JWK:
|
|
40
|
-
const
|
|
40
|
+
const publicKeyJwk = {
|
|
41
41
|
crv: 'Ed25519',
|
|
42
42
|
kty: 'OKP',
|
|
43
43
|
x: (0, uint8arrays_1.toString)(publicKey, 'base64url')
|
|
44
44
|
};
|
|
45
|
-
if (JSON.stringify(method.
|
|
45
|
+
if (JSON.stringify(method.publicKeyJwk) === JSON.stringify(publicKeyJwk)) {
|
|
46
46
|
return {
|
|
47
47
|
verificationMethodId: method.id,
|
|
48
48
|
privateKeyHex: key.privateKeyHex
|
|
49
49
|
};
|
|
50
50
|
}
|
|
51
|
-
else {
|
|
52
|
-
throw new Error(`JWK not matching ${method.publicKeyJWK}, ${publicKeyJWK}`);
|
|
53
|
-
}
|
|
54
51
|
}
|
|
55
52
|
}
|
|
56
53
|
throw new Error('No verification method type provided');
|
|
@@ -111,7 +108,7 @@ function createDidVerificationMethod(verificationMethodTypes, verificationKeys)
|
|
|
111
108
|
id: verificationKeys[_].keyId,
|
|
112
109
|
type,
|
|
113
110
|
controller: verificationKeys[_].didUrl,
|
|
114
|
-
publicKeyMultibase:
|
|
111
|
+
publicKeyMultibase: toMultibaseRaw((0, did_jwt_1.base64ToBytes)(verificationKeys[_].publicKey))
|
|
115
112
|
};
|
|
116
113
|
case types_1.VerificationMethods.Ed255192018:
|
|
117
114
|
return {
|
|
@@ -125,7 +122,7 @@ function createDidVerificationMethod(verificationMethodTypes, verificationKeys)
|
|
|
125
122
|
id: verificationKeys[_].keyId,
|
|
126
123
|
type,
|
|
127
124
|
controller: verificationKeys[_].didUrl,
|
|
128
|
-
|
|
125
|
+
publicKeyJwk: {
|
|
129
126
|
crv: 'Ed25519',
|
|
130
127
|
kty: 'OKP',
|
|
131
128
|
x: (0, uint8arrays_1.toString)((0, uint8arrays_1.fromString)(verificationKeys[_].publicKey, 'base64pad'), 'base64url')
|
|
@@ -141,23 +138,76 @@ function createDidPayload(verificationMethods, verificationKeys) {
|
|
|
141
138
|
if (!verificationKeys || verificationKeys.length === 0)
|
|
142
139
|
throw new Error('No verification keys provided');
|
|
143
140
|
const did = verificationKeys[0].didUrl;
|
|
144
|
-
return
|
|
141
|
+
return {
|
|
145
142
|
id: did,
|
|
146
143
|
controller: verificationKeys.map(key => key.didUrl),
|
|
147
144
|
verificationMethod: verificationMethods,
|
|
148
145
|
authentication: verificationKeys.map(key => key.keyId),
|
|
149
|
-
|
|
150
|
-
});
|
|
146
|
+
};
|
|
151
147
|
}
|
|
152
148
|
exports.createDidPayload = createDidPayload;
|
|
149
|
+
function validateSpecCompliantPayload(didDocument) {
|
|
150
|
+
var _a;
|
|
151
|
+
// id is required, validated on both compile and runtime
|
|
152
|
+
if (!(didDocument === null || didDocument === void 0 ? void 0 : didDocument.id))
|
|
153
|
+
return { valid: false, error: 'id is required' };
|
|
154
|
+
// verificationMethod is required
|
|
155
|
+
if (!(didDocument === null || didDocument === void 0 ? void 0 : didDocument.verificationMethod))
|
|
156
|
+
return { valid: false, error: 'verificationMethod is required' };
|
|
157
|
+
// verificationMethod must be an array
|
|
158
|
+
if (!Array.isArray(didDocument === null || didDocument === void 0 ? void 0 : didDocument.verificationMethod))
|
|
159
|
+
return { valid: false, error: 'verificationMethod must be an array' };
|
|
160
|
+
// verificationMethod types must be supported
|
|
161
|
+
const protoVerificationMethod = didDocument.verificationMethod.map((vm) => {
|
|
162
|
+
switch (vm === null || vm === void 0 ? void 0 : vm.type) {
|
|
163
|
+
case types_1.VerificationMethods.Ed255192020:
|
|
164
|
+
if (!vm.publicKeyMultibase)
|
|
165
|
+
throw new Error('publicKeyMultibase is required');
|
|
166
|
+
return v2_1.VerificationMethod.fromPartial({
|
|
167
|
+
id: vm.id,
|
|
168
|
+
controller: vm.controller,
|
|
169
|
+
verificationMethodType: types_1.VerificationMethods.Ed255192020,
|
|
170
|
+
verificationMaterial: vm.publicKeyMultibase,
|
|
171
|
+
});
|
|
172
|
+
case types_1.VerificationMethods.JWK:
|
|
173
|
+
if (!vm.publicKeyJwk)
|
|
174
|
+
throw new Error('publicKeyJwk is required');
|
|
175
|
+
return v2_1.VerificationMethod.fromPartial({
|
|
176
|
+
id: vm.id,
|
|
177
|
+
controller: vm.controller,
|
|
178
|
+
verificationMethodType: types_1.VerificationMethods.JWK,
|
|
179
|
+
verificationMaterial: JSON.stringify(vm.publicKeyJwk),
|
|
180
|
+
});
|
|
181
|
+
case types_1.VerificationMethods.Ed255192018:
|
|
182
|
+
if (!vm.publicKeyBase58)
|
|
183
|
+
throw new Error('publicKeyBase58 is required');
|
|
184
|
+
return v2_1.VerificationMethod.fromPartial({
|
|
185
|
+
id: vm.id,
|
|
186
|
+
controller: vm.controller,
|
|
187
|
+
verificationMethodType: types_1.VerificationMethods.Ed255192018,
|
|
188
|
+
verificationMaterial: vm.publicKeyBase58,
|
|
189
|
+
});
|
|
190
|
+
default:
|
|
191
|
+
throw new Error(`Unsupported verificationMethod type: ${vm === null || vm === void 0 ? void 0 : vm.type}`);
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
const protoService = (_a = didDocument === null || didDocument === void 0 ? void 0 : didDocument.service) === null || _a === void 0 ? void 0 : _a.map((s) => {
|
|
195
|
+
return v2_1.Service.fromPartial({
|
|
196
|
+
id: s === null || s === void 0 ? void 0 : s.id,
|
|
197
|
+
serviceType: s === null || s === void 0 ? void 0 : s.type,
|
|
198
|
+
serviceEndpoint: s === null || s === void 0 ? void 0 : s.serviceEndpoint,
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
return { valid: true, protobufVerificationMethod: protoVerificationMethod, protobufService: protoService };
|
|
202
|
+
}
|
|
203
|
+
exports.validateSpecCompliantPayload = validateSpecCompliantPayload;
|
|
153
204
|
function sha256(message) {
|
|
154
205
|
return (0, crypto_1.createHash)('sha256').update(message).digest('hex');
|
|
155
206
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
return basics_1.bases['base58btc'].encode(mbKey);
|
|
207
|
+
function toMultibaseRaw(key) {
|
|
208
|
+
const multibase = new Uint8Array(MULTICODEC_ED25519_HEADER.length + key.length);
|
|
209
|
+
multibase.set(MULTICODEC_ED25519_HEADER);
|
|
210
|
+
multibase.set(key, MULTICODEC_ED25519_HEADER.length);
|
|
211
|
+
return basics_1.bases['base58btc'].encode(multibase);
|
|
162
212
|
}
|
|
163
213
|
//# sourceMappingURL=utils.js.map
|
package/build/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAAA,mCAegB;AAChB,6CAAkD;AAClD,gDAA2C;AAC3C,qCAAuC;AACvC,gDAAsF;AACtF,+BAAyB;AACzB,mCAAmC;AACnC,qDAGqC;AASrC,MAAM,yBAAyB,GAAG,IAAI,UAAU,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;AAE/D,SAAgB,mBAAmB,CAAC,GAAoB,EAAE,GAAoB;IAC1E,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,KAAK,GAAG,CAAC,KAAK,CAAC,CAAC,GAAG,IAAI,IAAI,CAAC,KAAK,KAAK,GAAG,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAA;AACrG,CAAC;AAFD,kDAEC;AAED,SAAgB,wCAAwC,CAAC,GAA0B,EAAE,kBAAwC;IACzH,IAAI,CAAA,kBAAkB,aAAlB,kBAAkB,uBAAlB,kBAAkB,CAAE,MAAM,MAAK,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAA;IAEzF,MAAM,SAAS,GAAG,IAAA,wBAAU,EAAC,GAAG,CAAC,YAAY,EAAE,KAAK,CAAC,CAAA;IAErD,KAAI,MAAM,MAAM,IAAI,kBAAkB,EAAE;QACpC,QAAQ,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,IAAI,EAAE;YAClB,KAAK,2BAAmB,CAAC,WAAW;gBAChC,MAAM,kBAAkB,GAAG,cAAc,CAAC,SAAS,CAAC,CAAA;gBACpD,IAAI,MAA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AC;AAED,SAAS,cAAc,CAAC,GAAe;IACnC,MAAM,SAAS,GAAG,IAAI,UAAU,CAAC,yBAAyB,CAAC,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC;IAEhF,SAAS,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC;IACzC,SAAS,CAAC,GAAG,CAAC,GAAG,EAAE,yBAAyB,CAAC,MAAM,CAAC,CAAC;IAErD,OAAO,cAAK,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;AAChD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cheqd/sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-develop.1",
|
|
4
4
|
"description": "A TypeScript SDK built with CosmJS to interact with cheqd network ledger",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Cheqd Foundation Limited (https://github.com/cheqd)",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
},
|
|
27
27
|
"homepage": "https://github.com/cheqd/sdk#readme",
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@cheqd/ts-proto": "^
|
|
29
|
+
"@cheqd/ts-proto": "^2.0.0-develop.1",
|
|
30
30
|
"@cosmjs/amino": "^0.29.4",
|
|
31
31
|
"@cosmjs/encoding": "^0.29.4",
|
|
32
32
|
"@cosmjs/math": "^0.29.4",
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
"@stablelib/ed25519": "^1.0.3",
|
|
38
38
|
"cosmjs-types": "^0.5.2",
|
|
39
39
|
"did-jwt": "^6.9.0",
|
|
40
|
+
"did-resolver": "^4.0.1",
|
|
40
41
|
"multiformats": "^9.9.0",
|
|
41
42
|
"uuid": "^9.0.0"
|
|
42
43
|
},
|
package/src/index.ts
CHANGED
|
@@ -6,12 +6,14 @@ import { createDefaultCheqdRegistry } from './registry'
|
|
|
6
6
|
import { CheqdSigningStargateClient } from './signer'
|
|
7
7
|
import { CheqdNetwork, IContext, IModuleMethodMap } from './types'
|
|
8
8
|
import { createSignInputsFromImportableEd25519Key } from './utils'
|
|
9
|
+
import { GasPrice } from '@cosmjs/stargate'
|
|
9
10
|
|
|
10
11
|
export interface ICheqdSDKOptions {
|
|
11
12
|
modules: AbstractCheqdSDKModule[]
|
|
12
|
-
authorizedMethods?: string[]
|
|
13
|
-
network?: CheqdNetwork
|
|
14
13
|
rpcUrl: string
|
|
14
|
+
network?: CheqdNetwork
|
|
15
|
+
gasPrice?: GasPrice
|
|
16
|
+
authorizedMethods?: string[]
|
|
15
17
|
readonly wallet: OfflineSigner
|
|
16
18
|
}
|
|
17
19
|
|
|
@@ -78,6 +80,7 @@ export class CheqdSDK {
|
|
|
78
80
|
this.options.wallet,
|
|
79
81
|
{
|
|
80
82
|
registry,
|
|
83
|
+
gasPrice: this.options?.gasPrice,
|
|
81
84
|
}
|
|
82
85
|
)
|
|
83
86
|
|
package/src/modules/did.ts
CHANGED
|
@@ -2,26 +2,41 @@ import { createProtobufRpcClient, DeliverTxResponse, QueryClient } from "@cosmjs
|
|
|
2
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,
|
|
5
|
+
import { DIDDocument, DidStdFee, IContext, ISignInputs, SpecValidationResult, VerificationMethods } from '../types';
|
|
6
6
|
import {
|
|
7
7
|
MsgCreateDidDoc,
|
|
8
|
+
MsgCreateDidDocPayload,
|
|
8
9
|
MsgCreateDidDocResponse,
|
|
9
10
|
MsgDeactivateDidDoc,
|
|
10
11
|
MsgDeactivateDidDocPayload,
|
|
11
12
|
MsgDeactivateDidDocResponse,
|
|
12
13
|
MsgUpdateDidDoc,
|
|
14
|
+
MsgUpdateDidDocPayload,
|
|
13
15
|
MsgUpdateDidDocResponse,
|
|
14
16
|
protobufPackage,
|
|
15
|
-
|
|
17
|
+
Service,
|
|
18
|
+
SignInfo,
|
|
19
|
+
VerificationMethod
|
|
16
20
|
} from "@cheqd/ts-proto/cheqd/did/v2"
|
|
17
21
|
import { EncodeObject, GeneratedType } from "@cosmjs/proto-signing"
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
export const
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
import { v4 } from "uuid"
|
|
23
|
+
import { Coin } from "cosmjs-types/cosmos/base/v1beta1/coin";
|
|
24
|
+
import { Int53 } from "@cosmjs/math";
|
|
25
|
+
|
|
26
|
+
export const protobufLiterals = {
|
|
27
|
+
MsgCreateDidDoc: "MsgCreateDidDoc",
|
|
28
|
+
MsgCreateDidDocResponse: "MsgCreateDidDocResponse",
|
|
29
|
+
MsgUpdateDidDoc: "MsgUpdateDidDoc",
|
|
30
|
+
MsgUpdateDidDocResponse: "MsgUpdateDidDocResponse",
|
|
31
|
+
MsgDeactivateDidDoc: "MsgDeactivateDidDoc",
|
|
32
|
+
MsgDeactivateDidDocResponse: "MsgDeactivateDidDocResponse",
|
|
33
|
+
} as const
|
|
34
|
+
export const typeUrlMsgCreateDidDoc = `/${protobufPackage}.${protobufLiterals.MsgCreateDidDoc}`
|
|
35
|
+
export const typeUrlMsgCreateDidDocResponse = `/${protobufPackage}.${protobufLiterals.MsgCreateDidDocResponse}`
|
|
36
|
+
export const typeUrlMsgUpdateDidDoc = `/${protobufPackage}.${protobufLiterals.MsgUpdateDidDoc}`
|
|
37
|
+
export const typeUrlMsgUpdateDidDocResponse = `/${protobufPackage}.${protobufLiterals.MsgUpdateDidDocResponse}`
|
|
38
|
+
export const typeUrlMsgDeactivateDidDoc = `/${protobufPackage}.${protobufLiterals.MsgDeactivateDidDoc}`
|
|
39
|
+
export const typeUrlMsgDeactivateDidDocResponse = `/${protobufPackage}.${protobufLiterals.MsgDeactivateDidDocResponse}`
|
|
25
40
|
|
|
26
41
|
export interface MsgCreateDidDocEncodeObject extends EncodeObject {
|
|
27
42
|
readonly typeUrl: typeof typeUrlMsgCreateDidDoc,
|
|
@@ -87,6 +102,14 @@ export class DIDModule extends AbstractCheqdSDKModule {
|
|
|
87
102
|
[typeUrlMsgDeactivateDidDocResponse, MsgDeactivateDidDocResponse],
|
|
88
103
|
]
|
|
89
104
|
|
|
105
|
+
static readonly baseMinimalDenom = 'ncheq' as const
|
|
106
|
+
|
|
107
|
+
static readonly fees = {
|
|
108
|
+
DefaultCreateDidFee: { amount: '50000000000', denom: DIDModule.baseMinimalDenom } as const,
|
|
109
|
+
DefaultUpdateDidFee: { amount: '25000000000', denom: DIDModule.baseMinimalDenom } as const,
|
|
110
|
+
DefaultDeactivateDidFee: { amount: '10000000000', denom: DIDModule.baseMinimalDenom } as const,
|
|
111
|
+
} as const
|
|
112
|
+
|
|
90
113
|
constructor(signer: CheqdSigningStargateClient) {
|
|
91
114
|
super(signer)
|
|
92
115
|
this.methods = {
|
|
@@ -100,12 +123,36 @@ export class DIDModule extends AbstractCheqdSDKModule {
|
|
|
100
123
|
return DIDModule.registryTypes
|
|
101
124
|
}
|
|
102
125
|
|
|
103
|
-
async createDidTx(signInputs: ISignInputs[] | SignInfo[], didPayload:
|
|
126
|
+
async createDidTx(signInputs: ISignInputs[] | SignInfo[], didPayload: DIDDocument, address: string, fee: DidStdFee | 'auto' | number, memo?: string, versionId?: string, context?: IContext): Promise<DeliverTxResponse> {
|
|
104
127
|
if (!this._signer) {
|
|
105
128
|
this._signer = context!.sdk!.signer
|
|
106
129
|
}
|
|
107
130
|
|
|
108
|
-
|
|
131
|
+
if (!versionId || versionId === '') {
|
|
132
|
+
versionId = v4()
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const { valid, error, protobufVerificationMethod, protobufService } = await DIDModule.validateSpecCompliantPayload(didPayload)
|
|
136
|
+
|
|
137
|
+
if (!valid) {
|
|
138
|
+
throw new Error(`DID payload is not spec compliant: ${error}`)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const payload = MsgCreateDidDocPayload.fromPartial({
|
|
142
|
+
context: <string[]>didPayload?.['@context'],
|
|
143
|
+
id: didPayload.id,
|
|
144
|
+
controller: <string[]>didPayload.controller,
|
|
145
|
+
verificationMethod: protobufVerificationMethod,
|
|
146
|
+
authentication: <string[]>didPayload.authentication,
|
|
147
|
+
assertionMethod: <string[]>didPayload.assertionMethod,
|
|
148
|
+
capabilityInvocation: <string[]>didPayload.capabilityInvocation,
|
|
149
|
+
capabilityDelegation: <string[]>didPayload.capabilityDelegation,
|
|
150
|
+
keyAgreement: <string[]>didPayload.keyAgreement,
|
|
151
|
+
service: protobufService,
|
|
152
|
+
alsoKnownAs: <string[]>didPayload.alsoKnownAs,
|
|
153
|
+
versionId: versionId
|
|
154
|
+
})
|
|
155
|
+
|
|
109
156
|
let signatures: SignInfo[]
|
|
110
157
|
if(ISignInputs.isSignInput(signInputs)) {
|
|
111
158
|
signatures = await this._signer.signCreateDidTx(signInputs, payload)
|
|
@@ -131,12 +178,35 @@ export class DIDModule extends AbstractCheqdSDKModule {
|
|
|
131
178
|
)
|
|
132
179
|
}
|
|
133
180
|
|
|
134
|
-
async updateDidTx(signInputs: ISignInputs[] | SignInfo[], didPayload:
|
|
181
|
+
async updateDidTx(signInputs: ISignInputs[] | SignInfo[], didPayload: DIDDocument, address: string, fee: DidStdFee | 'auto' | number, memo?: string, versionId?: string, context?: IContext): Promise<DeliverTxResponse> {
|
|
135
182
|
if (!this._signer) {
|
|
136
183
|
this._signer = context!.sdk!.signer
|
|
137
184
|
}
|
|
138
185
|
|
|
139
|
-
|
|
186
|
+
if (!versionId || versionId === '') {
|
|
187
|
+
versionId = v4()
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const { valid, error, protobufVerificationMethod, protobufService } = await DIDModule.validateSpecCompliantPayload(didPayload)
|
|
191
|
+
|
|
192
|
+
if (!valid) {
|
|
193
|
+
throw new Error(`DID payload is not spec compliant: ${error}`)
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const payload = MsgUpdateDidDocPayload.fromPartial({
|
|
197
|
+
context: <string[]>didPayload?.['@context'],
|
|
198
|
+
id: didPayload.id,
|
|
199
|
+
controller: <string[]>didPayload.controller,
|
|
200
|
+
verificationMethod: protobufVerificationMethod,
|
|
201
|
+
authentication: <string[]>didPayload.authentication,
|
|
202
|
+
assertionMethod: <string[]>didPayload.assertionMethod,
|
|
203
|
+
capabilityInvocation: <string[]>didPayload.capabilityInvocation,
|
|
204
|
+
capabilityDelegation: <string[]>didPayload.capabilityDelegation,
|
|
205
|
+
keyAgreement: <string[]>didPayload.keyAgreement,
|
|
206
|
+
service: protobufService,
|
|
207
|
+
alsoKnownAs: <string[]>didPayload.alsoKnownAs,
|
|
208
|
+
versionId: versionId
|
|
209
|
+
})
|
|
140
210
|
let signatures: SignInfo[]
|
|
141
211
|
if(ISignInputs.isSignInput(signInputs)) {
|
|
142
212
|
signatures = await this._signer.signUpdateDidTx(signInputs, payload)
|
|
@@ -162,15 +232,29 @@ export class DIDModule extends AbstractCheqdSDKModule {
|
|
|
162
232
|
)
|
|
163
233
|
}
|
|
164
234
|
|
|
165
|
-
async deactivateDidTx(signInputs: ISignInputs[] | SignInfo[], didPayload:
|
|
235
|
+
async deactivateDidTx(signInputs: ISignInputs[] | SignInfo[], didPayload: DIDDocument, address: string, fee: DidStdFee | 'auto' | number, memo?: string, versionId?: string, context?: IContext): Promise<DeliverTxResponse> {
|
|
166
236
|
if (!this._signer) {
|
|
167
237
|
this._signer = context!.sdk!.signer
|
|
168
238
|
}
|
|
169
239
|
|
|
170
|
-
|
|
240
|
+
if (!versionId || versionId === '') {
|
|
241
|
+
versionId = v4()
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
const { valid, error, protobufVerificationMethod } = await DIDModule.validateSpecCompliantPayload(didPayload)
|
|
245
|
+
|
|
246
|
+
if (!valid) {
|
|
247
|
+
throw new Error(`DID payload is not spec compliant: ${error}`)
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const payload = MsgDeactivateDidDocPayload.fromPartial({
|
|
251
|
+
id: didPayload.id,
|
|
252
|
+
versionId: versionId
|
|
253
|
+
})
|
|
254
|
+
|
|
171
255
|
let signatures: SignInfo[]
|
|
172
256
|
if(ISignInputs.isSignInput(signInputs)) {
|
|
173
|
-
signatures = await this._signer.signDeactivateDidTx(signInputs, payload,
|
|
257
|
+
signatures = await this._signer.signDeactivateDidTx(signInputs, payload, protobufVerificationMethod!)
|
|
174
258
|
} else {
|
|
175
259
|
signatures = signInputs
|
|
176
260
|
}
|
|
@@ -192,6 +276,95 @@ export class DIDModule extends AbstractCheqdSDKModule {
|
|
|
192
276
|
memo
|
|
193
277
|
)
|
|
194
278
|
}
|
|
279
|
+
|
|
280
|
+
static async validateSpecCompliantPayload(didDocument: DIDDocument): Promise<SpecValidationResult> {
|
|
281
|
+
// id is required, validated on both compile and runtime
|
|
282
|
+
if (!didDocument?.id) return { valid: false, error: 'id is required' }
|
|
283
|
+
|
|
284
|
+
// verificationMethod is required
|
|
285
|
+
if (!didDocument?.verificationMethod) return { valid: false, error: 'verificationMethod is required' }
|
|
286
|
+
|
|
287
|
+
// verificationMethod must be an array
|
|
288
|
+
if (!Array.isArray(didDocument?.verificationMethod)) return { valid: false, error: 'verificationMethod must be an array' }
|
|
289
|
+
|
|
290
|
+
// verificationMethod types must be supported
|
|
291
|
+
const protoVerificationMethod = didDocument.verificationMethod.map((vm) => {
|
|
292
|
+
switch (vm?.type) {
|
|
293
|
+
case VerificationMethods.Ed255192020:
|
|
294
|
+
if (!vm?.publicKeyMultibase) throw new Error('publicKeyMultibase is required')
|
|
295
|
+
|
|
296
|
+
return VerificationMethod.fromPartial({
|
|
297
|
+
id: vm.id,
|
|
298
|
+
controller: vm.controller,
|
|
299
|
+
verificationMethodType: VerificationMethods.Ed255192020,
|
|
300
|
+
verificationMaterial: vm.publicKeyMultibase,
|
|
301
|
+
})
|
|
302
|
+
case VerificationMethods.JWK:
|
|
303
|
+
if (!vm?.publicKeyJwk) throw new Error('publicKeyJwk is required')
|
|
304
|
+
|
|
305
|
+
return VerificationMethod.fromPartial({
|
|
306
|
+
id: vm.id,
|
|
307
|
+
controller: vm.controller,
|
|
308
|
+
verificationMethodType: VerificationMethods.JWK,
|
|
309
|
+
verificationMaterial: JSON.stringify(vm.publicKeyJwk),
|
|
310
|
+
})
|
|
311
|
+
case VerificationMethods.Ed255192018:
|
|
312
|
+
if (!vm?.publicKeyBase58) throw new Error('publicKeyBase58 is required')
|
|
313
|
+
|
|
314
|
+
return VerificationMethod.fromPartial({
|
|
315
|
+
id: vm.id,
|
|
316
|
+
controller: vm.controller,
|
|
317
|
+
verificationMethodType: VerificationMethods.Ed255192018,
|
|
318
|
+
verificationMaterial: vm.publicKeyBase58,
|
|
319
|
+
})
|
|
320
|
+
default:
|
|
321
|
+
throw new Error('Unsupported verificationMethod type')
|
|
322
|
+
}
|
|
323
|
+
})
|
|
324
|
+
|
|
325
|
+
const protoService = didDocument?.service?.map((s) => {
|
|
326
|
+
return Service.fromPartial({
|
|
327
|
+
id: s?.id,
|
|
328
|
+
serviceType: s?.type,
|
|
329
|
+
serviceEndpoint: <string[]>s?.serviceEndpoint,
|
|
330
|
+
})
|
|
331
|
+
})
|
|
332
|
+
|
|
333
|
+
return { valid: true, protobufVerificationMethod: protoVerificationMethod, protobufService: protoService } as SpecValidationResult
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
static async generateCreateDidDocFees(feePayer: string, granter?: string): Promise<DidStdFee> {
|
|
337
|
+
return {
|
|
338
|
+
amount: [
|
|
339
|
+
DIDModule.fees.DefaultCreateDidFee
|
|
340
|
+
],
|
|
341
|
+
gas: '360000',
|
|
342
|
+
payer: feePayer,
|
|
343
|
+
granter: granter
|
|
344
|
+
} as DidStdFee
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
static async generateUpdateDidDocFees(feePayer: string, granter?: string): Promise<DidStdFee> {
|
|
348
|
+
return {
|
|
349
|
+
amount: [
|
|
350
|
+
DIDModule.fees.DefaultUpdateDidFee
|
|
351
|
+
],
|
|
352
|
+
gas: '360000',
|
|
353
|
+
payer: feePayer,
|
|
354
|
+
granter: granter
|
|
355
|
+
} as DidStdFee
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
static async generateDeactivateDidDocFees(feePayer: string, granter?: string): Promise<DidStdFee> {
|
|
359
|
+
return {
|
|
360
|
+
amount: [
|
|
361
|
+
DIDModule.fees.DefaultDeactivateDidFee
|
|
362
|
+
],
|
|
363
|
+
gas: '360000',
|
|
364
|
+
payer: feePayer,
|
|
365
|
+
granter: granter
|
|
366
|
+
} as DidStdFee
|
|
367
|
+
}
|
|
195
368
|
}
|
|
196
369
|
|
|
197
370
|
export type MinimalImportableDIDModule = MinimalImportableCheqdSDKModule<DIDModule>
|
package/src/modules/resource.ts
CHANGED
|
@@ -6,8 +6,13 @@ import { MsgCreateResource, MsgCreateResourcePayload, MsgCreateResourceResponse,
|
|
|
6
6
|
import { DeliverTxResponse } from "@cosmjs/stargate"
|
|
7
7
|
import { SignInfo } from "@cheqd/ts-proto/cheqd/did/v2";
|
|
8
8
|
|
|
9
|
-
export const
|
|
10
|
-
|
|
9
|
+
export const protobufLiterals = {
|
|
10
|
+
MsgCreateResource: 'MsgCreateResource',
|
|
11
|
+
MsgCreateResourceResponse: 'MsgCreateResourceResponse'
|
|
12
|
+
} as const
|
|
13
|
+
|
|
14
|
+
export const typeUrlMsgCreateResource = `/${protobufPackage}.${protobufLiterals.MsgCreateResource}`
|
|
15
|
+
export const typeUrlMsgCreateResourceResponse = `/${protobufPackage}.${protobufLiterals.MsgCreateResourceResponse}`
|
|
11
16
|
|
|
12
17
|
export interface MsgCreateResourceEncodeObject extends EncodeObject {
|
|
13
18
|
readonly typeUrl: typeof typeUrlMsgCreateResource,
|
|
@@ -24,6 +29,14 @@ export class ResourceModule extends AbstractCheqdSDKModule {
|
|
|
24
29
|
[typeUrlMsgCreateResourceResponse, MsgCreateResourceResponse]
|
|
25
30
|
]
|
|
26
31
|
|
|
32
|
+
static readonly baseMinimalDenom = 'ncheq' as const
|
|
33
|
+
|
|
34
|
+
static readonly fees = {
|
|
35
|
+
DefaultCreateResourceImageFee: { amount: '10000000000', denom: ResourceModule.baseMinimalDenom } as const,
|
|
36
|
+
DefaultCreateResourceJsonFee: { amount: '2500000000', denom: ResourceModule.baseMinimalDenom } as const,
|
|
37
|
+
DefaultCreateResourceDefaultFee: { amount: '5000000000', denom: ResourceModule.baseMinimalDenom } as const,
|
|
38
|
+
} as const
|
|
39
|
+
|
|
27
40
|
constructor(signer: CheqdSigningStargateClient) {
|
|
28
41
|
super(signer)
|
|
29
42
|
this.methods = {
|
|
@@ -71,6 +84,39 @@ export class ResourceModule extends AbstractCheqdSDKModule {
|
|
|
71
84
|
memo
|
|
72
85
|
)
|
|
73
86
|
}
|
|
87
|
+
|
|
88
|
+
static async generateCreateResourceImageFees(feePayer: string, granter?: string): Promise<DidStdFee> {
|
|
89
|
+
return {
|
|
90
|
+
amount: [
|
|
91
|
+
ResourceModule.fees.DefaultCreateResourceImageFee
|
|
92
|
+
],
|
|
93
|
+
gas: '360000',
|
|
94
|
+
payer: feePayer,
|
|
95
|
+
granter: granter
|
|
96
|
+
} as DidStdFee
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
static async generateCreateResourceJsonFees(feePayer: string, granter?: string): Promise<DidStdFee> {
|
|
100
|
+
return {
|
|
101
|
+
amount: [
|
|
102
|
+
ResourceModule.fees.DefaultCreateResourceJsonFee
|
|
103
|
+
],
|
|
104
|
+
gas: '360000',
|
|
105
|
+
payer: feePayer,
|
|
106
|
+
granter: granter
|
|
107
|
+
} as DidStdFee
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
static async generateCreateResourceDefaultFees(feePayer: string, granter?: string): Promise<DidStdFee> {
|
|
111
|
+
return {
|
|
112
|
+
amount: [
|
|
113
|
+
ResourceModule.fees.DefaultCreateResourceDefaultFee
|
|
114
|
+
],
|
|
115
|
+
gas: '360000',
|
|
116
|
+
payer: feePayer,
|
|
117
|
+
granter: granter
|
|
118
|
+
} as DidStdFee
|
|
119
|
+
}
|
|
74
120
|
}
|
|
75
121
|
|
|
76
122
|
export type MinimalImportableResourcesModule = MinimalImportableCheqdSDKModule<ResourceModule>
|
package/src/signer.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { CheqdExtensions } from './modules/_'
|
|
2
2
|
import { EncodeObject, isOfflineDirectSigner, OfflineSigner, encodePubkey, TxBodyEncodeObject, makeSignDoc } from "@cosmjs/proto-signing"
|
|
3
|
-
import { DeliverTxResponse, GasPrice, HttpEndpoint,
|
|
3
|
+
import { DeliverTxResponse, GasPrice, HttpEndpoint, SigningStargateClient, SigningStargateClientOptions, calculateFee, SignerData } from "@cosmjs/stargate"
|
|
4
4
|
import { Tendermint34Client } from "@cosmjs/tendermint-rpc"
|
|
5
5
|
import { createDefaultCheqdRegistry } from "./registry"
|
|
6
6
|
import { MsgCreateDidDocPayload, SignInfo, MsgUpdateDidDocPayload, MsgDeactivateDidDocPayload, VerificationMethod } from '@cheqd/ts-proto/cheqd/did/v2';
|
|
7
|
-
import { DidStdFee, ISignInputs, TSignerAlgo,
|
|
7
|
+
import { DidStdFee, ISignInputs, TSignerAlgo, VerificationMethods } from './types';
|
|
8
8
|
import { base64ToBytes, EdDSASigner, hexToBytes, Signer, ES256Signer, ES256KSigner } from 'did-jwt';
|
|
9
9
|
import { assert, assertDefined } from '@cosmjs/utils'
|
|
10
10
|
import { encodeSecp256k1Pubkey } from '@cosmjs/amino'
|
|
@@ -50,8 +50,6 @@ export function makeDidAuthInfoBytes(
|
|
|
50
50
|
payer: feePayer
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
|
-
//* There is a `Long` type incompatibility in the protobuf library that causes the following line to throw an error. No actual type mismatch is ever encountered.
|
|
54
|
-
// @ts-ignore
|
|
55
53
|
return AuthInfo.encode(AuthInfo.fromPartial(authInfo)).finish()
|
|
56
54
|
}
|
|
57
55
|
|
|
@@ -78,11 +76,6 @@ export class CheqdSigningStargateClient extends SigningStargateClient {
|
|
|
78
76
|
super(tmClient, signer, options)
|
|
79
77
|
this._signer = signer
|
|
80
78
|
if (options.gasPrice) this._gasPrice = options.gasPrice
|
|
81
|
-
/** GRPC Connection */
|
|
82
|
-
|
|
83
|
-
/* if (tmClient) {
|
|
84
|
-
this.cheqdExtensions = QueryClient.withExtensions(tmClient, setupCheqdExtensions)
|
|
85
|
-
} */
|
|
86
79
|
}
|
|
87
80
|
|
|
88
81
|
async signAndBroadcast(
|
|
@@ -129,11 +122,6 @@ export class CheqdSigningStargateClient extends SigningStargateClient {
|
|
|
129
122
|
}
|
|
130
123
|
|
|
131
124
|
return this._signDirect(signerAddress, messages, fee, memo, signerData)
|
|
132
|
-
|
|
133
|
-
// TODO: override signAmino as well
|
|
134
|
-
/* return isOfflineDirectSigner(this._signer)
|
|
135
|
-
? this._signDirect(signerAddress, messages, fee, memo, signerData)
|
|
136
|
-
: this._signAmino(signerAddress, messages, fee, memo, signerData) */
|
|
137
125
|
}
|
|
138
126
|
|
|
139
127
|
private async _signDirect(
|
|
@@ -203,7 +191,6 @@ export class CheqdSigningStargateClient extends SigningStargateClient {
|
|
|
203
191
|
const signInfos: SignInfo[] = await Promise.all(signInputs.map(async (signInput) => {
|
|
204
192
|
return {
|
|
205
193
|
verificationMethodId: signInput.verificationMethodId,
|
|
206
|
-
// TODO: We can't rely on `payload.verificationMethod` here because `CreateResourceTx` doesn't have it
|
|
207
194
|
signature: base64ToBytes((await (await this.getDidSigner(signInput.verificationMethodId, payload.verificationMethod))(hexToBytes(signInput.privateKeyHex))(signBytes)) as string)
|
|
208
195
|
}
|
|
209
196
|
}))
|
|
@@ -218,7 +205,6 @@ export class CheqdSigningStargateClient extends SigningStargateClient {
|
|
|
218
205
|
const signInfos: SignInfo[] = await Promise.all(signInputs.map(async (signInput) => {
|
|
219
206
|
return {
|
|
220
207
|
verificationMethodId: signInput.verificationMethodId,
|
|
221
|
-
// TODO: We can't rely on `payload.verificationMethod` here because `CreateResourceTx` doesn't have it
|
|
222
208
|
signature: base64ToBytes((await (await this.getDidSigner(signInput.verificationMethodId, payload.verificationMethod))(hexToBytes(signInput.privateKeyHex))(signBytes)) as string)
|
|
223
209
|
}
|
|
224
210
|
}))
|
|
@@ -233,7 +219,6 @@ export class CheqdSigningStargateClient extends SigningStargateClient {
|
|
|
233
219
|
const signInfos: SignInfo[] = await Promise.all(signInputs.map(async (signInput) => {
|
|
234
220
|
return {
|
|
235
221
|
verificationMethodId: signInput.verificationMethodId,
|
|
236
|
-
// TODO: We can't rely on `payload.verificationMethod` here because `CreateResourceTx` doesn't have it
|
|
237
222
|
signature: base64ToBytes((await (await this.getDidSigner(signInput.verificationMethodId, verificationMethod))(hexToBytes(signInput.privateKeyHex))(signBytes)) as string)
|
|
238
223
|
}
|
|
239
224
|
}))
|