@cheqd/sdk 1.5.0-develop.1 → 1.5.0-develop.3
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/test.yml +7 -3
- package/CHANGELOG.md +14 -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 +5 -5
- package/build/modules/did.d.ts.map +1 -1
- package/build/modules/did.js +26 -5
- package/build/modules/did.js.map +1 -1
- package/build/modules/resource.d.ts +3 -2
- package/build/modules/resource.d.ts.map +1 -1
- package/build/modules/resource.js +8 -1
- package/build/modules/resource.js.map +1 -1
- package/build/signer.d.ts.map +1 -1
- package/build/signer.js +5 -5
- package/build/signer.js.map +1 -1
- package/build/types.d.ts +237 -3
- 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 +6 -14
- package/build/utils.d.ts.map +1 -1
- package/build/utils.js +46 -69
- package/build/utils.js.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +1 -3
- package/src/modules/did.ts +28 -12
- package/src/modules/resource.ts +9 -3
- package/src/signer.ts +6 -6
- package/src/types.ts +157 -4
- package/src/utils.ts +56 -82
- package/tests/modules/did.test.ts +66 -8
- package/tests/modules/resource.test.ts +1 -1
- package/tests/signer.test.ts +16 -13
- package/tests/testutils.test.ts +34 -22
- package/tests/utils.test.ts +22 -2
package/build/utils.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const v2_1 = require("@cheqd/ts-proto/cheqd/did/v2");
|
|
3
|
+
exports.createDidPayload = exports.createDidVerificationMethod = exports.createVerificationKeys = exports.createKeyPairHex = exports.createKeyPairBase64 = exports.createKeyPairRaw = exports.createSignInputsFromImportableEd25519Key = exports.isEqualKeyValuePair = void 0;
|
|
5
4
|
const types_1 = require("./types");
|
|
6
5
|
const uint8arrays_1 = require("uint8arrays");
|
|
7
6
|
const basics_1 = require("multiformats/basics");
|
|
@@ -21,9 +20,17 @@ function createSignInputsFromImportableEd25519Key(key, verificationMethod) {
|
|
|
21
20
|
const publicKey = (0, uint8arrays_1.fromString)(key.publicKeyHex, 'hex');
|
|
22
21
|
for (const method of verificationMethod) {
|
|
23
22
|
switch (method === null || method === void 0 ? void 0 : method.type) {
|
|
24
|
-
case types_1.VerificationMethods.
|
|
25
|
-
const publicKeyMultibase =
|
|
26
|
-
if (
|
|
23
|
+
case types_1.VerificationMethods.Ed255192020:
|
|
24
|
+
const publicKeyMultibase = _encodeMbKey(MULTICODEC_ED25519_PUB_HEADER, publicKey);
|
|
25
|
+
if (method.publicKeyMultibase === publicKeyMultibase) {
|
|
26
|
+
return {
|
|
27
|
+
verificationMethodId: method.id,
|
|
28
|
+
privateKeyHex: key.privateKeyHex
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
case types_1.VerificationMethods.Ed255192018:
|
|
32
|
+
const publicKeyBase58 = basics_1.bases['base58btc'].encode(publicKey).slice(1);
|
|
33
|
+
if (method.publicKeyBase58 === publicKeyBase58) {
|
|
27
34
|
return {
|
|
28
35
|
verificationMethodId: method.id,
|
|
29
36
|
privateKeyHex: key.privateKeyHex
|
|
@@ -35,12 +42,15 @@ function createSignInputsFromImportableEd25519Key(key, verificationMethod) {
|
|
|
35
42
|
kty: 'OKP',
|
|
36
43
|
x: (0, uint8arrays_1.toString)(publicKey, 'base64url')
|
|
37
44
|
};
|
|
38
|
-
if (
|
|
45
|
+
if (JSON.stringify(method.publicKeyJWK) === JSON.stringify(publicKeyJWK)) {
|
|
39
46
|
return {
|
|
40
47
|
verificationMethodId: method.id,
|
|
41
48
|
privateKeyHex: key.privateKeyHex
|
|
42
49
|
};
|
|
43
50
|
}
|
|
51
|
+
else {
|
|
52
|
+
throw new Error(`JWK not matching ${method.publicKeyJWK}, ${publicKeyJWK}`);
|
|
53
|
+
}
|
|
44
54
|
}
|
|
45
55
|
}
|
|
46
56
|
throw new Error('No verification method type provided');
|
|
@@ -66,27 +76,28 @@ function createKeyPairHex(seed) {
|
|
|
66
76
|
};
|
|
67
77
|
}
|
|
68
78
|
exports.createKeyPairHex = createKeyPairHex;
|
|
69
|
-
function createVerificationKeys(
|
|
79
|
+
function createVerificationKeys(publicKey, algo, key, network = types_1.CheqdNetwork.Testnet) {
|
|
70
80
|
let methodSpecificId;
|
|
71
81
|
let didUrl;
|
|
82
|
+
publicKey = publicKey.length == 43 ? publicKey : (0, uint8arrays_1.toString)((0, uint8arrays_1.fromString)(publicKey, 'hex'), 'base64');
|
|
72
83
|
switch (algo) {
|
|
73
84
|
case types_1.MethodSpecificIdAlgo.Base58:
|
|
74
|
-
methodSpecificId = basics_1.bases['base58btc'].encode((0, did_jwt_1.base64ToBytes)(
|
|
75
|
-
didUrl = `did:cheqd:${network}:${(basics_1.bases['base58btc'].encode(((0, uint8arrays_1.fromString)(sha256(
|
|
85
|
+
methodSpecificId = basics_1.bases['base58btc'].encode((0, did_jwt_1.base64ToBytes)(publicKey));
|
|
86
|
+
didUrl = `did:cheqd:${network}:${(basics_1.bases['base58btc'].encode(((0, uint8arrays_1.fromString)(sha256(publicKey))).slice(0, 16))).slice(1)}`;
|
|
76
87
|
return {
|
|
77
88
|
methodSpecificId,
|
|
78
89
|
didUrl,
|
|
79
90
|
keyId: `${didUrl}#${key}`,
|
|
80
|
-
publicKey
|
|
91
|
+
publicKey,
|
|
81
92
|
};
|
|
82
93
|
case types_1.MethodSpecificIdAlgo.Uuid:
|
|
83
|
-
methodSpecificId = basics_1.bases['base58btc'].encode((0, did_jwt_1.base64ToBytes)(
|
|
94
|
+
methodSpecificId = basics_1.bases['base58btc'].encode((0, did_jwt_1.base64ToBytes)(publicKey));
|
|
84
95
|
didUrl = `did:cheqd:${network}:${(0, uuid_1.v4)()}`;
|
|
85
96
|
return {
|
|
86
97
|
methodSpecificId,
|
|
87
98
|
didUrl,
|
|
88
99
|
keyId: `${didUrl}#${key}`,
|
|
89
|
-
publicKey
|
|
100
|
+
publicKey,
|
|
90
101
|
};
|
|
91
102
|
}
|
|
92
103
|
}
|
|
@@ -95,29 +106,30 @@ function createDidVerificationMethod(verificationMethodTypes, verificationKeys)
|
|
|
95
106
|
var _a;
|
|
96
107
|
return (_a = verificationMethodTypes.map((type, _) => {
|
|
97
108
|
switch (type) {
|
|
98
|
-
case types_1.VerificationMethods.
|
|
109
|
+
case types_1.VerificationMethods.Ed255192020:
|
|
110
|
+
return {
|
|
111
|
+
id: verificationKeys[_].keyId,
|
|
112
|
+
type,
|
|
113
|
+
controller: verificationKeys[_].didUrl,
|
|
114
|
+
publicKeyMultibase: _encodeMbKey(MULTICODEC_ED25519_PUB_HEADER, (0, did_jwt_1.base64ToBytes)(verificationKeys[_].publicKey))
|
|
115
|
+
};
|
|
116
|
+
case types_1.VerificationMethods.Ed255192018:
|
|
99
117
|
return {
|
|
100
118
|
id: verificationKeys[_].keyId,
|
|
101
|
-
type
|
|
119
|
+
type,
|
|
102
120
|
controller: verificationKeys[_].didUrl,
|
|
103
|
-
|
|
104
|
-
publicKeyMultibase: verificationKeys[_].methodSpecificId,
|
|
105
|
-
publicKeyJwk: []
|
|
106
|
-
})
|
|
121
|
+
publicKeyBase58: verificationKeys[_].methodSpecificId.slice(1)
|
|
107
122
|
};
|
|
108
123
|
case types_1.VerificationMethods.JWK:
|
|
109
124
|
return {
|
|
110
125
|
id: verificationKeys[_].keyId,
|
|
111
|
-
type
|
|
126
|
+
type,
|
|
112
127
|
controller: verificationKeys[_].didUrl,
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
},
|
|
119
|
-
publicKeyMultibase: ''
|
|
120
|
-
})
|
|
128
|
+
publicKeyJWK: {
|
|
129
|
+
crv: 'Ed25519',
|
|
130
|
+
kty: 'OKP',
|
|
131
|
+
x: (0, uint8arrays_1.toString)((0, uint8arrays_1.fromString)(verificationKeys[_].publicKey, 'base64pad'), 'base64url')
|
|
132
|
+
}
|
|
121
133
|
};
|
|
122
134
|
}
|
|
123
135
|
})) !== null && _a !== void 0 ? _a : [];
|
|
@@ -129,7 +141,7 @@ function createDidPayload(verificationMethods, verificationKeys) {
|
|
|
129
141
|
if (!verificationKeys || verificationKeys.length === 0)
|
|
130
142
|
throw new Error('No verification keys provided');
|
|
131
143
|
const did = verificationKeys[0].didUrl;
|
|
132
|
-
return
|
|
144
|
+
return types_1.MsgCreateDidPayload.fromPartial({
|
|
133
145
|
id: did,
|
|
134
146
|
controller: verificationKeys.map(key => key.didUrl),
|
|
135
147
|
verificationMethod: verificationMethods,
|
|
@@ -138,49 +150,14 @@ function createDidPayload(verificationMethods, verificationKeys) {
|
|
|
138
150
|
});
|
|
139
151
|
}
|
|
140
152
|
exports.createDidPayload = createDidPayload;
|
|
141
|
-
function createDidPayloadWithSignInputs(seed, keys) {
|
|
142
|
-
if (seed && keys)
|
|
143
|
-
throw new Error('Only one of seed or keys should be passed as an argument');
|
|
144
|
-
if (!keys) {
|
|
145
|
-
keys = [seed ? createKeyPairBase64(seed) : createKeyPairBase64()];
|
|
146
|
-
}
|
|
147
|
-
const verificationMethodTypes = keys.map((key) => !key.algo || key.algo == types_1.MethodSpecificIdAlgo.Base58 ? types_1.VerificationMethods.Base58 : types_1.VerificationMethods.JWK);
|
|
148
|
-
const verificationKeys = keys.map((key, i) => createVerificationKeys(key, key.algo || types_1.MethodSpecificIdAlgo.Base58, `key-${i}`));
|
|
149
|
-
const verificationMethod = createDidVerificationMethod(verificationMethodTypes, verificationKeys);
|
|
150
|
-
let payload = {
|
|
151
|
-
id: verificationKeys[0].didUrl,
|
|
152
|
-
controller: verificationKeys.map(key => key.didUrl),
|
|
153
|
-
verificationMethod: verificationMethod,
|
|
154
|
-
authentication: verificationKeys.map(key => key.keyId),
|
|
155
|
-
};
|
|
156
|
-
const keyHexs = keys.map((key) => convertKeyPairtoTImportableEd25519Key(key));
|
|
157
|
-
const signInputs = keyHexs.map((key) => createSignInputsFromImportableEd25519Key(key, verificationMethod));
|
|
158
|
-
return { didPayload: v2_1.MsgCreateDidDocPayload.fromPartial(payload), keys, signInputs };
|
|
159
|
-
}
|
|
160
|
-
exports.createDidPayloadWithSignInputs = createDidPayloadWithSignInputs;
|
|
161
|
-
function convertKeyPairtoTImportableEd25519Key(keyPair) {
|
|
162
|
-
return {
|
|
163
|
-
type: 'Ed25519',
|
|
164
|
-
privateKeyHex: (0, uint8arrays_1.toString)((0, uint8arrays_1.fromString)(keyPair.privateKey, 'base64'), 'hex'),
|
|
165
|
-
kid: 'kid',
|
|
166
|
-
publicKeyHex: (0, uint8arrays_1.toString)((0, uint8arrays_1.fromString)(keyPair.publicKey, 'base64'), 'hex')
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
exports.convertKeyPairtoTImportableEd25519Key = convertKeyPairtoTImportableEd25519Key;
|
|
170
|
-
function createSignInputsFromKeyPair(didDocument, keys) {
|
|
171
|
-
const keyHexs = keys.map((key) => convertKeyPairtoTImportableEd25519Key(key));
|
|
172
|
-
const signInputs = keyHexs.map((key) => createSignInputsFromImportableEd25519Key(key, didDocument.verificationMethod));
|
|
173
|
-
return signInputs;
|
|
174
|
-
}
|
|
175
|
-
exports.createSignInputsFromKeyPair = createSignInputsFromKeyPair;
|
|
176
153
|
function sha256(message) {
|
|
177
154
|
return (0, crypto_1.createHash)('sha256').update(message).digest('hex');
|
|
178
155
|
}
|
|
179
156
|
// encode a multibase base58-btc multicodec key
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
157
|
+
function _encodeMbKey(header, key) {
|
|
158
|
+
const mbKey = new Uint8Array(header.length + key.length);
|
|
159
|
+
mbKey.set(header);
|
|
160
|
+
mbKey.set(key, header.length);
|
|
161
|
+
return basics_1.bases['base58btc'].encode(mbKey);
|
|
162
|
+
}
|
|
186
163
|
//# 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,mCAcgB;AAChB,6CAAkD;AAClD,gDAA2C;AAC3C,qCAAuC;AACvC,gDAAsF;AACtF,+BAAyB;AACzB,mCAAmC;AASnC,0CAA0C;AAC1C,MAAM,6BAA6B,GAAG,IAAI,UAAU,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;AAInE,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,kBAA+C;IAChI,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,YAAY,CAAC,6BAA6B,EAAE,SAAS,CAAC,CAAA;gBACjF,IAAI,MAAM,C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AAC;QACtD,SAAS,EAAE,IAAA,SAAE,GAAE;KAClB,CACJ,CAAA;AACL,CAAC;AAhBD,4CAgBC;AAED,SAAS,MAAM,CAAC,OAAe;IAC3B,OAAO,IAAA,mBAAU,EAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;AAC7D,CAAC;AAED,+CAA+C;AAC/C,SAAS,YAAY,CAAC,MAAW,EAAE,GAAe;IAC9C,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC;IAEzD,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAClB,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;IAE9B,OAAO,cAAK,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC5C,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cheqd/sdk",
|
|
3
|
-
"version": "1.5.0-develop.
|
|
3
|
+
"version": "1.5.0-develop.3",
|
|
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": "^1.0.16-develop.
|
|
29
|
+
"@cheqd/ts-proto": "^1.0.16-develop.3",
|
|
30
30
|
"@cosmjs/amino": "^0.29.4",
|
|
31
31
|
"@cosmjs/encoding": "^0.29.4",
|
|
32
32
|
"@cosmjs/math": "^0.29.4",
|
package/src/index.ts
CHANGED
package/src/modules/did.ts
CHANGED
|
@@ -2,18 +2,17 @@ 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, MsgDeactivateDidPayload } from "../types"
|
|
5
|
+
import { DidStdFee, IContext, ISignInputs, MsgCreateDidPayload, MsgDeactivateDidPayload, MsgUpdateDidPayload, VerificationMethodPayload } from "../types"
|
|
6
6
|
import {
|
|
7
7
|
MsgCreateDidDoc,
|
|
8
|
-
MsgCreateDidDocPayload,
|
|
9
8
|
MsgCreateDidDocResponse,
|
|
10
9
|
MsgDeactivateDidDoc,
|
|
11
10
|
MsgDeactivateDidDocPayload,
|
|
12
11
|
MsgDeactivateDidDocResponse,
|
|
13
12
|
MsgUpdateDidDoc,
|
|
14
|
-
MsgUpdateDidDocPayload,
|
|
15
13
|
MsgUpdateDidDocResponse,
|
|
16
|
-
protobufPackage
|
|
14
|
+
protobufPackage,
|
|
15
|
+
SignInfo
|
|
17
16
|
} from "@cheqd/ts-proto/cheqd/did/v2"
|
|
18
17
|
import { EncodeObject, GeneratedType } from "@cosmjs/proto-signing"
|
|
19
18
|
|
|
@@ -84,6 +83,8 @@ export class DIDModule extends AbstractCheqdSDKModule {
|
|
|
84
83
|
[typeUrlMsgCreateDidDocResponse, MsgCreateDidDocResponse],
|
|
85
84
|
[typeUrlMsgUpdateDidDoc, MsgUpdateDidDoc],
|
|
86
85
|
[typeUrlMsgUpdateDidDocResponse, MsgUpdateDidDocResponse],
|
|
86
|
+
[typeUrlMsgDeactivateDidDoc, MsgDeactivateDidDoc],
|
|
87
|
+
[typeUrlMsgDeactivateDidDocResponse, MsgDeactivateDidDocResponse],
|
|
87
88
|
]
|
|
88
89
|
|
|
89
90
|
constructor(signer: CheqdSigningStargateClient) {
|
|
@@ -99,13 +100,18 @@ export class DIDModule extends AbstractCheqdSDKModule {
|
|
|
99
100
|
return DIDModule.registryTypes
|
|
100
101
|
}
|
|
101
102
|
|
|
102
|
-
async createDidTx(signInputs: ISignInputs[], didPayload: Partial<
|
|
103
|
+
async createDidTx(signInputs: ISignInputs[] | SignInfo[], didPayload: Partial<MsgCreateDidPayload>, address: string, fee: DidStdFee | 'auto' | number, memo?: string, context?: IContext): Promise<DeliverTxResponse> {
|
|
103
104
|
if (!this._signer) {
|
|
104
105
|
this._signer = context!.sdk!.signer
|
|
105
106
|
}
|
|
106
107
|
|
|
107
|
-
const payload =
|
|
108
|
-
|
|
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
|
+
}
|
|
109
115
|
|
|
110
116
|
const value: MsgCreateDidDoc = {
|
|
111
117
|
payload,
|
|
@@ -125,13 +131,18 @@ export class DIDModule extends AbstractCheqdSDKModule {
|
|
|
125
131
|
)
|
|
126
132
|
}
|
|
127
133
|
|
|
128
|
-
async updateDidTx(signInputs: ISignInputs[], didPayload: Partial<
|
|
134
|
+
async updateDidTx(signInputs: ISignInputs[] | SignInfo[], didPayload: Partial<MsgUpdateDidPayload>, address: string, fee: DidStdFee | 'auto' | number, memo?: string, context?: IContext): Promise<DeliverTxResponse> {
|
|
129
135
|
if (!this._signer) {
|
|
130
136
|
this._signer = context!.sdk!.signer
|
|
131
137
|
}
|
|
132
138
|
|
|
133
|
-
const payload =
|
|
134
|
-
|
|
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
|
+
}
|
|
135
146
|
|
|
136
147
|
const value: MsgUpdateDidDoc = {
|
|
137
148
|
payload,
|
|
@@ -151,13 +162,18 @@ export class DIDModule extends AbstractCheqdSDKModule {
|
|
|
151
162
|
)
|
|
152
163
|
}
|
|
153
164
|
|
|
154
|
-
async deactivateDidTx(signInputs: ISignInputs[], didPayload: MsgDeactivateDidPayload, address: string, fee: DidStdFee | 'auto' | number, memo?: string, context?: IContext): Promise<DeliverTxResponse> {
|
|
165
|
+
async deactivateDidTx(signInputs: ISignInputs[] | SignInfo[], didPayload: MsgDeactivateDidPayload, address: string, fee: DidStdFee | 'auto' | number, memo?: string, context?: IContext): Promise<DeliverTxResponse> {
|
|
155
166
|
if (!this._signer) {
|
|
156
167
|
this._signer = context!.sdk!.signer
|
|
157
168
|
}
|
|
158
169
|
|
|
159
170
|
const payload = MsgDeactivateDidDocPayload.fromPartial({id: didPayload.id, versionId: didPayload.versionId})
|
|
160
|
-
|
|
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
|
+
}
|
|
161
177
|
|
|
162
178
|
const value: MsgDeactivateDidDoc = {
|
|
163
179
|
payload,
|
package/src/modules/resource.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { EncodeObject, GeneratedType } from "@cosmjs/proto-signing"
|
|
|
4
4
|
import { DidStdFee, IContext, ISignInputs } from '../types';
|
|
5
5
|
import { MsgCreateResource, MsgCreateResourcePayload, MsgCreateResourceResponse, protobufPackage } from "@cheqd/ts-proto/cheqd/resource/v2"
|
|
6
6
|
import { DeliverTxResponse } from "@cosmjs/stargate"
|
|
7
|
+
import { SignInfo } from "@cheqd/ts-proto/cheqd/did/v2";
|
|
7
8
|
|
|
8
9
|
export const typeUrlMsgCreateResource = `/${protobufPackage}.MsgCreateResource`
|
|
9
10
|
export const typeUrlMsgCreateResourceResponse = `/${protobufPackage}.MsgCreateResourceResponse`
|
|
@@ -34,9 +35,14 @@ export class ResourceModule extends AbstractCheqdSDKModule {
|
|
|
34
35
|
return []
|
|
35
36
|
}
|
|
36
37
|
|
|
37
|
-
static async signPayload(payload: MsgCreateResourcePayload, signInputs: ISignInputs[]): Promise<MsgCreateResource> {
|
|
38
|
+
static async signPayload(payload: MsgCreateResourcePayload, signInputs: ISignInputs[] | SignInfo[]): Promise<MsgCreateResource> {
|
|
38
39
|
const signBytes = MsgCreateResourcePayload.encode(payload).finish()
|
|
39
|
-
|
|
40
|
+
let signatures: SignInfo[]
|
|
41
|
+
if(ISignInputs.isSignInput(signInputs)) {
|
|
42
|
+
signatures = await CheqdSigningStargateClient.signIdentityTx(signBytes, signInputs)
|
|
43
|
+
} else {
|
|
44
|
+
signatures = signInputs
|
|
45
|
+
}
|
|
40
46
|
|
|
41
47
|
return {
|
|
42
48
|
payload,
|
|
@@ -44,7 +50,7 @@ export class ResourceModule extends AbstractCheqdSDKModule {
|
|
|
44
50
|
}
|
|
45
51
|
}
|
|
46
52
|
|
|
47
|
-
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> {
|
|
48
54
|
if (!this._signer) {
|
|
49
55
|
this._signer = context!.sdk!.signer
|
|
50
56
|
}
|
package/src/signer.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { DeliverTxResponse, GasPrice, HttpEndpoint, QueryClient, SigningStargate
|
|
|
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, VerificationMethods } from './types';
|
|
7
|
+
import { DidStdFee, ISignInputs, TSignerAlgo, VerificationMethodPayload, 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'
|
|
@@ -176,11 +176,11 @@ export class CheqdSigningStargateClient extends SigningStargateClient {
|
|
|
176
176
|
}
|
|
177
177
|
|
|
178
178
|
verificationMethods.forEach((verificationMethod) => {
|
|
179
|
-
if (!(Object.values(VerificationMethods) as string[]).includes(verificationMethod.
|
|
180
|
-
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}`)
|
|
181
181
|
}
|
|
182
|
-
if (!this.didSigners[verificationMethod.
|
|
183
|
-
this.didSigners[verificationMethod.
|
|
182
|
+
if (!this.didSigners[verificationMethod.verificationMethodType ?? '']) {
|
|
183
|
+
this.didSigners[verificationMethod.verificationMethodType ?? ''] = EdDSASigner
|
|
184
184
|
}
|
|
185
185
|
})
|
|
186
186
|
|
|
@@ -189,7 +189,7 @@ export class CheqdSigningStargateClient extends SigningStargateClient {
|
|
|
189
189
|
|
|
190
190
|
async getDidSigner(verificationMethodId: string, verificationMethods: Partial<VerificationMethod>[]): Promise<(secretKey: Uint8Array) => Signer> {
|
|
191
191
|
await this.checkDidSigners(verificationMethods)
|
|
192
|
-
const verificationMethod = verificationMethods.find(method => method.id === verificationMethodId)?.
|
|
192
|
+
const verificationMethod = verificationMethods.find(method => method.id === verificationMethodId)?.verificationMethodType
|
|
193
193
|
if (!verificationMethod) {
|
|
194
194
|
throw new Error(`Verification method for ${verificationMethodId} not found`)
|
|
195
195
|
}
|
package/src/types.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { CheqdSDK } from "."
|
|
2
2
|
import { Coin } from "@cosmjs/proto-signing"
|
|
3
3
|
import { Signer } from "did-jwt"
|
|
4
|
-
import { MsgDeactivateDidDocPayload, VerificationMethod } from "@cheqd/ts-proto/cheqd/did/v2"
|
|
4
|
+
import { MsgCreateDidDocPayload, MsgDeactivateDidDocPayload, MsgUpdateDidDocPayload, VerificationMethod, Service } from "@cheqd/ts-proto/cheqd/did/v2"
|
|
5
|
+
import { DeepPartial, Exact } from "cosmjs-types/confio/proofs"
|
|
5
6
|
|
|
6
7
|
export enum CheqdNetwork {
|
|
7
8
|
Mainnet = 'mainnet',
|
|
@@ -19,7 +20,8 @@ export interface IContext {
|
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
export enum VerificationMethods {
|
|
22
|
-
|
|
23
|
+
Ed255192020 = 'Ed25519VerificationKey2020',
|
|
24
|
+
Ed255192018 = 'Ed25519VerificationKey2018',
|
|
23
25
|
JWK = 'JsonWebKey2020',
|
|
24
26
|
}
|
|
25
27
|
|
|
@@ -38,6 +40,12 @@ export interface ISignInputs {
|
|
|
38
40
|
privateKeyHex: string
|
|
39
41
|
}
|
|
40
42
|
|
|
43
|
+
export const ISignInputs = {
|
|
44
|
+
isSignInput(object: Object[]): object is ISignInputs[] {
|
|
45
|
+
return object.some((x)=> 'privateKeyHex' in x)
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
41
49
|
export interface IKeyPair {
|
|
42
50
|
publicKey: string
|
|
43
51
|
privateKey: string
|
|
@@ -70,5 +78,150 @@ export interface DidStdFee {
|
|
|
70
78
|
}
|
|
71
79
|
|
|
72
80
|
export interface MsgDeactivateDidPayload extends MsgDeactivateDidDocPayload {
|
|
73
|
-
verificationMethod:
|
|
74
|
-
}
|
|
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
|
+
}
|